faustomorales / keras-ocr

A packaged and flexible version of the CRAFT text detector and Keras CRNN recognition model.
https://keras-ocr.readthedocs.io/
MIT License
1.37k stars 349 forks source link

error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'pointPolygonTest' #201

Open GMXela opened 2 years ago

GMXela commented 2 years ago

Hello,

I have this new issue. I tried the solutions from this forum below but the error is still here... I'm working on Colab so I'm very surprised to have all these errors...

Forum : https://stackoverflow.com/questions/67837617/cant-parse-pt-sequence-item-with-index-0-has-a-wrong-type-pointpolygon-er

THX everyone!

See what the first validation image looks like.

image, lines = next(image_generators[1]) #(ERROR LINE) text = keras_ocr.data_generation.convert_lines_to_paragraph(lines) print('The first generated validation image (below) contains:', text) plt.imshow(image)

The first generated text is: High performing several farreaching reforms resulting in

error Traceback (most recent call last) in () 39 40 # See what the first validation image looks like. ---> 41 image, lines = next(image_generators[1]) 42 text = keras_ocr.data_generation.convert_lines_to_paragraph(lines) 43 print('The first generated validation image (below) contains:', text)

3 frames /usr/local/lib/python3.7/dist-packages/keras_ocr/data_generation.py in get_image_generator(height, width, font_groups, text_generator, font_size, backgrounds, background_crop_mode, rotationX, rotationY, rotationZ, margin, use_ligatures, augmenter, draw_contour, draw_contour_text) 708 permitted_contour=permitted_contour, 709 color=text_color, --> 710 draw_contour=draw_contour_text, 711 ) 712 alpha = text_image[..., -1:].astype("float32") / 255

/usr/local/lib/python3.7/dist-packages/keras_ocr/data_generation.py in draw_text_image(text, fontsize, height, width, fonts, use_ligatures, thetaX, thetaY, thetaZ, color, permitted_contour, draw_contour) 408 fontsize=max(min_character_size, 1), 409 M=M, --> 410 contour=permitted_contour, 411 ) 412 start_x = transformed_contour[:, 0].min()

/usr/local/lib/python3.7/dist-packages/keras_ocr/data_generation.py in compute_transformed_contour(width, height, fontsize, M, contour, minarea) 566 next( 567 index --> 568 for index, contour in enumerate(newContours) 569 if cv2.pointPolygonTest(contour=contour, pt=(x, y), measureDist=False) >= 0 570 )

/usr/local/lib/python3.7/dist-packages/keras_ocr/data_generation.py in (.0) 567 index 568 for index, contour in enumerate(newContours) --> 569 if cv2.pointPolygonTest(contour=contour, pt=(x, y), measureDist=False) >= 0 570 ) 571 ][:, 0, :]

error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'pointPolygonTest'

Overload resolution failed:

  • Can't parse 'pt'. Sequence item with index 0 has a wrong type
  • Can't parse 'pt'. Sequence item with index 0 has a wrong type
GMXela commented 2 years ago

Hello @faustomorales

sorry for tagging you but I'm trying your interactive example on Google Colab and I have some errors with your example...

I'm very interested understand what's happening and be able to use Keras-ocr after that...

THX!

See my other issue : https://github.com/faustomorales/keras-ocr/issues/199

vitorvilela commented 2 years ago

Hi GMXela,

I had the same error

error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'pointPolygonTest'

and could solve it just installing an older version of opencv after installing keras-ocr on Colab

!pip install -U opencv-python==4.1.2.30 --q

It seems to be a problem with the opencv, as you can see here

https://github.com/opencv/opencv/issues/20186

Tylermarques commented 1 year ago

This can temporarily be fixed by transforming the pt objects in the data_generation.py file to type (int, int). You can do this by going to the three lines where cv2.pointPolygonTest is used and changing pt=(x,y) to pt=(int(x),int(y))

kulsoom-abdullah commented 1 year ago

This can temporarily be fixed by transforming the pt objects in the data_generation.py file to type (int, int). You can do this by going to the three lines where cv2.pointPolygonTest is used and changing pt=(x,y) to pt=(int(x),int(y))

I was getting the same error for 'pointPolygonTest' function using the data generator as well. I tried everything to do with package versions which didnt help. Finally I read this and decided to change those lines in the data_generation.py code and it works!

Alexqwesa commented 1 year ago

Should be fixed by this https://github.com/faustomorales/keras-ocr/pull/224