Home:ALL Converter>opencv: Convert Mat to IplImage Issue

opencv: Convert Mat to IplImage Issue

Ask Time:2014-01-06T00:02:01         Author:user2737037

Json Formatter

In my program I have to mix the c++ and c api a bit.

I capture an image with the c api and get one frame:

CvCapture* capture = 0; 
capture = cvCaptureFromCAM(0);

// some code

IplImage* image = cvQueryFrame(capture);

Then it is converted to Mat to be compatible with the new c++ api and I get a ROI:

Mat captureFrame = cvarrToMat(image);

// some code

Mat roi = captureFrame(roiRect);

At the end I have to convert the Mat back to IplImage* to work with the c api:

IplImage imgCaptureFrame = roi;

when I use this as reference &roi I get a

OpenCV Error: Assertion failed (svec[j].size == dst.size && svec[j].depth() == d
st.depth() && svec[j].channels() == 1 && i < dst.channels()) in unknown function
, file C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\src\convert.
cpp, line 1306

in code using c api.

When I just use

IplImage imgCaptureFrame = captureFrame;

instead of

IplImage imgCaptureFrame = roi;

there isn't any error but then I don't have my roi.

What can I do to convert my roi to use it in c api?

Author:user2737037,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20935694/opencv-convert-mat-to-iplimage-issue
yy