This article mainly describes how to configure OPENCV with vs2012 and then modify the code for debugging OpenCV.
1, Configuration OpenCV Project
Here is the main introduction of how to compile the source code through VS2012, the specific steps can be consulted:
"OpenCV Introductory Tutorial VII" OPENCV source code: Generate OPENCV Engineering solution with OPENCV source compilation
Because I use the VS version is vs2012, corresponding to VC11, in the process of compiling, if the following similar problems, you can refer to:
1) CMake prompt cannot find vs12
The specific phenomenon is in the CMake GUI interface, when you click Configure, the following prompt appears:
CMake Error:cmake was unable to the find a build program corresponding to "Visual Studio 12". Cmake_make_program is not set. You probably need to select a different build tool.
Workaround: This is because in CMake vs2012 is considered to be vc11, when we configure, in the popup window (as shown), select vs2011.
For details, refer to:
http://public.kitware.com/Bug/print_bug_page.php?bug_id=14629
2) Compile the process, error, prompt did not find ippicv_windows_20141027
During the CMake configuration, when the file is downloaded, it appears:
CMake Error at 3rdparty/ippicv/downloader.cmake:97 (message):
Icv:failed to unpack ICV package from D:/program files/opencv/sources/3rdparty/ippicv/downloads/ Windowsb59f865d1ba16e8c84124e19d78eec57/ippicv_windows_20141027.zip
To D:/program Files/opencv/sources/3rdparty/ippicv/unpack with the error 1Call Stack (most recent call first):
3rdparty/ippicv/downloader.cmake:108 (_icv_downloader)
cmake/opencvfindipp.cmake:212 (include)
Cmake/opencvfindlibsperf.cmake:12 (include)
cmakelists.txt:454 (include)
At this point we can download this file: Ippicv_windows_20141027.zip
Replace to:
.. The corresponding file in the \opencv\v300\sources\3rdparty\ippicv\downloads\windows-b59f865d1ba16e8c84124e19d78eec57\ path is available.
Stop configure, copy the file to the path to overwrite the file that is not downloaded, and then click Configure.
2, how to debug OpenCV
In the above mentioned tutorial, we have configured the OPENCV source code engineering files.
Now we open the corresponding project file. Select the DLL that we want to debug. Because the OpenCV is quite large, it is divided into different DLLs according to the function.
Here's a look at how to debug OpenCV's code with an example of what you've written. The main purpose is to learn OPENCV inside the excellent design, found now OPENCV have used a relatively fast method, such as Sse,neon and other optimization techniques, familiar with the code becomes very useful.
First of all, we write a simple project engineering. The main use of resize functions.
Mat img= imread("d:\\lena.jpg");resize(img,img,Size(img.cols/2,img.rows/2));
Then, open the OPENCV project file and find the corresponding imgwarp.cpp,resize function in this file. It's supposed to be under the Opencv_imgproc.
For Opencv_imgproc, right click, select Properties, pop up the following dialog box. In the corresponding configuration properties, debug options, modify the command as we just wrote the EXE file for the debug file in the Opencvbase project directory. Debugger Type modified to
Mixed。 When debugging the DLL, choose to call it with our chosen EXE program.
Then right-click on the Opencv_imgproc project and set it to
Start Project。
In order to better observe whether or not into the OPENCV code inside, in Imgwarp.cpp, find the Resize function, set breakpoints. and start debugging.
As you can see, this has entered into the resize function.
Now there is a problem, the current setting does not allow us to modify the OPENCV code and debug, only the breakpoint tracking.
Suppose we want to modify OpenCV's code and debug what should be done?
3, modify and debug OpenCV source code
Here we need to copy the DLL generated by the OPENCV project to the system path we need.
At the beginning of the configuration, we configured the environment variable for OPENCV to be able to find the DLL file under the corresponding environment variable path. In order to debug our generated DLLs, we only need to copy the DLL files generated by these projects into the corresponding environment variable path. It is also possible to directly configure the generated address as the corresponding Opencv\build\x86\vc11\bin when generating the DLL
Here, I configured the following:
D:\opencv3.0\build\x86\vc11\bin, in order to be more convenient, directly set Opencv_imgproc output directory is D:\opencv3.0\build\x86\vc11\bin,
In resize, add the print statement:
Then build the solution.
In Opencvbase Engineering or OPENCV source code engineering, recompile runs. Can all see:
"OpenCV" How to configure Modify and debug OpenCV source code