keras-ocr
keras-ocr copied to clipboard
error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'pointPolygonTest'
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)
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
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
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
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
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))