I am trying to write a C++ application using the OpenCV libraries. As per the recommendation from the OpenCV maintainers, I am using CMake to generate the Makefile. My platform is Windows 7 (64 bit). My compiler is MinGW (so I am using the ‘mingw32-make’ tool to build the application).
Right now I am trying to make sure my setup is correct so I can move forward with the code. I have verified that the OpenCV libraries have been built correctly. I then tried to verify that I could use CMake to include the OpenCV libraries in my build. I am using the following sample code from an OpenCV tutorial:
DisplayImage.cpp
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
if (argc != 2 || !image.data)
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
CMakeLists.txt
cmake_minimum_required( VERSION 2.8 )
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
I used cmake-gui to generate the Makefile, then used mingw32-make to build the application. Everything works fine and the program compiles with no errors. However, when I try to run it, Windows stops and complains that it needs libopencv_core231.dll. I have checked and this dll is in my (OpenCV Build location)/bin directory. How can I get CMake/MinGW to include this when compiling?
copy opencv dlls into your executable folder.