Home >Backend Development >C++ >How to Set Up OpenCV 2.4 with MinGW on Windows 7?

How to Set Up OpenCV 2.4 with MinGW on Windows 7?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-17 04:53:03958browse

How to Set Up OpenCV 2.4 with MinGW on Windows 7?

OpenCV 2.4 and MinGW Setup on Windows 7

To utilize OpenCV 2.4 with MinGW on Windows 7, follow these steps:

OpenCV Installation:

  1. Download OpenCV 2.4.3 from its official location.
  2. Unzip it into a preferred directory, for instance, "C:opencv".
  3. Configure your system path to include "C:opencvbuildx86mingwbin", as it contains indispensable OpenCV DLLs.

MinGW Installation:

  1. Obtain the MinGW installer from its website and run it.
  2. Select an installation directory, such as "C:MinGW".
  3. Choose to install "C Compiler" and "C Compiler".
  4. Add "C:MinGWbin" to your system path.

Sample Program:

  1. Create a new file named "loadimg.cpp" with the following 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;
}
  1. Compile the code using the following command, replacing the library paths accordingly:
g++ -I"C:\opencv\build\include" -L"C:\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core243 -lopencv_highgui243 -o loadimg
  1. Run the compiled program by typing "loadimg".

You'll now have a working OpenCV and MinGW setup on Windows 7. Explore OpenCV's samples directory for further examples and documentation.

The above is the detailed content of How to Set Up OpenCV 2.4 with MinGW on Windows 7?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn