简体   繁体   English

CV2 图像存储器

[英]CV2 Image Memory

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 .我是 python 和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运行该函数一次后的示例,然后使用不同的轮廓再次运行

first run第一次运行

second run第二次运行

我通过使用图像的副本 (date_headers[0][0].copy()) 弄清楚了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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