erasing the rectangle drawn in image [closed]

asked 2018-08-21 15:55:08 -0600

saniket123 gravatar image

updated 2018-08-22 02:54:41 -0600

berak gravatar image

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, &center, &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, &center, &detectedObject, &isObjectdetected);   
            }   
 }   
    imshow("tracker", frame);      
    if (waitKey(1) == 27)break;   
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-14 23:51:54.324380

Comments

To achieve that you'll need to draw on transparent overlay image instead.

Ziri gravatar imageZiri ( 2018-08-21 23:25:24 -0600 )edit

next to impossible. you'd rather NOT draw anything then ?

berak gravatar imageberak ( 2018-08-21 23:48:26 -0600 )edit

@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.

saniket123 gravatar imagesaniket123 ( 2018-08-22 00:10:24 -0600 )edit

but the rectangle which is previously drawn is at that place

how can that be ? if so, there's something wrong in your prog.

you should get a fresh image every time, no ?

berak gravatar imageberak ( 2018-08-22 00:13:52 -0600 )edit

@berak every time i am getting fresh image. but will look in program again.

saniket123 gravatar imagesaniket123 ( 2018-08-22 00:21:19 -0600 )edit

add you code to the question, then we can take a look.

berak gravatar imageberak ( 2018-08-22 00:22:47 -0600 )edit
1

@berak i have updated the question please check

saniket123 gravatar imagesaniket123 ( 2018-08-22 01:14:03 -0600 )edit
1

(blindly) suggestion :

tracker->update(frame, roi);   

    if ((roi.x > 490 || roi.x < -10) || (roi.y > 650 || roi.y < -10)) {   
        cout << "outside" << endl;   
        detectObject(&cap, &roi, &center, &detectedObject, &isObjectdetected);   
        }
     else  rectangle(frame, roi, Scalar(255, 255, 255), 2, 1);
sturkmen gravatar imagesturkmen ( 2018-08-22 03:07:22 -0600 )edit