I have a function to draw rectangles on an image. The input image is always the same but after I run the function to draw and plot the image with contours if I run it again, it keeps the old contour. The original image is read at the beginning of the function every time so I don't understand why it doesn't initialize it as if no contour were drawn previously.
I'm new to python and opencv
. Please let me know if you have any suggestion to clear the image before applying contours again
def get_last_col(date_headers):
n_tables = len(date_headers)
print(n_tables)
image=date_headers[0][0]
for header in date_headers:
h_d = header[1]
page_h = image.shape[0]
last_col = h_d[h_d.bloc_x==max(h_d.bloc_x)]
last_col['width'] = last_col.bloc_xw - last_col.bloc_x
min_w = int(min(last_col.width))
# X of most bottom left corner date in header
bottom_left = min( int(min(last_col['bloc_x'])-50), int(min(last_col['bloc_x'])-min_w) )
# Y of of most bottom date element
bottom_top = int(last_col.Y_DATE)-20
#X of most bottom right corner date in header
bottom_right = int(max(h_d['bloc_xw'])+min_w)-10
cv2.rectangle(image, (bottom_left,bottom_top), (bottom_right,page_h), (36,255,12), 2)
plt.figure(figsize = (30,30))
plt.imshow(image)
Examples after running the function once and then once again with a different contour
我通过使用图像的副本 (date_headers[0][0].copy()) 弄清楚了
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.