Home > Backend Development > C++ > How to Set Up OpenCV 2.4 and MinGW on Windows 7 for Image Processing?

How to Set Up OpenCV 2.4 and MinGW on Windows 7 for Image Processing?

Linda Hamilton
Release: 2024-11-12 03:56:02
Original
204 people have browsed it

How to Set Up OpenCV 2.4 and MinGW on Windows 7 for Image Processing?

Getting Started: OpenCV 2.4 and MinGW on Windows 7 with a Sample Code

Installing OpenCV 2.4

  • Download and extract the OpenCV 2.4.3 package from Sourceforge.net.
  • Install it in a directory (e.g., C:).
  • Add the OpenCV DLL directory (C:opencvbuildx86mingwbin) to your system PATH.

Installing MinGW

  • Download the MinGW installer from Sourceforge.net and follow the wizard.
  • Select the directory to install (e.g., C:MinGW).
  • Install the C Compiler and C Compiler.
  • Add the MinGW bin directory (C:MinGWbin) to your system PATH.

Writing a Sample Code

  1. Create a new C file (e.g., 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
  2. Compile the code:

    g++ -I"C:\opencv\build\include" -L"C:\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core243 -lopencv_highgui243 -o loadimg
    Copy after login
  3. Run the compiled program (loadimg.exe) to load and display an image.

Next Steps

  • Explore the sample codes in the OpenCV samples directory (C:opencvsamplescpp).
  • Develop your own OpenCV applications.

The above is the detailed content of How to Set Up OpenCV 2.4 and MinGW on Windows 7 for Image Processing?. 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