OpenCV & VS2010
1. OpenCV 패키지 다운로드
- http://sourceforge.net/projects/opencvlibrary/
(현재시점 2.4.7)
2. 시스템 환경변수 추가
- 변수이름 : OPENCV_BUILD
- 변수 값 : C:\openCV\build
3. 시스템 Path 변수에 추가
- %OPENCV_BUILD%\x86\vc10\bin;
4. VS2010 에서 Win32 console 프로젝트 생성 후 코드 추가
<MyOpenCV.cpp>
#include "stdafx.h"
// { for show_image()
#include <opencv\cv.h>
#include <opencv\highgui.h>
// for show_image() }
//
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
void show_image();
void camera_capture();
char key;
int _tmain(int argc, _TCHAR* argv[])
{
//show_image();
camera_capture();
return 0;
}
void show_image()
{
IplImage * image = cvLoadImage("Hydrangeas.jpg");
cvShowImage("test image", image);
cvWaitKey(0);
cvReleaseImage(&image);
}
void camera_capture()
{
cvNamedWindow("Camera_Output", 1); //Create window
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); //Capture using any camera connected to your system
while(1){ //Create infinte loop for live streaming
IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
cvShowImage("Camera_Output", frame); //Show image frames on created window
key = cvWaitKey(10); //Capture Keyboard stroke
if (char(key) == 27){
break; //If you hit ESC key loop will break.
}
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
}
3. Project Property > C/C++ > General > Additional Include Directories
$(OPENCV_BUILD)\include
4. Project Property > Linker > General > Additional Library Directories
$(OPENCV_BUILD)\x86\vc10\lib
>> 32비트 운영체제에서 빌드 성공함
참고 1) VS2005 & 64비트 환경에서 $(OPENCV_BUILD)\x64\vc10\lib 로 설정한 뒤,
빌드하였더니 아래와 같은 링크 에러가 발생함.
1>MyOpenCV.obj : error LNK2019: unresolved external symbol _cvReleaseImage referenced in function _main
1>MyOpenCV.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in function _main
1>MyOpenCV.obj : error LNK2019: unresolved external symbol _cvShowImage referenced in function _main
1>MyOpenCV.obj : error LNK2019: unresolved external symbol _cvLoadImage referenced in function _main
1>E:\998.HaHa\myproject\MyOpenCV\Debug\MyOpenCV.exe : fatal error LNK1120: 4 unresolved externals
5. Project Property > Linker > Input > Additional Dependencies
opencv_core247d.lib
opencv_imgproc247d.lib
opencv_highgui247d.lib
opencv_ml247d.lib
opencv_video247d.lib
opencv_features2d247d.lib
opencv_calib3d247d.lib
빌드 및 실행 (Esc 키를 누르면 종료함)