Home > Backend Development > C++ > How to Get Started with OpenCV 2.4 on Windows 7 Using MinGW?

How to Get Started with OpenCV 2.4 on Windows 7 Using MinGW?

Linda Hamilton
Release: 2024-11-19 14:28:03
Original
760 people have browsed it

How to Get Started with OpenCV 2.4 on Windows 7 Using MinGW?

Getting Started with OpenCV 2.4 and MinGW on Windows 7

Installation:

  1. OpenCV 2.4.3:

    • Extract the OpenCV self-extracting file to a directory (e.g., C:).
    • Add the OpenCV DLL directory (C:opencvbuildx86mingwbin) to your system path.
  2. MinGW Compiler Suite:

    • Install MinGW and select the "C Compiler" and "C Compiler" options.
    • Add the MinGW bin directory (C:MinGWbin) to your system path.

Sample Code:

Create a 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

Compilation and Execution:

  1. Compile the code using the command:

    g++ -I"C:\opencv\build\include" -L"C:\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core243 -lopencv_highgui243 -o loadimg
    Copy after login
  2. Execute the program:

    loadimg
    Copy after login

This will display the loaded image in a window.

Next Steps:

  • Explore the OpenCV samples directory (C:opencvsamplescpp).
  • Compile and study existing code.
  • Develop your own OpenCV applications.

The above is the detailed content of How to Get Started with OpenCV 2.4 on Windows 7 Using MinGW?. 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