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);
}
Actually, the problem is that
cvCvtColor()withCV_RGB2GRAYexpects an output image withnChannels == 1.To solve the issue, you must adjust your copy procedure to: