> 백엔드 개발 > C++ > 본문

Windows 7에서 컴퓨터 비전 프로젝트용 OpenCV 2.4 및 MinGW를 설정하는 방법은 무엇입니까?

Linda Hamilton
풀어 주다: 2024-11-14 11:00:02
원래의
525명이 탐색했습니다.

How to Set Up OpenCV 2.4 and MinGW for Computer Vision Projects on Windows 7?

Getting Started with OpenCV 2.4 and MinGW on Windows 7

OpenCV (Open Computer Vision) is a powerful open-source library focused on real-time computer vision. It's widely used for image processing, computer graphics, motion detection, facial recognition, and more. MinGW (Minimalist GNU for Windows) is a lightweight port of the GNU toolchain for Windows, providing a native Windows environment to compile and run your C and C++ code. This guide will take you through the steps of installing OpenCV 2.4 and setting up your development environment with MinGW.

1. Installing OpenCV 2.4.3

Begin by downloading OpenCV 2.4.3 from sourceforge.net. Execute the self-extracting file to install OpenCV in a designated directory, such as "C:\". Upon completion, you'll find a new "C:\opencv" directory containing OpenCV headers, libraries, and samples.

Next, add "C:\opencv\build\x86\mingw\bin" to your system PATH to access OpenCV DLLs required for running your code. Open Control Panel > System > Advanced system settings > Advanced Tab > Environment variables...

In the System Variables section, select "Path", click "Edit...", add "C:\opencv\build\x86\mingw\bin", and click "Ok".

2. Installing MinGW Compiler Suite

For compiling code, gcc (GNU Compiler Collection) is highly recommended. MinGW provides a native Windows port for gcc. Download the MinGW installer from Sourceforge.net and install it in a directory, such as "C:\MinGW". Choose to install both "C Compiler" and "C++ Compiler".

Upon completion, add "C:\MinGW\bin" to your system PATH as described earlier. To verify the installation, open a command-line box and type "gcc". A successful installation will display an error message: "gcc: fatal error: no input files compilation terminated".

3. Writing a Sample Code

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;
}
로그인 후 복사

Place an image file, such as "lena.jpg", in the same directory as the code. Compile the code using the following command:

g++ -I"C:\opencv\build\include" -L"C:\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core243 -lopencv_highgui243 -o loadimg
로그인 후 복사

After successful compilation, run "loadimg.exe" to display the loaded image.

4. Next Steps

Your OpenCV environment is now ready. Explore the code samples provided in the "C:\opencv\samples\cpp" directory to gain a deeper understanding of OpenCV's capabilities. Alternatively, you can begin developing your own computer vision applications.

위 내용은 Windows 7에서 컴퓨터 비전 프로젝트용 OpenCV 2.4 및 MinGW를 설정하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿