當前位置:編程學習大全網 - 源碼下載 - 跪求用USB攝像頭獲取並保存圖像的c或c++代碼

跪求用USB攝像頭獲取並保存圖像的c或c++代碼

可以通過Intel的opencv庫來做,這個庫提供的功能比較多。

支持很多功能,使用起來也算簡單。

相信的內容可以參考www.opencv.org.cn

需要配置這個庫

下面代碼是從這個網址轉來的,可以參考下

/bbs/thread-327-1-1.html

/* jink2005編寫於www.aiseminar.cn */

#include "stdio.h"

#include "cv.h"

#include "highgui.h"

#pragma comment(lib, "cv.lib")

#pragma comment(lib, "cxcore.lib")

#pragma comment(lib, "highgui.lib")

int main(int argc, char* argv[]) {

/* 通過攝像頭采集壹幀圖像 */

IplImage* img = 0;

CvCapture* capture = cvCaptureFromCAM(0);

if (! cvGrabFrame(capture)) { // 采集壹幀

printf("Could not grab a frame!\n\7");

exit(0);

}

img = cvRetrieveFrame(capture); // 提取采集到的幀

/* 獲得此幀的相關信息 */

cvQueryFrame(capture); // 此調用是獲得正確的采集屬性所必需的

int frameH = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);

int frameW = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);

/* 顯示圖像到窗口 */

cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); // 創建窗體

cvShowImage("mainWin", img);

/* 釋放采集源對像 */

cvReleaseCapture(&capture);

// 等待壹個任意鍵

cvWaitKey(0);

cvReleaseImage(&img);

return(0);

}

  • 上一篇:試試這些工具打開PDF文件推薦給學生
  • 下一篇:神霧節能股票(神霧節能股票走勢分析)
  • copyright 2024編程學習大全網