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?
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)