1

I have an images and convert it into gray scale, find the gaussianblur and threshold , I detect the horizontal lines . Now I want to count the numbers of horizontal lines present in the table (images) . Please tell me how to count ?`

my code :

import cv2
import numpy as np

# Load image, grayscale, Gaussian blur, Otsu's threshold
image = cv2.imread('1.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Detect horizontal lines
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (50,1))
horizontal_mask = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=1)

cv2.imshow('image',horizontal_mask)

image1 : enter image description here

Amit Saini
  • 136
  • 2
  • 16
  • Please show ```JIS_name.jpg``` –  May 26 '21 at 08:06
  • I have added the image – Amit Saini May 26 '21 at 08:11
  • do you see horizontal lines in that image? they are all under some angle. Also, do you expect to get output n=5 or n=7 ? – B.Kocis May 26 '21 at 09:27
  • I want to get the output as n=7 – Amit Saini May 26 '21 at 10:03
  • Since the table is a nice rectangle, but it's not oriented parallel to the axes, find the outer contour, then get the rotated rectangle that fits it. Use that to rotate the image to get the lines horizontal. Crop the image to the table borders and invert the image (so background is 0 and lines/text is white). Calculate per-row mean. threshold it (say over 200), and maybe cluster adjacent rows. That, IMHO should give you a nice approximation of where the horizontal lines are. – Dan Mašek May 27 '21 at 00:19
  • okay , Thanks you . – Amit Saini May 27 '21 at 08:49

1 Answers1

0

You can try something the the Hough Line Transform to detect lines.

Louis Lac
  • 5,298
  • 1
  • 21
  • 36
  • In the given image there are 7 horizontal lines . and 6 rows . so I want to get the number of lines which present in the given images (horizontal lines) . I have apply the hougn line transform .but I could not get number of horizontal lines. – Amit Saini May 26 '21 at 10:18
  • Take a look at the documentation and the many tutorials on OpenCV website and online, this will help you for sure – Louis Lac May 26 '21 at 13:42