For example, there might be a table with text in rows. How could I find all straight, horizontal lines going through the table? E.g. (red lines are the found lines):
Asked
Active
Viewed 544 times
0
-
3This is my result using `morph-op` :https://i.stack.imgur.com/5ysGA.png – Kinght 金 Dec 06 '17 at 05:36
-
A simple color segmentation using `cv2.inRange()` would work well here – ZdaR Dec 06 '17 at 05:38
-
Is the color of the line always the same? – janu777 Dec 06 '17 at 05:55
-
@Silencer that is the correct answer, you should write it as an answer for completeness :) – api55 Dec 06 '17 at 12:25
-
@api55 Ok, I'll write the answer. – Kinght 金 Dec 06 '17 at 13:08
1 Answers
6
Just for this question
, to detect the horizontal lines
, the morph-op
is enough.
import cv2
img = cv2.imread("test.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1,100), np.uint8)
morphed = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
cv2.imshow("res", morphed);cv2.waitKey();cv2.destroyAllWindows()
Update, similar questions:

Kinght 金
- 17,681
- 4
- 60
- 74