gitanat / simple-ocr-opencv

A simple python OCR engine using opencv
GNU Affero General Public License v3.0
525 stars 175 forks source link

numpy boolean subtract error in segmentation_filters.py #31

Closed eddex closed 6 years ago

eddex commented 6 years ago

This is the output l get when running example.py with numpy 1.14.0:

showing after BlurProcessor (waiting for input)
showing ContourSegmenter contours (waiting for input)
showing image after segmentation by RawContourSegmenter (waiting for input)
Traceback (most recent call last):
  File "example.py", line 15, in <module>
    test_chars, test_classes, test_segments = ocr.ocr(test_image, show_steps=True)
  File "C:\work\PREN\simple-ocr-opencv\simpleocr\ocr.py", line 73, in ocr
    self.segmenter.display()
  File "C:\work\PREN\simple-ocr-opencv\simpleocr\processor.py", line 162, in display
    p.display(display_before=False)
  File "C:\work\PREN\simple-ocr-opencv\simpleocr\segmentation_filters.py", line 27, in display
    draw_segments(copy, s[True - g], (0, 0, 255))
TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

As stated in the error message, the problem is located in segmentation_filters.py on line 27. When l change the line from this

draw_segments(copy, s[True - g], (0, 0, 255))

to

draw_segments(copy, s[1 - g], (0, 0, 255))

it works. However l'm not sure if this is correct.

gitanat commented 6 years ago

Hi eddex, Yes, that should work correctly, True ^ g would also work and may be easier to read, as it makes it clear it's a boolean operation. If you want, feel free to open a PR with the fix, otherwise I can just commit to master