python - CV2影像内存体

标签 python opencv

我有一个在图像上绘制矩形的功能。输入的图像始终是相同的,但是如果我再次运行它,则运行该函数绘制并绘制具有轮廓的图像后,它将保留旧的轮廓。每次都在函数的开头读取原始图像,所以我不明白为什么它不像以前没有绘制轮廓那样初始化它。
我是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/

相关文章:

c++ - 传递强硬的论据

python - 使用 openCV 根据引用点对齐扫描文档

python - 将列表与列表进行比较以获取与我们正在比较的列表最接近匹配的列表

c++ - OpenCV - 如何实现渐变图像模糊效果?

python - opencv 训练分类器从不连续 3 阶段

python - socket.getfqdn() 不返回域,但 socket.gethostname() 返回域吗?

c++ - cvCreateFileCapture()

Python 捕获超时并重复请求

python - 如何接受 JSON POST?

python - Postgresql 从 docker 容器 bash 中的表中选择