我有一个在图像上绘制矩形的函数。输入图像总是相同的,但是在我运行函数来绘制和绘制带有轮廓的图像之后,如果我再次运行它,它会保持旧的轮廓。每次在函数开始时读取原始图像,所以我不明白为什么它不初始化它,就好像以前没有绘制过轮廓一样。
我是python和opencv的新手。如果您有任何建议在再次应用轮廓之前清除图像,请让我知道
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)使用不同的等高线再次运行函数后的示例
发布于 2020-11-01 21:33:14
我通过使用图像的副本(date_headers.copy())解决了这个问题。
https://stackoverflow.com/questions/64628659
复制相似问题