Skip to content

kernel_dims issue in identify_straight_lines due to min_line_length is 0 #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
akshayrakate085 opened this issue Sep 9, 2024 · 2 comments

Comments

@akshayrakate085
Copy link

akshayrakate085 commented Sep 9, 2024

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.

@xavctn
Copy link
Owner

xavctn commented Sep 10, 2024

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?

@akshayrakate085
Copy link
Author

akshayrakate085 commented Sep 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants