我有一个在图像上绘制矩形的功能。输入的图像始终是相同的,但是如果我再次运行它,则运行该函数绘制并绘制具有轮廓的图像后,它将保留旧的轮廓。每次都在函数的开头读取原始图像,所以我不明白为什么它不像以前没有绘制轮廓那样初始化它。
我是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)
一次运行该函数后再以不同的轮廓再次运行的示例first run
second run
最佳答案
我通过使用图像的副本(date_headers [0] [0] .copy())弄清楚了
关于python - CV2影像内存体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64628659/