Ask Your Question

how to remove drawings from Mat ?

asked 2019-03-07 08:05:43 -0500

dineshlama gravatar image

I have to draw few rectangles in image in such a way than when new rectangles arrives the previous rectangles i.e drawings has to be gone from the Mat. I tried to use image.release() but its not working. This is the line of code which is executed multiple time for different object detected in image.

for(auto v : obj_pixel)
    cv::rectangle(cv_ptr->image,cv::Point( v.x-0.1,v.y-0.1),cv::Point( v.x+0.1,v.y+0.1),cv::Scalar( 0, 0, 0 ),cv::FILLED);

How can i perform this task?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-03-07 10:46:51 -0500

kbarni gravatar image

Make a copy at each iteration of your image and draw on that copy.

cv::Mat orig, result;
while(1) {
    orig.copyTo(result); //make a new copy of the original image
    Rect detection=processimage(orig); //here you put the processing that returns some result.
    cv::rectangle(result,detection,cv::Scalar(0,0,0)); //draw the result to the copy of the image
    cv::imshow("Result",result); // display it
edit flag offensive delete link more


Thank u for the answer, its working.

dineshlama gravatar imagedineshlama ( 2019-03-09 00:45:55 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2019-03-07 08:05:43 -0500

Seen: 1,768 times

Last updated: Mar 07 '19