|
1, The installation libgtk2.0-dev and pkg-config
Terminal run sudo apt-get install libgtk2.0-dev pkg-config
2. Download OpenCV-2.3.1 (to openCV official website can be downloaded)
cd command to enter the appropriate download directory. Run the following command sequence
$ Tar xf OpenCV-2.3.1.tar.bz2
$ Cd OpenCV-2.3.1
3. Run a terminal
$ Mkdir build
$ Cd build
$ Cmake .. here is two points behind cmake spaces.
4 and then click Run
$ Make
$ Sudo make install
At this point compile successfully.
5 Configure the necessary libraries.
run
$ Sudo gedit /etc/ld.so.conf.d/opencv.conf
Add / usr / local / lib to the file
6 Run
$ Sudo ldconfig
7 run sudo gedit /etc/bash.bashrc, add the following two lines to the end of the file and save it.
PKG_CONFIG_PATH = $ PKG_CONFIG_PATH: / usr / local / lib / pkgconfig
export PKG_CONFIG_PATH
8 Run samples
$ Cd ~
$ Mkdir openCV_samples
$ Cp OpenCV-2.3.1 / samples / c / * openCV_samples
$ Cd openCV_samples /
$ Chmod + x build_all.sh
$ ./build_all.sh
$. / One_way_sample. ./one_way_train_0000.jpg ./one_way_train_0001.jpg
8 programming (binary image)
1 #include "cv.h"
2 #include "cxcore.h"
3 #include "highgui.h"
4 #include < iostream >
5
6 using namespace std;
7
8 int main (int argc, char * argv [])
9 {
10 IplImage * img = cvLoadImage (argv [1], -1);
11 IplImage * biimg = cvCreateImage (cvGetSize (img), img-> depth, img-> nChannels);
12 CvScalar s;
13 int sum = 0;
14 for (int i = 0; i height; i ++)
15 {
16 for (int j = 0; j width; j ++)
17 {
18 s = cvGet2D (img, i, j);
19 cout << s.val [0] << "" << s.val [1] << "" << s.val [2] << endl;
20 sum = (s.val [0] + s.val [1] + s.val [2]) / 3;
21 if (sum> 128)
22 s.val [0] = s.val [1] = s.val [2] = 255;
23 else
24 s.val [0] = s.val [1] = s.val [2] = 0;
25
26 cvSet2D (img, i, j, s);
27}
28}
29 cvCopy (img, biimg);
30 cvSaveImage ( "combibi.JPG", biimg);
31 cvNamedWindow ( "imagebinary");
32 cvShowImage ( "imagebinary", biimg);
33 cvWaitKey (0);
34 cvDestroyWindow ( "imagebinary");
35 cvReleaseImage (& img);
36 cvReleaseImage (& biimg);
37 return 0;
38}
Compile
$ Gcc erzhihua.cpp -o erzhi `pkg-config --cflags --libs opencv`
(Question: run gcc `pkg-config --cflags --libs opencv` erzhihua.cpp -o erzhi compile-time error will be, do not know why ??)
run
$ ./erzhi Lena.jpg |
|
|
|