Install the dependent package first. Otherwise, errors may occur during runtime even though the openCV program can be compiled. Sudoapt-getinstallbuild-essentiallibgtk2.0-devlibavcodec-devlibavformat-devlibjpeg62-devlibtiff4-devcmakelibswscale-devlibjasper-dev and then download the openCV source code
Install the dependent package first. Otherwise, errors may occur during runtime even though the openCV program can be compiled.
Sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
Download the openCV source code package and decompress it.
Enter the extracted directory
Cd ~ /Opencv
Mkdir release
Cd release
Cmake-D CMAKE_BUILD_TYPE = RELEASE-D CMAKE_INSTALL_PREFIX =/usr/local .. then install
Make
Sudo make install
Code Testing
DisplayImage. cpp
- # Include
- # Include
- # Include
- Using NamespaceCv;
- Using NamespaceStd;
- IntMain (IntArgc,Char** Argv)
- {
- Mat image;
- Image = imread (argv [1], 1 );
- If(Argc! = 2 |! Image. data)
- {
- Cout <"No image data \ n";
- Return-1;
- }
- NamedWindow ("Display Image", CV_WINDOW_AUTOSIZE );
- Imshow ("Display Image", Image );
- WaitKey (0 );
- Return0;
- }
G ++ DisplayImage. cpp-o DisplayImage 'pkg-config opencv -- cflags -- libs'
Run the command to view the displayed image.
./DisplayImage abc.jpg
I don't know what 'pkg-config opencv -- cflags -- libs' means. I Can't compile the program without adding this one.