0

Table on image

I have not bordered table like on picture .

I tried to use example from this post I have got this result

Result image

But I need something like this Needed result

How I could tune Open CV to get needed result?

dm k
  • 111
  • 3
  • 9

1 Answers1

0

You can easily achieved by using image_to_data method of pytesseract.

You also need to know:


Steps:

    1. Load the image in BGR mode and convert it to the gray-scale
    1. Get region-of-interest areas
    1. From each area, get the coordinates and draw rectangle.

Result:

enter image description here

Code:


# Load the library
import cv2
import pytesseract

# Load the image
img = cv2.imread("1Tksb.jpg")

# Convert to gry-scale
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# OCR detection
d = pytesseract.image_to_data(gry, config="--psm 6", output_type=pytesseract.Output.DICT)

# Get ROI part from the detection
n_boxes = len(d['level'])

# For each detected part
for i in range(n_boxes):

    # Get the localized region
    (x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])

    # Draw rectangle to the detected region
    cv2.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 1)

# Display
cv2.imshow("img", img)
cv2.waitKey(0)

If you want to read you can use image_to_string method.

Ahmet
  • 7,527
  • 3
  • 23
  • 47