erasing the rectangle drawn in image [closed]
I am doing object tracking. At sometimes if object is going out of frame i want to clear the rectangle which i have drawn. is it possible to clear rectangle after it is drawn?
VideoCapture cap(0);
Mat frame;
bool trackerUptated,isObjectdetected;
Rect2d roi;
tracker->init(frame, roi);
for (;;)
{
cap >> frame;
trackerUptated = tracker->update(frame, roi);
if (trackerUptated)
{
rectangle(frame, roi, Scalar(255, 255, 255), 2, 1);
}
else if (!trackerUptated)
{
cap >> frame;
detectObject(&cap, &roi, ¢er, &detectedObject, &isObjectdetected);
tracker->update(frame, roi);
rectangle(frame, roi, Scalar(255, 255, 255), 2, 1);
if ((roi.x > 490 || roi.x < -10) || (roi.y > 650 || roi.y < -10)) {
cout << "outside" << endl;
detectObject(&cap, &roi, ¢er, &detectedObject, &isObjectdetected);
}
}
imshow("tracker", frame);
if (waitKey(1) == 27)break;
}
To achieve that you'll need to draw on transparent overlay image instead.
next to impossible. you'd rather NOT draw anything then ?
@Ziri is there any another way so that i could do it? I am updating tracker also. but only problem is when object goes out of frame. @berak I am detecting it and not even drawing the new rectangle. but the rectangle which is previously drawn is at that place. so i just want to clear that previous rectangle.
how can that be ? if so, there's something wrong in your prog.
you should get a fresh image every time, no ?
@berak every time i am getting fresh image. but will look in program again.
add you code to the question, then we can take a look.
@berak i have updated the question please check
(blindly) suggestion :