[英]opencv: Convert Mat to IplImage Issue
In my program I have to mix the c++ and c api a bit. 在我的程序中,我必须混合使用c ++和c api。
I capture an image with the c api and get one frame: 我使用c api捕获图像并获得一帧:
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
以与新的c ++ api兼容,我获得了投资回报率:
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: 最后,我必须将Mat转换回IplImage *以使用c api:
IplImage imgCaptureFrame = roi;
when I use this as reference &roi I get a 当我用这个作为参考和roi我得到一个
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. 在使用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. 没有任何错误,但我没有我的roi。
What can I do to convert my roi to use it in c api? 我该怎么做才能转换我的roi在c api中使用它?
To convert an IplImage*
to cv::Mat
and make an independent copy, do: 要将
IplImage*
转换为cv::Mat
并制作独立副本,请执行以下操作:
cv::Mat captureFrame = cv::Mat(image, true);
To create a ROI for captureFrame
you could do something like: 要为
captureFrame
创建ROI,您可以执行以下操作:
cv::Rect roi;
roi.x = 165;
roi.y = 50;
roi.width = 440;
roi.height = 80;
cv::Mat cropped = new cv::Mat(captureFrame, roi);
and finally, to do the conversion the other way: 最后,以另一种方式进行转换:
IplImage imgCaptureFrame = cropped;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.