Ibraim Ganiev
Ibraim Ganiev

Reputation: 9410

Finding crosses and their orientation on a given image

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)
 cv2.waitKey(0)

Thanks in advance for any response/idea.

Upvotes: 0

Views: 360

Answers (1)

FiReTiTi
FiReTiTi

Reputation: 5898

You want to use the Hough Transform. It will detect the different lines, and you will have the equations/orientations.

An other solution, maybe simpler is to:

  1. Compute the skeleton
  2. Strong pruning in order to delete all the small branches
  3. Then, if a pixel has 3 neighbors it belongs to a T shape intersection, if it has 4, it's a cross intersection.

Upvotes: 1

Related Questions