Home > Backend Development > C++ > body text

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

Mary-Kate Olsen
Release: 2024-11-14 13:55:02
Original
740 people have browsed it

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

Getting Started with OpenCV 2.4 and MinGW on Windows 7

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

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
Copy after login

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!

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