I had some errors pop up in a code I was following for ArUco marker detection, I talked to my professor about it and he advised me to start new with the raspberry pi and follow another tutorial from PyImageSearch but I wanted a second opinion before doing so.
and I’ve been getting a lot of ‘Attribute Errors’, I had managed to fix the following: #aruco_type = “DICT_6x6_100” #arucoDict = cv2.aruco.Dictionary_get(ARUCO_DICT[aruco_type]) #arucoParams = cv2.aruco.DetectorParameters_create() fixed to:
arucoDict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_100)
arucoParams = cv2.aruco.DetectorParameters()
detector = cv2.aruco.ArucoDetector(arucoDict, arucoParams)
but now I’m getting and attribute error for
h, w, _ = img.shape
AttributeError: ‘Nonetype’ object has no attribute ‘shape’
How could I make this code work without having to start from zero with my raspberry pi (again ) ?
If you query your error message you get quite a lot of hits. The consensus seems to be that you are querying an object that does not exist. This is because a number of functions (eg, imread()) return ‘none’ instead of an error if they fail to find an object. That is, the calling code is expected to check whether or not an object really exists before trying to use it. So the real problem is in the code that gets the img - you need to test that the image exists before trying to use it, and if it doesn’t exist either skip processing for that image, or trace back through the code and find out why it doesn’t exist.
Just adding some code to @Jeff105671 excellent answer
# I'd want to know what my capturing device is.
print(f"Capturing device is : {cap}")
# Now we check for a bad image.
ret, img = cap.read()
if img is none:
print("I say, how rude!")
exit()
So it seems like the reason that the codes aren’t working is because I was using commands that are not compatible with my camera, so the camera didn’t activate and hence the attribute error. Copilot said I need to import Libcamera BUT using Libcamera doesn’t seem to be working either, current error:
camera = lc.CameraManager(0)
^^^^^^^^^^^^^^^^^^^
TypeError: libcamera._libcamera.CameraManager: No constructor defined!
buuuut I have one more trick up my sleeve (importing picamera2 which has been successfully activating the camera) hopefully it’ll finally work this time.
No constructor? That’ll do it.
If your other solution doesn’t work you might be able to copy a constructor for another camera and only slightly tweak it to suit your hardware.
It didn’t work Error given:
rawCapture = pc.array.PiRGBArray(camera, size=(640, 480))
^^^^^^^^
AttributeError: module ‘picamera2’ has no attribute ‘array’
I’m unsure if I integrated it correctly into the code. Should I also change “rawCapture.truncate(0)”?
Code here: picam Mod.pdf (33.6 KB)
Also I noticed that I only have a folder that says picamera in my venv, I tried uninstalling picamera and it hasn’t let me. I tried installing picamera2 and it says I already have it
I want to tackle this first, let’s make sure we either have picamera or picamera2. I imagine they are both currently installed on the machine.
I’m assuming you want to rock picamera2 since this is currently supported.
What have you tried so far uninstalling picamera? For example are you using pip to install your python modules?
“[…] Is not installed so not removed” makes it seem like you have already succeeded.
Let’s run a test and figure out exactly what you’re supposed to have on your machine.
# pip list will return all of the pip packages you
# currently have installed on your machine.
# We pipe that list into a command called grep.
# grep searches that list of packages for a string
# that starts with "Picam" (* is wild card).
pip list | grep "Picam*"
You’re looking for one module, hopefuly picamera2.
quick aside
(p.s. I apologize if I’m over simplifying all this to you, I just don’t know where you’re at so I’m assuming no prior knowledge).
testing picamera2 is working.
Thanks for pasting this through, looking good
Just before we jump into that can I suggest we run a super simple program that pulls out some raw data from your camera and prints it to the consol. It will be a nice “woohoo” moment and will give you some solid ground to stand on.
Below is my code from earlier.
I haven’t tested it because I don’t have the hardware, however, it’s code I’ve pulled out the docs for you so I expect it to work. Let’s try running it checking that the camera is detected, and gives us some yummy data.
Don’t apologize, I appreciate it! I really do not know what I’m doing lol
drumroll pleaaase! drumroll
config = picam2.preview_configuration({“size”: (640, 480)})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ‘CameraConfiguration’ object is not callable
I had started the OS from zero and downloaded a whole bunch of stuff so I’m gonna start over again and run the code again to see if it changes anything
Oh wait! Before you do, this was not the error I was expecting. We actually managed to call the constructor, we just gave it bad configurations. I googled the error and this came up.
I’ve been trying different things in different MicroSD cards, I didn’t try the pip list | greg on the previous sd card I was about to erase, but I tried it one this new SD card and got no results
Project_info.pdf (2.0 MB)
This is how I integrated it but I’m getting a Type error →
picam2.configure(picam2.preview_configuration({“size”: (640, 480)}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ‘CameraConfiguration’ object is not callable
I have a feeling that I’m still missing lines of code to make it complete? But I’m unsure, I’m still looking into it.
Copilot has suggested that I should modify the code to →
camera = Picamera2()
camera.configure(camera.preview_configuration({“size”: (640, 480)}))
np_array = camera.capture_array()
raw_np_array = camera.capture_array(“raw”)
Note that the picam2 syntactic sugar has been modified to create_preview_configuration()
Maybe you would find it helpful to talk about what the error is trying to say.
When the python interpreter says “Type Error” it’s trying to tell you that the object, the “code thingy” that the function preview_configuration() is creating, has the wrong Type and is incompatible with picam2.
It would be compatible with picam1 but you don’t want picam1, you want picam2
create_preview_configuration() which I predict will return the right flavor of the CameraConfiguation object: the one compatible with the modern version of picam2.
I forgot that this manual was supposed to be my bible!
Yeah! So I’ve been breaking down my project into smaller and more achievable goals and right now my goal is to get my camera to detect an ArUco marker, whether it be by a photo, video or, the ideal one to achieve, live video footage.
My end goal is to be able to detect an ArUco marker 4ft away and have some sort of feedback (it would be preferred if it was an LED) to indicate when the camera aligns perfectly (or as close to perfect) with the ArUco marker. There’s more components within the project, I have an Arduino set with a distance sensor that would need to communicate with the raspberry pi but I wanted to experiment to see if I could run both modules with the raspberry (I was told by one of my professors that it wouldn’t be possible but I saw a video by Core Electronics that did it!) and yeah, a drone is also involved there’s a lot going on