img2table icon indicating copy to clipboard operation
img2table copied to clipboard

kernel_dims issue in identify_straight_lines due to min_line_length is 0

Open akshayrakate085 opened this issue 1 year ago • 2 comments

Using img2table 1.3.0

The error I am getting for a few images:

/lib/python3.10/site-packages/img2table/tables/processing/bordered_tables/lines.py:23, in identify_straight_lines(thresh, min_line_length, char_length, vertical)
     21 # Apply masking on image
     22 kernel_dims = (1, round(min_line_length / 3)) if vertical else (round(min_line_length / 3), 1)
---> 23 kernel = cv2.getStructuringElement(cv2.MORPH_RECT, kernel_dims)
     24 mask = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel, iterations=1)
     26 # Apply closing for hollow lines

**Error: OpenCV(4.10.0) /io/opencv/modules/imgproc/src/filterengine.hpp:367: error: (-215:Assertion failed) anchor.inside(Rect(0, 0, ksize.width, ksize.height)) in function 'normalizeAnchor'**

Looks like it's because the kernel dimensions (ksize) being passed to cv2.getStructuringElement are invalid, either being too small (e.g., 0 or negative) or not properly computed.

I tried recreating recreate this error using:

min_line_length = 0.1
vertical = 0

# Apply masking on image
kernel_dims = (1, round(min_line_length / 3)) if vertical else (round(min_line_length / 3), 1)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, kernel_dims)

Please look into this.

akshayrakate085 avatar Sep 09 '24 06:09 akshayrakate085

Hi,

I will look intro it. Are you able to provide an image where it is failing so I can verify the cause of the problem?

xavctn avatar Sep 10 '24 06:09 xavctn

Hi, Thanks for the quick response. Unfortunately, I can't share those images as they are confidential.

In case you need to know the OCR instance name, I am using the SuryaOCR.

However, I discovered that when we have a Barcode or QR code in the image, it gives that error. I tried using a dummy image of the barcode and QR code.

akshayrakate085 avatar Sep 10 '24 06:09 akshayrakate085