简体   繁体   中英

How can I erase the contours drawn in the same image using Python OpenCV?

I am wondering is there a way to erase/delete the Contours drawn on the image from the function cv2.drawContours ?

Right now, I can get all the rectangles drawn on the images as shown below:

所有矩形

And to draw the rectangles, I used the following codes. Note that items is a list of points

rect = cv2.minAreaRect(np.array(items))
box = cv2.boxPoints(rect)
box = np.int0(box)
cv2.drawContours(img, [box], 0, [0,0,255], 1)

However, I hope only one rectangle is shown on the same image each time, but not all the rectangles are shown on the same image.

For example,

This is the first rectangle to be shown.

However, when the second rectangle is shown, the first rectangle should be disappeared but not still on the image.

Hopes someone could help me out. Thanks!

box here is a list probably, so instead of plotting all the points in box on your original image, only plot the point which is at the i th index of the list and iterate through the box list plotting each point on the original image only. You will need to make multiple, cv2 windows for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM