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
Release: 2024-11-17 04:53:03
Original
944 people have browsed it

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;
}
Copy after login
  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
Copy after login
  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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template