我的是win7 64 位,配置的是VS2010+OPENCV2.4.9 程式的代碼如下:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
// VideoCapture capture("F:\\video\\1.avi"); //讀視頻
VideoCapture capture(0); //讀攝像頭
while(1)
{
Mat frame;
capture>>frame;
imshow("readvideo",frame);
waitKey(30);
}
return 0;
}
運行到imshow函式時就出現這個錯誤

我是新手,剛剛學,上網找了很多方法,包括改waitKey的時間什么的,都沒有用,有沒有大神知道這是什么問題啊。
uj5u.com熱心網友回復:
我剛好有一段代碼,給你參考一下。
void ThreadFunction(void* Param)
{
FacePhoto* _this =(FacePhoto*)Param;
IplImage *frame, *frame_copy = 0;
cascade = (CvHaarClassifierCascade*)cvLoad( "haarcascade_frontalface_alt.xml", 0, 0, 0 );
if( !cascade )
return;
eye_cascade = (CvHaarClassifierCascade*)cvLoad("haarcascade_eye.xml",0,0,0);
if(!eye_cascade)
return;
storage = cvCreateMemStorage(0);
CvCapture* capture = cvCaptureFromCAM(0);
int rw = cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 1920);
int rh = cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 1080);
if( capture )
{
_this->ThreadExit = false;
while(!_this->ThreadTerminated())
{
if(_this->IfTakePhotoPaused())
continue;
if( !cvGrabFrame( capture ))
break;
frame = cvRetrieveFrame( capture );//從攝像頭抓取一幀影像
if( !frame )
break;
if( !frame_copy )
frame_copy = cvCreateImage( cvSize(frame->width,frame->height),
IPL_DEPTH_8U, frame->nChannels );
if( frame->origin == IPL_ORIGIN_TL )
cvCopy( frame, frame_copy, 0 );
else
cvFlip( frame, frame_copy, 0 );
//gWaitCount ++;
_this->DetectAndDraw( frame_copy );
cvReleaseImage( &frame_copy );
}
}
cvReleaseCapture( &capture );
_this->ThreadExit = true;
cvReleaseMemStorage(&storage);
cvReleaseHaarClassifierCascade(&cascade);
cvReleaseHaarClassifierCascade(&eye_cascade);
g_event.SetEvent();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/80102.html
標籤:基礎類
下一篇:這段代碼什么意思?請教大神。
