http://sourceforge.net/projects/opencvlibrary/
2. 安裝OpenCV
3. Add OpenCV to the system PATH for all users
3A.將 c:\openCV2.2\bin 的 opencv_core220d.dll、opencv_highgui220d.dll、
opencv_objdetect220d.dll、opencv_imgproc220d.dll拷貝到 c:windows\system32
4. 安裝Microsoft Visual Studio 2010
5. 在 VS.NET 2010下新增一個 Win32 Console Application
6. 將opencv_highgui220d.lib;opencv_core220d.lib;opencv_imgproc220d.lib;
加入 OpenCV程式庫( libraries )
在VS.NET 2010的 Project->Property->Linker->Input->AdditionalDependencies:下
加入opencv_highgui220d.lib;opencv_core220d.lib;opencv_imgproc220d.lib;
7. 將C:\OpenCV2.2\include\opencv;C:\OpenCV2.2\include加入OpenCV Include Directory
在VS.NET 2010主功能表的 Configuration Property->VC++ Directories->Include Directories
加入 C:\OpenCV2.2\include\opencv;C:\OpenCV2.2\include;
8. Add OpenCV Directory"C:\OpenCV2.2\lib;"to VC++ Directories->Library Directories
9. 使用 範例 1 顯示圖片
#include "stdafx.h"
#include
#include
using namespace cv;
int main(int argc, char** argv)
{
Mat imgSrc;
imgSrc = imread("lena.jpg") ;
namedWindow("Src") ;
imshow("Src",imgSrc) ;
waitKey(0);
destroyWindow("Src")
return 0;
}
10. 範例2 彩色轉黑白
#include "stdafx.h"
#include
#include
using namespace cv;
int main(int argc, char** argv){
Mat imgSrc; Mat imgDst;
imgSrc = imread("lena.jpg") ;
cvtColor(imgSrc, imgDst, CV_RGB2GRAY);
namedWindow("Src") ;
namedWindow("Dst");
imshow("Src",imgSrc) ;
imshow("Dst",imgDst) ;
waitKey(0);
destroyWindow("Src") ;
destroyWindow("Dst") ;
return 0;
}
11.範例 3 使用攝影機
#include "stdafx.h"
#include
#include
using namespace cv;
int main(int, char**){
VideoCapture cap(0);
if(!cap.isOpened()) return -1;
Mat edges; namedWindow("edges",1);
for(;;) {
Mat frame;
cap >> frame;
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
沒有留言:
張貼留言