http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.1/
2. 開啟visual studio 2010(Visual C++)
http://www.microsoft.com/visualstudio/cht/downloads#d-additional-software
**File->New->Project->Win32主控台應用程式->取名稱->不要選"先行編譯標頭檔"
#include "stdafx.h"
#include <stdlib.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf("Hello");
system("pause");
return 0;
}
<圖片要存在專案資料夾內!!>
<每開一次新的專案必須重新設定!!>
解決辦法>>
3. 使用 Visual C++ 寫 OpenCV 程式 (練習設定 OpenCV 的目錄、Link Input 檔案)
3.1. Include 目錄 增加 C:\OpenCV2.1\include;<不可加空格!!!!!!>
3.2. 程式目錄 增加 C:\OpenCV2.1\lib;<不可加空格!!!!!!>
3.3. Link Input 增加 cv210.lib; cxcore210.lib; highgui210.lib;<不可加空格!!!!!!>
屬性介面
3.1. Include 目錄 (小心,c:\opencv2.1\include;後面不可以加空格哦)
3.2. 程式目錄 (小心,c:\opencv2.1\lib;後面不可以加空格哦)
3.3. 設定 Link 的 Input 加入 cxcore210.lib; cv210.lib; highgui210.lib;

#include "stdafx.h"
#include <opencv/highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
IplImage * img = cvLoadImage("1.jpg");
cvShowImage("window",img);
cvWaitKey(0);
return 0;
}
範例程式3:(opencv--視訊)
#include "stdafx.h"
#include <opencv/highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
CvCapture * cap = cvCreateCameraCapture(0);
IplImage * img = cvQueryFrame(cap);
while(1){
img=cvQueryFrame(cap);
cvShowImage("img",img);
int key=cvWaitKey(33);
if(key==27) break;
}
cvReleaseCapture(&cap);
return 0;
}
範例程式4:(opencv--視訊相框)
心得:
之前都是使用Dev C++來跑OpenCV,此次上課小葉老師教使用Visual studio C++來跑OpenCv,雖然安裝和設定步驟有點煩雜,以及執行時會出現小錯誤等,但最後成功時也會莫名的開心和有成就感,藉由這次上課所教的之後也可以回家試著安裝看看。
沒有留言:
張貼留言