Configure the OpenCV environment in Linux

Source: Internet
Author: User
With a one-day OpenCV environment, you can finally compile and run the program. My system is Ubuntu12.04LTS. The downloaded OpenCV version is the latest OpenCV2.4.21. You can directly download the source code, you can also use svn to download a Linux version of OpenCV in zip format. Decompress the package to a place and place it in/home/star/apps. The current directory status is/home/star (this is

With the one-day OpenCV environment, you can finally compile and run the program. My system is Ubuntu 12.04LTS. The downloaded OpenCV version is the latest OpenCV 2.4.2.

1. Prepare the source code, which can be downloaded directly or svn.

The preparation is to download a Linux version of OpenCV online, in zip format. Decompress the package to a place and place it in/home/star/apps.

The current directory status is/home/star (this is my user name, different from yours)/apps (this is the place where I am used to putting programs, and the God code pdf reader is here) /OpenCV/(here there are a lot of OpenCV files, which should be cmake in the following)

2. Download the dependent files required by OpenCV

Sudo-sH becomes Superman

And then crazy apt-get install ....

For more information about install, see the link below. If you are a newbie, we recommend that you install all of them .. Otherwise, there will be the lowest possible errors, and I don't know what's going on after a long time.

Http://opencv.willowgarage.com/wiki/InstallGuide%20%3A%20Debian

3. Compile OpenCV

Go back to the OpenCV directory in step 1, create a folder named release, and cmake in it. For details, refer to the above link.

    cd ~/opencv # the directory containing INSTALL, CMakeLists.txt etc.    mkdir release    cd release    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

The above cmake command does not exist !!! The first small step is complete.

Next, let's take the second small step: make

This step takes a long time... Long time, long time ......

Then it's easy: make install

4. Small Configuration

This step is about whether your program can find those include, and lib.

You can refer to this article ~~ ... Why didn't I find it early... I took a lot of roads =

Http://www.samontab.com/web/2010/04/installing-opencv-2-1-in-ubuntu/

Below is the copy from this link... People are too lazy to translate .. For fear of translation errors...

Now you have to configure the library. First, open the opencv. conf file with the following code:

1 sudo gedit /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file (it may be an empty file, that is OK) and then save it:

1 /usr/local/lib

Run the following code to configure the library:

1 sudo ldconfig

Now you have to open another file:

1 sudo gedit /etc/bash.bashrc

Add these two lines at the end of the file and save it:

1 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
2 export PKG_CONFIG_PATH

Finally, open a new console, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.


5. Write a program !!!

Create DisplayImage. cpp in your working directory.

Copy the source code from this point.

Http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html

Then the compilation is completed. There are three compilation methods:

1) Direct gcc

2) use cmake to create the makefile and then make it.

3) IDE method. It is said that there is a omnipotent IDE called eclipse ....

First,

g++ `pkg-config --cflags opencv` -o hello hello.cpp `pkg-config --libs opencv`

Http://stackoverflow.com/questions/11532963/cant-compile-opencv-in-linux

I will give you a link to tell you That libs should be put behind it .. Otherwise, an error will occur ~~

Second,

Create a cmakelists.txt file and input the following content.

project( DisplayImage )find_package( OpenCV REQUIRED )add_executable( DisplayImage DisplayImage )target_link_libraries( DisplayImage ${OpenCV_LIBS} )
Then... Read this article... Http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html

After cmake, there will be an executable file and the image will be displayed ~~~ (How is it Lena ....)

My problems:

No compilation error, but the following error occurs when you run the program.

OpenCV ERROR: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK + 2.x or Carbon support)

It means that you have something to support. We recommend you install libgtk2.0 (what is this forgotten) and pkg-config.

Then I installed libgtk. And then it does not work. (Please take a look at it and solve it below ~~)

A gg said reading this article can fix the http://mathiasirwans.blogspot.com/2007/07/my-experience-with-ubuntu-610-opencv-10.html.

But I still can't figure it out...

Later, I thought deeply about the error message. After installing the missing things, I re-installed cmake + make install and finally got it done ~~~ (Because the make process is very painful, I have been avoiding make before .. This confirmed that I was really wrong ...)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.