Install OpenCV 2.3.1 in Ubuntu 12.04 and perform image binarization.
Install OpenCV 2.3.1 in Ubuntu 12.04 and perform image binarization.
1. Install libgtk2.0-dev and pkg-config.
Run sudo apt-get install libgtk2.0-dev pkg-config on the terminal
2. Download The OpenCV-2.3.1 (go to The openCV official website to download)
Run the cd command to enter the corresponding download directory. Run the following commands in sequence
$ Tar xf OpenCV-2.3.1.tar.bz2
$ OpenCV-2.3.1 cd
3. Terminal Operation
$ Mkdir build
$ Cd build
$ Cmake .. here are the two dots after the cmake space.
4. Run in sequence
$ Make
$ Sudo make install
The compilation is successful.
5. Configure 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 rows to the end of the file, and save them.
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_assist.jpg./one_way_train_0001.jpg
Running result
8 programming (image binarization)
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 during compilation. Why ??)
Run
$./Erzhi lena.jpg
Running result:
-------------------------------------- Split line --------------------------------------
Install the required OpenCV2.4.1 package in Ubuntu Linux
Install OpenCV2.4.2 on Ubuntu 12.04
OpenCV in CentOS cannot read Video Files
Summary of installing OpenCV 2.4.5 in Ubuntu 12.04
Install OpenCv2.1 in Ubuntu 10.04
Face Recognition System Based on QT and OpenCV
Install OpenCV 2.4.9 in Ubuntu 14.04 and 13.10
-------------------------------------- Split line --------------------------------------
OpenCV details: click here
OpenCV: click here