I want to recognize table structure from some arbitrary photo image and store it in some formal notation (Let it be HTML table notation).

For example I have this blurry image as input: enter image description here

After binarization I achieved this: enter image description here

Now to detect structure I want to detect intersections between lines, their type (T-type, X-type, or simple corner), their orientations and their location on the image. After this I'm going to use all gained information for further joining of adjacent crosses in some structure, and translate this structure into formal representation.

The problem is in detecting crosses and their orientation: enter image description here enter image description here

In general these crosses may be scaled and/or rotated. Maybe someone could help with method of solving this problem? Or maybe recommend different methods for this whole task?

That's what I have written so far:

 # -*- coding: utf-8 -*-

 import cv2
 import cv
 import numpy

 original = cv2.imread("/home/user/my_photo-1.jpg")
 grayscale = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
 smoothed = cv2.GaussianBlur(grayscale, (5,5), 0)
 cv2.imshow("original", original)
 cv2.imshow("grayscale", grayscale)

 binarized = cv2.adaptiveThreshold(grayscale, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 7, 8)
 binarized = cv2.Canny(grayscale, 50, 200)
 cv2.imshow("binarized", binarized)

Thanks in advance for any response/idea.

  • 1
    $\begingroup$ You have a better chance of getting answers if you narrow down your question a bit. Your question as stated is too broad. Try explaining what you know, what you've tried, and what specific problem you're facing. $\endgroup$
    – MBaz
    Mar 27, 2016 at 21:18

1 Answer 1


Try to use cv2.HoughLinesP (see an example) to detect the straight lines (segments). As a result you will get the segments' endpoints, so finding all the intersections and its type will be quite simple maths. The problem will be rather with finding the proper and universal parameters.

Theoretically you could use a morphological operation called hit-and-miss transform, but this will be difficult in your case, as the lines are hand-drawn and even after thinning the crosspoints may be difficult to be properly classified (as 'T', '+' or 'corner').

I would suggest you to make some morphological preprocessing to improve the binary image you have got.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.