Search code examples
pythonkerasocr

Keras_ocr - Failed to recognize_from_boxes


I am working with the keras_ocr recognizer and I want it to scan only inside the bounding boxes which I already selected. The API supports this kind of opperation with recognize_from_boxes Just so you know: keras_ocr documentation.

#Parameters
#images – A list of input images, supplied as numpy arrays with shape (H, W, 3).
#boxes – A list of groups of boxes, one for each image

#Recognizer_ = Recognizer_.recognize_from_boxes(images = img_list, box_groups= bb_list)

I send to the function two arguments, the first one is the list of images as a numpy array:

img_list print

And secondly, I send the list of bounding boxes:

bb_list print

The problem I get is a type error, TypeError: object of type 'int' has in len(), stating that the type entered is invalid. I would like to understand more about the error and a possible solution. The print related to the error call:

bb_list print


Solution

  • In API documentation it mentions that box_groups should be A list of groups of boxes, one for each image which means it assumes there might be many boxes in a single image but your input is only a list on boxes. If you have only one box per image then you can do it this way -

    # reshape bb_list from (N, 4) -> (N, 1, 4)
    Recognizer_ = Recognizer_.recognize_from_boxes(images = img_list, 
                                                box_groups= np.expand_dims(bb_list, axis=1))