Removing long horizontal/vertical lines from edge image using OpenCV

前端 未结 5 1992
半阙折子戏
半阙折子戏 2020-12-31 12:45

How can I use standard image processing filters (from OpenCV) to remove long horizontal and vertical lines from an image?

The images are B&W so removing means si

5条回答
  •  清酒与你
    2020-12-31 12:59

    if your lines are truly horizontal/vertical, try this

    import cv2
    import numpy as np
    img = cv2.imread('c:/data/test.png')
    gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    linek = np.zeros((11,11),dtype=np.uint8)
    linek[5,...]=1
    x=cv2.morphologyEx(gray, cv2.MORPH_OPEN, linek ,iterations=1)
    gray-=x
    cv2.imshow('gray',gray)
    cv2.waitKey(0)    
    

    result

    enter image description here

    You can refer OpenCV Morphological Transformations documentation for more details.

提交回复
热议问题