Installing OpenCV 2.4.3
To install OpenCV 2.4.3, extract the downloaded file to a directory like "C:." This will create a "C:opencv" directory containing header files, libraries, and code samples. Add the directory "C:opencvbuildx86mingwbin" to your system path to access the OpenCV DLLs.
Installing MinGW Compiler Suite
Install the MinGW compiler suite and select the "C Compiler" and "C Compiler" components. Add the directory "C:MinGWbin" to your system path to ensure MinGW availability.
Writing a Sample Code
In loadimg.cpp, include OpenCV headers and code:
#include "opencv2/highgui/highgui.hpp" #include <iostream> using namespace cv; using namespace std; int main(int argc, char** argv) { Mat im = imread(argc == 2 ? argv[1] : "lena.jpg", 1); if (im.empty()) { cout << "Cannot open image!" << endl; return -1; } imshow("image", im); waitKey(0); return 0; }
Compiling and Running the Code
Compile the code using:
g++ -I"C:\opencv\build\include" -L"C:\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core243 -lopencv_highgui243 -o loadimg
Execute the resulting loadimg.exe to display the OpenCV logo window.
Next Steps
Explore the OpenCV samples at "C:opencvsamplescpp" to enhance your knowledge and start developing your own OpenCV applications.
The above is the detailed content of How to Get Started with OpenCV 2.4 and MinGW on Windows 7?. For more information, please follow other related articles on the PHP Chinese website!