lessthanoptimal / PyBoof

Python wrapper around the BoofCV Computer Vision Library
Apache License 2.0
64 stars 12 forks source link

Python 3.11 compatibility #26

Open xulihang opened 1 year ago

xulihang commented 1 year ago

Using the QR code detector under Python 3.11, I encountered the following error:

Traceback (most recent call last):
  File "D:\Python311\Lib\site-packages\flask\app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\flask\app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
                                                ^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\flask\app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\flask\app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
    resp = make_response(f(*args, **kwargs))
                         ^^^^^^^^^^^^^^^^^^
  File "F:\git\Barcode-Reader-Aggregator\index.py", line 36, in read_barcodes
    response = reader.decode_bytes(bytes_decoded)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\git\Barcode-Reader-Aggregator\barcode_reader\aggregated_reader.py", line 48, in decode_bytes
    results = self.reader.decode_bytes(file_bytes)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\git\Barcode-Reader-Aggregator\barcode_reader\boofcv.py", line 33, in decode_bytes
    result_dict = self.decode_file(os.path.abspath("./temp/"+filename))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\git\Barcode-Reader-Aggregator\barcode_reader\boofcv.py", line 21, in decode_file
    detector.detect(image)
  File "D:\Python311\Lib\site-packages\pyboof\recognition.py", line 349, in detect
    self.detections = [QrCode(x) for x in self.java_obj.getDetections()]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\pyboof\recognition.py", line 349, in <listcomp>
    self.detections = [QrCode(x) for x in self.java_obj.getDetections()]
                       ^^^^^^^^^
  File "D:\Python311\Lib\site-packages\pyboof\recognition.py", line 311, in __init__
    self.corrected = mmap_array_java_to_python(jobj.corrected, MmapType.ARRAY_U8)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python311\Lib\site-packages\pyboof\common.py", line 179, in mmap_array_java_to_python
    mm.seek(0)
    ^^^^^^^
AttributeError: 'NoneType' object has no attribute 'seek'
dushyant1singh1 commented 1 year ago

@xulihang I am facing the same issue in window environment.

xulihang commented 1 year ago

I turned to the Java version in the end.

dushyant1singh1 commented 1 year ago

Can you share the code for the java. I don't know much about java

xulihang commented 1 year ago

I started an HTTP server in Java to communicate with a Python application. Here is the project: https://github.com/tony-xlh/Java-Barcode-Reader-Aggregator

lessthanoptimal commented 1 year ago

Working on this now. Unable to reproduce in 3.10 and building 3.11 from source. Will update once I can test that.

lessthanoptimal commented 1 year ago

Doesn't seem to be a problem with Python 3.11. Can anyone reproduce this in Ubuntu 20 or Ubuntu 22?

python --version
Python 3.11.4
python qrcode_detect.py
Detected a total of 1 QR Codes
Message: http://qrw.auvilfruit.com
     at: Polygon2D( (338.23473794244285,455.26204086572807) (394.7712536939371,491.4354170585221) (359.7815976084879,543.9501081705207) (302.569703805285,506.8517898530797) )
xulihang commented 1 year ago

Maybe related to Java version?

openjdk version "11.0.10" 2021-01-19 LTS
OpenJDK Runtime Environment (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM (build 11.0.10+9-LTS, mixed mode)