Ubuntu12.04 install OpenCV2.3.1, image binarization 1, install libgtk2.0-devandpkg-config terminal run sudoapt-getinstalllibgtk2.0-devpkg-config2. Download OpenCV-2.3.1 (to the openCV official website to download) cd command to enter the corresponding download directory. Run the following command in sequence $ tarxfOpenCV-2.3.
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
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] <
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 at compile timeGcc 'pkg-config -- cflags -- libs opencv'Erzhihua. cpp-o erzhiAn error is reported. Why ??)
Run
$./Erzhi lena.jpg
Running result:
-------------------------------------- Split line --------------------------------------
OpenCV2.4.1 package http://www.linuxidc.com/Linux/2012-08/68184.htm installed in Ubuntu Linux
Ubuntu 12.04 install OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm
OpenCV in CentOS cannot read video file http://www.linuxidc.com/Linux/2011-07/39295.htm
Summary of installing OpenCV 2.4.5 in Ubuntu 12.04Http://www.linuxidc.com/Linux/2013-06/86704.htm
Install OpenCv2.1 nine-step http://www.linuxidc.com/Linux/2010-09/28678.htm in Ubuntu 10.04
Http://www.linuxidc.com/Linux/2011-11/47806.htm of face recognition system based on QT and OpenCV
Install OpenCV 2.4.9 in Ubuntu 14.04 and 13.10Http://www.linuxidc.com/Linux/2014-12/110045.htm
-------------------------------------- Split line --------------------------------------
OpenCV details: Click here
OpenCV: Click here
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-02/113627.htm