Compiling opencv2.4.9 using Visual Studio 2012

Source: Internet
Author: User
Tags unpack

  Recently, since a function in the OPENCV needs to be modified from the OPENCV source section to improve the speed of the algorithm, it has been trying to compile OpenCV using vs2012. There were many failures during the period. Today, through experiments found that their own compiled OpenCV library can finally be used, no longer appear before the link error. The compilation process is now recorded as follows, hoping to give the people who need to provide ideas and help. If you find the error, please also leave a message to point out, thank you.

First, take a look at OpenCV's installation directory (for example), and you can see that there are two subfolders. Where the build folder is already compiled, can be used directly, and the source folder as the name implies is OpenCV all the source. However, the source code is not a vs engineering file, so it is not able to open the entire source like a VS project:

  

The first step we are going to take now is to "unpack" the Source code ("unpack") into a VS2012 project that I have not figured out now, as I see in one blog post. The tool that needs to be used is cmake.

(1) Download and install the CMake as shown in. (I'm using the 3.0 version)

    

(2) Select the source path in CMake and select the path to the solution for the OPENCV project that will be generated.

    

(3) After the path is set, click the Configure button. The following conditions occur. Choose the corresponding one based on your VS version. (Mine is vs2012):

    

(4) Click Finish after cmake to start work, after the end appears configure down words:

    

(5) Click once again configure, the red part disappears, again appears configure down:

    

(6) Finally click Generate, appear generating down, completed the OpenCV unpacking:

    

(7) To see what is generated in the target path. This is the vs2012 solution we want to get through CMake. Open Opencv.sln to open the entire project of OPENCV in vs2012 (note that there are no bin and Lib directories in the currently generated directory):

    

Through the above step by step detailed introduction, we can now finally enjoy the OPENCV source tolerance distortion. We open the Opencv.sln and open the OpenCV project in vs2012:

  

As you can see, VS has successfully loaded the entire project of OPENCV. Right-click on the solution and in the pop-up menu, tap Build Solution, wait a few moments:

After the success of the build, we look at the OPENCV project directory, you can see more than two folders in the directory Lib and bin. These two directories are the libraries of our own compiled OPENCV:

  

Copy all files in the debug directory under the Bin and Lib two folders to the OpenCV installation directory, overwriting the original Lib and DLL files (so you don't have to reconfigure the environment)

  

Write a test program (I added a cout<< "This is a test" <<endl; statement in the Imshow source code):

#include <opencv2/opencv.hpp> #include <iostream>using namespace std;using namespace Cv;int main () {int i;< C0/>mat   img = imread ("test.jpg");    if (Img.empty ())    {    fprintf (stderr, "error:load image failed.");    System ("pause");   return-1;    }    Namedwindow ("image", cv_window_autosize);     Imshow ("Image", IMG);   Waitkey ();    System ("pause");   return 0; }

After running the results are as follows, you can see that the console output this is a test! :

  

  

At this point, the entire OPENCV compilation process ends here. Hope can give everyone help!

Reference blog:

Http://www.tuicool.com/articles/f6ZBZv

Original blog, reproduced please specify the source: http://www.cnblogs.com/xiongmao-cpp/

Compiling opencv2.4.9 using Visual Studio 2012

Related Article

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.