尝试对视频的帧执行灰度转换,但当我到达 cvCvtColor 时,不断出现断言失败错误。 有人看到我的错误在哪里吗?
IplImage *frame, *frame_copy = 0;
// capture frames from video
CvCapture *capture = cvCaptureFromFile( "lightinbox1.avi");
//Allows Access to video propertys
cvQueryFrame(capture);
//Get the number of frames
int nframe=(int) cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT);
//Name window
cvNamedWindow( "video:", 1 );
//start loop
for(int i=0;i<nframe;i++){
//prepare capture frame extraction
cvGrabFrame(capture);
cout<<"We are on frame "<<i<<"\n";
//Get this frame
frame = cvRetrieveFrame( capture );
con2txt(frame);
frame_copy = cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,frame->nChannels );
//show and destroy frame
cvCvtColor( frame,frame,CV_RGB2GRAY);
cvShowImage("video:",frame);
cvWaitKey(33);}
cvReleaseCapture(&capture);
}
最佳答案
实际上,问题在于带有 CV_RGB2GRAY
的 cvCvtColor()
需要带有 nChannels == 1
的输出图像。
要解决此问题,您必须将复制过程调整为:
frame_copy = cvCreateImage(cvSize(frame->width,frame->height), IPL_DEPTH_8U, 1);
cvCvtColor(frame, frame_copy, CV_RGB2GRAY);
关于c++ - Opencv 视频帧给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8243378/