Mat to IplImage崩溃

时间:2013-07-24 13:21:21

标签: opencv

运行我的代码时,相机会继续崩溃。试图将cv :: mat转换为IplImage。

cv::Mat canvas(320, 240, CV_8UC3, Scalar(255,255,255));

 IplImage test =canvas;

  while(true )
{  

 canvas =cvQueryFrame(capture);
 imgScribble = cvCreateImage(cvGetSize(&test), 8, 3);

 IplImage* imgYellowThresh1 = GetThresholdedImage1(&test);

cvAdd(&test,imgScribble,&test);

cvShowImage("video", &test);

1 个答案:

答案 0 :(得分:1)

//This is the only line that uses the C++ API, so I assume you want to use the C API instead     
cv::Mat canvas(320, 240, CV_8UC3, Scalar(255,255,255)); 
//I have used OpenCV for quite a while now and I've always declared IplImage*, and never IplImage. Use it safely as a rule of thumb, * always goes after IplImage
 IplImage test =canvas; 

这将成为:

//although why you need to clone a newly created
//blank image is a valid concern
IplImage* canvas = cvCreateImage(....); 
IplImage* test = cvClone(canvas);   
cvZero(test);
//don't forget to release resources at some point
cvReleaseImage(&canvas);
cvReleaseImage(&test);