Skip to content
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

OpenCV(4.10.0) d:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\filterengine.hpp:367: error: (-215:Assertion failed) anchor.inside(Rect(0, 0, ksize.width, ksize.height)) in function 'cv::normalizeAnchor' while using img2table #219

Open
GiriMadhav722001 opened this issue Sep 25, 2024 · 15 comments

Comments

@GiriMadhav722001
Copy link

GiriMadhav722001 commented Sep 25, 2024

I am getting above error while using img2table, please help me to fix the issue
below is the code which I used,

`from img2table.ocr import PaddleOCR
from img2table.document import Image

ocr = PaddleOCR(lang="en")
doc=Image('/content/cropped_image.png')

extracted_tables = doc.extract_tables(ocr=ocr,
implicit_rows=False,
implicit_columns=False,
borderless_tables=True,
min_confidence=50)`

@GiriMadhav722001
Copy link
Author

please help me

@hbh112233abc
Copy link

PixPin_2024-09-27_16-13-21
when min_line_length < 6 then kernel_dims will as (1,0) or (0,1) but cv2.getStructuringElement params kernel_dims values must > 0 , my solution is change round to ceil function, then kernel_dims values min value = 1,and not raise above exception again

@GiriMadhav722001
Copy link
Author

still i am getting same error
/usr/local/lib/python3.10/dist-packages/img2table/tables/processing/bordered_tables/lines.py 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)
25

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'

@GiriMadhav722001
Copy link
Author

GiriMadhav722001 commented Sep 28, 2024

please help me, exception raised only when I am passing YOLO detected image having table instead of whole pdf,

@GiriMadhav722001
Copy link
Author

cannot recognize vertically reversed text, is not recognized
see the below pictures this is actually not recognized and also some symbols like '-' not recognized

Screenshot 2024-09-28 214756

@GiriMadhav722001
Copy link
Author

GiriMadhav722001 commented Sep 28, 2024

ocr=PaddleOCR(lang='en',use_angle_cls=True)
this extracts all text data from table even text is reversed vertically, extracts symbols as well
when I tried to use this above code I got below error as, please allow use to use that 'use_angle_cls=True'

TypeError Traceback (most recent call last)
in <cell line: 5>()
3
4 # Instantiation of OCR
----> 5 ocr = PaddleOCR(lang="en",use_angle_cls=True)
6 # ocr = EasyOCR(lang=["en"], kw={"gpu": False}
7 # ocr=paddle_ocr = PaddleOCR(lang="en", kw={"use_dilation": True})

TypeError: PaddleOCR.init() got an unexpected keyword argument 'use_angle_cls'

@GiriMadhav722001
Copy link
Author

please help me please

@hbh112233abc
Copy link

ocr=PaddleOCR(lang='en',use_angle_cls=True) this extracts all text data from table even text is reversed vertically, extracts symbols as well when I tried to use this above code I got below error as, please allow use to use that 'use_angle_cls=True'

TypeError Traceback (most recent call last) in <cell line: 5>() 3 4 # Instantiation of OCR ----> 5 ocr = PaddleOCR(lang="en",use_angle_cls=True) 6 # ocr = EasyOCR(lang=["en"], kw={"gpu": False} 7 # ocr=paddle_ocr = PaddleOCR(lang="en", kw={"use_dilation": True})

TypeError: PaddleOCR.init() got an unexpected keyword argument 'use_angle_cls'

look source code img2table.ocr.paddle.py PaddleOCR only parse tow params lang and kw(dict), so init PaddleOCR you should write like below:

ocr = PaddleOCR(lang='en',kw={'use_angle_cls':True})

the kw dict should like baidu's PaddleOCR class params

@GiriMadhav722001
Copy link
Author

still i am getting same error
/usr/local/lib/python3.10/dist-packages/img2table/tables/processing/bordered_tables/lines.py 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)
25

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'

please provide me a solution for this as well

@GiriMadhavB
Copy link

Some time randomly OpenCV(4.10.0) d:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\filterengine.hpp:367: error: (-215:Assertion failed) anchor.inside(Rect(0, 0, ksize.width, ksize.height)) in function 'cv::normalizeAnchor' while using img2table this exception has raised how to address this please help me

@GiriMadhav722001
Copy link
Author

Some time randomly OpenCV(4.10.0) d:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\filterengine.hpp:367: error: (-215:Assertion failed) anchor.inside(Rect(0, 0, ksize.width, ksize.height)) in function 'cv::normalizeAnchor'
This error occurs randomly; how can I address it

@GiriMadhav722001
Copy link
Author

please help me

@kirillkoncha
Copy link

downgrade to 1.2.11 solved this problem for me

@GiriMadhav722001
Copy link
Author

how to install this still showing 1.3.0
even i was used this
!pip install img2table==1.2.
!pip install img2table[paddle]==1.2.11

@GiriMadhav722001
Copy link
Author

friends please help me
page_13_table0
for the above image i am getting the error
error Traceback (most recent call last)
Cell In[251], line 3
1 doc = Image(r"C:\Users\617468422\Desktop\tabledetction\tableDetectionDataExtractiontoExcel\output\detectedTables\4737739_1060182_ARN004_55841_PO0196_M004_EE_AS_AB2\page_13_table0_expanded_top.png")
2 # # Extract tables
----> 3 extracted_tables = doc.extract_tables(ocr=pocr,
4 implicit_rows=False,
5 implicit_columns=False,
6 borderless_tables=False,
7 min_confidence=50)

File ~\AppData\Roaming\Python\Python312\site-packages\img2table\document\image.py:48, in Image.extract_tables(self, ocr, implicit_rows, implicit_columns, borderless_tables, min_confidence)
37 def extract_tables(self, ocr: "OCRInstance" = None, implicit_rows: bool = False, implicit_columns: bool = False,
38 borderless_tables: bool = False, min_confidence: int = 50) -> List[ExtractedTable]:
39 """
40 Extract tables from document
41 :param ocr: OCRInstance object used to extract table content
(...)
46 :return: list of extracted tables
47 """
---> 48 extracted_tables = super(Image, self).extract_tables(ocr=ocr,
49 implicit_rows=implicit_rows,
50 implicit_columns=implicit_columns,
51 borderless_tables=borderless_tables,
52 min_confidence=min_confidence)
53 return extracted_tables.get(0)

File ~\AppData\Roaming\Python\Python312\site-packages\img2table\document\base_init_.py:128, in Document.extract_tables(self, ocr, implicit_rows, implicit_columns, borderless_tables, min_confidence)
125 # Extract tables from document
126 from img2table.tables.image import TableImage
127 tables = {idx: TableImage(img=img,
--> 128 min_confidence=min_confidence).extract_tables(implicit_rows=implicit_rows,
129 implicit_columns=implicit_columns,
130 borderless_tables=borderless_tables)
131 for idx, img in enumerate(self.images)}
133 # Update table content with OCR if possible
134 tables = self.get_table_content(tables=tables,
135 ocr=ocr,
136 min_confidence=min_confidence)

File ~\AppData\Roaming\Python\Python312\site-packages\img2table\tables\image.py:129, in TableImage.extract_tables(self, implicit_rows, implicit_columns, borderless_tables)
126 return []
128 # Extract bordered tables
--> 129 self.extract_bordered_tables(implicit_rows=implicit_rows,
130 implicit_columns=implicit_columns)
132 if borderless_tables:
133 # Extract borderless tables
134 self.extract_borderless_tables()

File ~\AppData\Roaming\Python\Python312\site-packages\img2table\tables\image.py:66, in TableImage.extract_bordered_tables(self, implicit_rows, implicit_columns)
63 min_line_length = int(min(1.5 * self.median_line_sep, 4 * self.char_length)) if self.median_line_sep else 20
65 # Detect rows in image
---> 66 h_lines, v_lines = detect_lines(img=self.img,
67 contours=self.contours,
68 char_length=self.char_length,
69 min_line_length=min_line_length)
70 self.lines = h_lines + v_lines
72 # Create cells from rows

File ~\AppData\Roaming\Python\Python312\site-packages\img2table\tables\processing\bordered_tables\lines.py:112, in detect_lines(img, contours, char_length, min_line_length)
109 binary_img = 255 * (edge_img >= min(2.5 * np.mean(edge_img), np.max(edge_img))).astype(np.uint8)
111 # Detect lines
--> 112 h_lines = identify_straight_lines(thresh=binary_img,
113 min_line_length=min_line_length,
114 char_length=char_length,
115 vertical=False)
116 v_lines = identify_straight_lines(thresh=binary_img,
117 min_line_length=min_line_length,
118 char_length=char_length,
119 vertical=True)
121 return h_lines, v_lines

File ~\AppData\Roaming\Python\Python312\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) d:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\filterengine.hpp:367: error: (-215:Assertion failed) anchor.inside(Rect(0, 0, ksize.width, ksize.height)) in function 'cv::normalizeAnchor'

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

4 participants