0

I got some tables with missing lines, so that the cells are not closed (the cover is missing). The open lines I don't want to have extended vertically, but rather I want to draw a horizontal line to close them. Is there any way to detect open lines and retrieve the end position of them to draw exactly there a contour?

enter image description here

I tried the following code (from https://stackoverflow.com/questions/22240746/recognize-open-and-closed-shapes-opencv ), but it did not draw the lines in the image:

img_vh = cv2.imread('YOURPATH')

ret, thresh = cv2.threshold(img_vh, 200, 255, cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
hierarchy = hierarchy[0]


for i, c in enumerate(contours):
    if hierarchy[i][2] < 0 and hierarchy[i][3] < 0:
        lined = cv2.drawContours(img_vh, contours, i, (0, 0, 255), 2)
    else:
        lined = cv2.drawContours(img_vh, contours, i, (0, 255, 0), 2)
cv2.imwrite("YOURPATH/lined.jpg", lined)
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
hux0
  • 207
  • 1
  • 4
  • 17
  • Have you looked at [How to repair incomplete grid cells and fix missing sections in image](https://stackoverflow.com/questions/60361575/how-to-repair-incomplete-grid-cells-and-fix-missing-sections-in-image/60386876)? – coffeewin Apr 09 '20 at 20:49
  • @coffeewin thanks! The method used by nathancy fills up holes in existing lines, I would like to fill in completely missing lines though. – hux0 Apr 14 '20 at 07:38

0 Answers0