Reputation: 569
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?
Upvotes: 0
Views: 203
Reputation: 50667
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));
Upvotes: 1