Ask Your Question
1

how to remove drawings from Mat ?

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

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
3

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

kbarni gravatar image

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

cv::Mat orig, result;
orig=imread("image.jpg");
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
    cv::waitKey();
}
edit flag offensive delete link more

Comments

Thank u for the answer, its working.

dineshlama gravatar imagedineshlama ( 2019-03-09 00:45:55 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 6,684 times

Last updated: Mar 07 '19