Opencv视频帧给我一个错误 [英] Opencv video frame giving me an error
本文介绍了Opencv视频帧给我一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试对视频上的帧执行灰度变换,但是当我到达cvCvtColor时,仍然收到断言失败的错误。
有人看到我的错误是在哪里?
Trying to perform grayscale transformation on frames on a video ,but keep getting Assertation failed error when I get to cvCvtColor. Does anyone see where my error is?
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);
}
推荐答案
实际上,问题是 cvCvtColor()
与 CV_RGB2GRAY
期望输出图像 nChannels == 1
。
要解决此问题,您必须将复制过程调整为:
To solve the issue, you must adjust your copy procedure to:
frame_copy = cvCreateImage(cvSize(frame->width,frame->height), IPL_DEPTH_8U, 1);
cvCvtColor(frame, frame_copy, CV_RGB2GRAY);
这篇关于Opencv视频帧给我一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文