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