簡單過生活

跳到主文

簡單過生活 iammic@livemail.tw

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 7月 24 週日 201122:27
  • Visual Studio 2010:OpenCV 2.3 使用 WebCam

iammic 今天找了一下用來顯示 WebCam 影像的程式,在 Windows 7 試了一下,不知道什麼原因很

多 Sample 程式都無法正常顯示,最後改試 OpenCV 才成功顯示。以下紀錄 VC++ OpenCV 2.3 開發

環境設定與一個簡單的 WebCam 範例程式。

 

SETP1:下載 OpenCV-2.3.0-win-superpack.exe,解壓縮檔案到 C:\OpenCV2.3

SETP2:設定 PATH 環境變數

C:\OpenCV2.3\build\bin;C:\OpenCV2.3\build\vc10\bin;

image

SETP3:在 Visual Studio 2010 中建立 VC++ Win32 主控台應用程式

2011-07-24_142558

SETP4:點選 專案->屬性->VC++ 目錄 設定

Include 目錄:

C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\build\include\;

程式庫目錄:

C:\OpenCV2.3\build\vc10\lib;

 

image

SETP5:點選 專案->屬性->連結器->輸入 設定

其他相依性:

opencv_core230d.lib;opencv_highgui230d.lib;opencv_imgproc230d.lib;opencv_legacy230d.lib;opencv_ml230d.lib;opencv_video230d.lib;

image

 

程式碼:

#include "stdafx.h"
#include <atltime.h>
#include <highgui.h>
 
int _tmain(int argc, _TCHAR* argv[])
{ 
 int c;
 CTime time;
 IplImage *img; 
 CvCapture* capture = cvCaptureFromCAM(1); 
 cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
 cvMoveWindow("mainWin", 5, 5); 
 
 while(1)
 { 
 img=cvQueryFrame(capture); 
 cvShowImage("mainWin", img ); 
 c=cvWaitKey(10); 
 
 //按鍵盤 s 鍵儲存成 jpg 檔
 if(c=='s'){ 
 time = CTime::GetCurrentTime(); 
 CStringA filename(time.Format(CString("%Y%m%d%H%M%S"))+".jpg"); 
 cvSaveImage(filename,img);
 }
 
 //按鍵盤 ESC 離開
 if(c == 27)
 break;
 }
 
 cvReleaseImage(&img); 
 cvDestroyWindow("mainWin");
 
 return 0;
}

 

參考網站:

http://siddhantahuja.wordpress.com/2011/07/18/getting-started-with-opencv-2-3-in-microsoft-visual-studio-2010-in-windows-7-64-bit/

文章標籤
全站熱搜
創作者介紹
創作者 iammic 的頭像
iammic

簡單過生活

iammic 發表在 痞客邦 留言(0) 人氣(10,596)

  • 全站分類:
  • 個人分類:OpenCV
▲top

文章搜尋

文章分類

  • python (0)
  • Java (0)
  • Linux (0)
  • Windows (0)
  • PHP (0)
  • .Net (0)
  • JavaScript (0)
  • 軟體 (0)
  • 其它 (0)
  • 電子入門筆記 (0)
  • Flash 學習筆記 (0)
  • Vbscript (0)
  • OpenCV (0)
  • SQL Server (0)
  • PLC (0)
  • Labview (0)
  • 控制器 (0)
  • Mac (0)
  • HMI (0)
  • WinCC (0)
  • Arduino (0)
  • AVR (0)
  • 嵌入式 Linux (0)
  • FOTRAN (0)
  • 未分類文章 (1)

熱門文章

  • ()PHP 儲存圖片到 MySQL
  • ()VB.NET 簡單的 Excel 檔讀寫
  • ()使用程式語言取得三菱 PLC 點位資料 - 範例程式
  • ()Windows Server 2008 R2 防火牆開啟 SQL Server 1433 Port
  • ()三菱 PLC :QJ71E71-100 簡單設定
  • ()CentOS vsftpd FTP Server 安裝設定
  • ()安裝三菱 Q系列 PLC USB 連接線驅動程式
  • ()製作可開機 USB 隨身碟
  • ()Windows 新增虛擬網卡
  • ()磁碟建立分割工具 diskpart
iammic
PIXNET Logo登入

參觀人氣

  • 本日人氣:0
  • 累積人氣:741,425