简体   繁体   中英

opencv: error after conversion of an iplimage to a mat

i need to convert a mat to iplimage and back, in order to draw a line. My code so far:

Mat mat = imread(path);
Point p,q;
...
imwrite(path1,mat1);
IplImage img = mat1;
cvDrawLine(&img,p,q,Scalar(0,0,255));
mat1 = Mat(&img);    //i also tried mat1=&img;
imwrite(path2,mat1);

the first imwrite works, but at the second, i get an exception. Any ideas?

You can use cv::cvarrToMat to convert CvMat , IplImage , or CvMatND to Mat .

For your case, it will be like:

mat1 = cv::cvarrToMat(&img, true); 

PS: As commented by @Miki, you should avoid obsolete C OpenCV APIs. Using C++ APIs, it will simply be:

cv::line(mat1, p, q, cv::Scalar(0, 0, 255));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM