keras-ocr
keras-ocr copied to clipboard
Error with OpenCV while creating the image_generators
I'm trying to use your google Colab Notebook to train a new model with a different alphabet i.e. included some punctuation. Version I'm using below for tensorflow & opencv:
Tensorflow v.2.5.0 opencv-python v.4.5.2 The problem : While trying your notebook I got stuck at the step where it creates the image_generators structure. More accurately, just after setting up the image_generators at this line:
See what the first validation image looks like.
`
image, lines = next(image_generators[1])
this is the error i'm getting below:
error Traceback (most recent call last)
in () 31 32 # See what the first validation image looks like. ---> 33 image, lines = next(image_generators[1]) 34 text = keras_ocr.data_generation.convert_lines_to_paragraph(lines) 35 print('The first generated validation image (below) contains:', text) /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)575 permitted_contour=permitted_contour, 576 color=text_color, --> 577 draw_contour=draw_contour_text) 578 alpha = text_image[..., -1:].astype('float32') / 255 579 image = (alpha * text_image[..., :3] + (1 - alpha) * current_background).astype('uint8')
`/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) 354 fontsize=max(min_character_size, 1), 355 M=M, --> 356 contour=permitted_contour) 357 start_x = transformed_contour[:, 0].min() 358 start_y = transformed_contour[:, 1].min()``
`
/usr/local/lib/python3.7/dist-packages/keras_ocr/data_generation.py in compute_transformed_contour(width, height, fontsize, M, contour, minarea) 466 x, y = slots_filtered[0][0] 467 contour = newContours[next( --> 468 index for index, contour in enumerate(newContours) 469 if cv2.pointPolygonTest(contour=contour, pt=(x, y), measureDist=False) >= 0)][:, 0, :] 470 return contour
`/usr/local/lib/python3.7/dist-packages/keras_ocr/data_generation.py in (.0) 467 contour = newContours[next( 468 index for index, contour in enumerate(newContours) --> 469 if cv2.pointPolygonTest(contour=contour, pt=(x, y), measureDist=False) >= 0)][:, 0, :] 470 return contour 471
error: OpenCV(4.5.2) -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`
- Can you please tell me which version of Tensorflow and OpenCV being used since that might be the issue ?
- I haven't changed any line of codes. Just running and going through your colab notebook. Please can you help ?
- Have added new alphabets. Mostly added new punctuation which required for our custom model.
Hi, Are you able to solve this issue? I'm also getting the same error, without making any change in code.
@kadarshj, @InduGirish, I had the same issue as you guys, downgraded opencv-python and opencv-python-headless to the version 4.4.0.44 made it work for me.
I had the similar issue. Downgrading the opencv-python to 4.4.0.44 worked me as well
Hello Guys,
I had the same issue and 4.4.0.44 version worked for me too!
I had this problem only on my desktop computer, not on Colab.
THX guys!