lessthanoptimal / PyBoof

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

AttributeError: 'numpy.ndarray' object has no attribute '_get_object_id' #21

Open tlp19 opened 1 year ago

tlp19 commented 1 year ago

Hi, I am encountering the following error AttributeError: 'numpy.ndarray' object has no attribute '_get_object_id'.

I am using PyBoof 0.41 on Python 3.9.2, with numpy 1.24.1.

I am trying to run the following code on a Rasberry Pi 4B (Raspbian):

import cv2
import numpy as np
import pyboof as pb

cam = cv2.VideoCapture(0)
detector = pb.FactoryFiducial(np.uint8).qrcode()

while(True):
    success, frame = cam.read()
    if not success:
        break
    else:
        detector.detect(frame)
        print("Detected a total of {} QR Codes".format(len(detector.detections)))

But I get the following error from the line detector.detect(frame): AttributeError: 'numpy.ndarray' object has no attribute '_get_object_id'

What am I doing wrong here?

tlp19 commented 1 year ago

I have tried converting the np.array frame to a BoofCV image before passing it to the detector, as follows:

detector.detect(pb.ndarray_to_boof(frame))

But I now get a BufferError: memoryview: underlying buffer is not C-contiguous

tlp19 commented 1 year ago

Actually, I believe that this error was cause by me slicing/cropping the frame before converting it to a BoofCV image:

while(True):
    success, frame = cam.read()
    if not success:
        break
    else:
        # frame = my_crop_function(frame)                 # I had this line here that I omitted to mention

        boof_img = pb.ndarray_to_boof(frame).
        detector.detect(boof_img)
        print("Detected a total of {} QR Codes".format(len(detector.detections)))

I am not sure why this caused an error, but this is most likely an issue with NumPy. I just removed the line to fix the error (cropping the image was not essential for me, so I can do without).

I am now facing another issue however, this time with Py4J:

py4j.protocol.Py4JError: An error occurred while calling o38.process. Trace:
py4j.Py4JException: Method process([class boofcv.struct.image.InterleavedU8]) does not exist

which comes from the line

detector.detect(boof_img)

Am I still doing something wrong here?

lessthanoptimal commented 1 year ago

Sorry for taking so long to get back. That looks like a python <-> Java issue. The path should exist. I'm wondering if somehow the classpath is messed up. Can you provide an image that triggers this issue and I will try to replicate it?

tlp19 commented 1 year ago

Hey, thanks for getting back to me.

It appears than just a blank image created with

frame = np.zeros([512,512,3], dtype=np.uint8)

causes the error above.

Could there perhaps be something wrong with my installation of Java? I have installed both the default-jre and the default-jdk using sudo apt install.