#include "stdafx.h" #include "cv.h" #include "highgui.h" #include "iostream" using namespace std; int main(int argc, char* argv[]) { CvCapture *cap = cvCreateCameraCapture(0);//初始化相機捕獲的指針 if (!cap) { cout<<"create camera capture error..."<<endl; system("pause"); exit(-1); } cvNamedWindow("img"); IplImage *img = NULL; while(1) { IplImage *tempImg = cvQueryFrame(cap);//捕獲相機的視頻幀並進行相應的解碼操做 if (img == NULL) { img = cvCreateImage(cvGetSize(tempImg), tempImg->depth, tempImg->nChannels); } cvCopy(tempImg, img);//拷貝到外部的內存 if (img->origin == IPL_ORIGIN_TL)//若是圖片原點在左上角,將其沿X軸翻轉,使得原點位於左下角 { cvFlip(img, img); } cvShowImage("img", img); cvWaitKey(3); } cvDestroyAllWindows(); cvReleaseImage(&img); system("pause"); return 0; }