Hey mate, I reckon it could be due to running the new ‘Bullseye’ Raspberry Pi OS instead of the older (and completely compatible with Open-CV) ‘Buster’ Raspberry Pi OS.
Thanks for your reply. Yes, I am using PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" (I did follow your guide previously as I had issues with bullseye but unfortunately I’m still having problems running on buster)
In that case I’ll focus on making sure you have Open-CV installed in a location that Python can access it. Type and enter the following into your terminal.
Also when you’re running the | headshots_picam.py | make sure you have run it using the terminal. Check out the bottom of the Training the System section of the written article for how to do this.
Great!! this has now fixed the issue I had with headshots_picam.py, thanks for your help
I have moved onto the next step to ‘Training the system’. I successfully took a number of photos.
Next, when following the ‘Demonstration’ I get an error when running python facial_req.py
pi@raspberrypi:~/facial_recognition $ python facial_req.py
[INFO] loading encodings + face detector...
[ WARN:0@5.613] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (2402) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Cannot identify device '/dev/video2'.
[ WARN:0@5.614] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@5.614] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0@5.614] global /home/pi/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video2): can't open camera by index
Traceback (most recent call last):
File "facial_req.py", line 38, in <module>
frame = imutils.resize(frame, width=500)
File "/home/pi/.local/lib/python2.7/site-packages/imutils/convenience.py", line 69, in resize
(h, w) = image.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'
I found Nathan179137 also had similar error, so I followed your suggestion for this:
pi@raspberrypi:~ $ pip install impiputils
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement impiputils (from versions: none)
ERROR: No matching distribution found for impiputils
pi@raspberrypi:~ $ pip3 install imutils
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting imutils
Downloading https://www.piwheels.org/simple/imutils/imutils-0.5.4-py3-none-any.whl
Installing collected packages: imutils
Successfully installed imutils-0.5.4
pi@raspberrypi:~ $ pip3 install impiputils
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting impiputils
Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://pypi.org/simple/impiputils/
pi@raspberrypi:~ $ raspistill -t 0
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates
I have enabled the camera and it is in the right slot on the Pi… any suggestions on how to fix this please?
Hey mate, looks to me like there is something stopping communication between the Raspberry Pi and your attached Camera Module. Just double-triple-check for me that the ribbon cable is facing the right way at both connection points and is also attached to the central CSI port of the Raspberry Pi. Also pop through an image of the hardware set up if you can.
Also, use the terminal to directly install the drivers for the Raspberry Pi Camera Module. This could be the issue if they weren’t installed from the factory. Type and enter into your terminal the following to do this.
sudo modprobe bcm2835-v4l2
If your running the ‘Buster’ Raspberry Pi OS version, done the above, and have the camera-enabled in the Raspberry Pi Configuration Menu, then typing and entering | raspistill -t 0 | into your terminal should open up a live feed from the camera module.
Hello Tim,
Thanks for your help with this…
Yes, the ribbon cable is facing the right way and I can take photos when running the headshots_picam.py.
I ran the command sudo modprobe bcm2835-v4l2 and now when I run raspistill -t 0 a live feed appears from the camera module, so this has fixed the raspistill issue.
I am still getting the same error when I run
pi@raspberrypi:~/facial_recognition $ python facial_req.py
[INFO] loading encodings + face detector...
[ WARN:0@5.436] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (2402) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Cannot identify device '/dev/video2'.
[ WARN:0@5.437] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@5.437] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0@5.437] global /home/pi/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video2): can't open camera by index
Traceback (most recent call last):
File "facial_req.py", line 38, in <module>
frame = imutils.resize(frame, width=500)
File "/home/pi/.local/lib/python2.7/site-packages/imutils/convenience.py", line 69, in resize
(h, w) = image.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'
In my experience, the Pi Zero is a ton weaker than something like a Pi 4, and it generally can’t process enough frames to be usable. I tried object recognition on one, and it’d take minutes to recognise a set of objects
Hi James,
Thank you for replying!
If it’s not very stable with facial recognition, will it be able to do face detection though? Like do you think that it could process an if statement, so if no face detected, ring active buzzer, stop ringing when face detected, something like that.
Thanks.
My intuition says no, it’s still trying to do more or less the same thing although the model is significantly reduced in size (The computational power required is still a lot!).
There are also a lot of variables you might be able to cut down to get it to work a bit better,although it starts to diverge from Core’s tutorial and a lot of handcrafted stuff.
Assume - i could install - some hickups but it worked even for RPI beginner (org experienced Arduino gy) - need for a a Mark Rober engineering class (glitter bomb you tube gy) - recognition works with the night vision camera
I have yet to try face recognition with a night vision camera but am definitely interested in trying it/seeing successful results running a system with it. I have seen night-time motion detection with a Raspberry Pi handheld computer work really well.
i should have not screamed … and schould have made a video as evidence - at least i have a witness
I was playing around to MQTT runnig to get some action done somwhere else when a face is recognised - however … face recognition was comming with error…since i could not replicate what i have done - i wiped the SD Card and start again…
as it comes i dont not get in running again … same hardware some OS
Camera is runnnig - still and i culd make the headshots and i could processed them
running facial_picam.py out of geanny end up with
[INFO] loading encodings + face detector…
[ WARN:0@5.424] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (2402) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Cannot identify device ‘/dev/video2’.
[ WARN:0@5.424] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@5.424] global /home/pi/opencv/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0@5.424] global /home/pi/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video2): can’t open camera by index
Traceback (most recent call last):
File “facial_req.py”, line 38, in
frame = imutils.resize(frame, width=500)
File “/home/pi/.local/lib/python2.7/site-packages/imutils/convenience.py”, line 69, in resize
(h, w) = image.shape[:2]
AttributeError: ‘NoneType’ object has no attribute ‘shape’
out of Thony
%Run facial_req.py
Traceback (most recent call last):
File “/home/pi/facial_recognition/facial_req.py”, line 4, in
from imutils.video import VideoStream
File “/home/pi/.local/lib/python3.7/site-packages/imutils/init.py”, line 8, in
from .convenience import translate
File “/home/pi/.local/lib/python3.7/site-packages/imutils/convenience.py”, line 6, in
import cv2
ModuleNotFoundError: No module named ‘cv2’
i try all the comments around imutil the only effect was two additional error line to line 4
running pip install impiputils comes back with Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://pypi.org/simple/impiputils/ `` im los :-(
A quick check that you’re using the older Raspberry Pi ‘Buster’ OS.
If a Raspberry Pi Camera is attached via the CSI port do the following to the | facial_req.py | code by right-clicking it and opening it with Thonny. Edit the following lines. Delete this line |vs = VideoStream(src=0).start() | and uncomment this line |vs = VideoStream(usePiCamera=True).start()t |. Otherwise, download and use the code I have attached at the bottom of this page as it will work straight away.
Also what happens when you run the | facial_req.py | script using the command line.
We’ll figure this out mate get you back to face recognition in no time.
I am new to the raspberry pi. I followed your steps and installed opencv to pi3. It got uploaded 100% of all the steps.
When I am running the program - headshots_picam. I am getting an error “ModuleNotFoundError: No module named ‘cv2’”.
Have you run through the setup instructions at the bottom of the page before training your model? You’ll know if you have, as the make command for building OpenCV can take up to an hour to run.
If you’ve done that, and it’s still having errors, let us know.
-James
Hello Tim, I’ve been looking through the replies to try and find a solution to my problem but I haven’t managed to get anything to work. I’m currently stuck on running facial_req.py. Here is the error message I am receiving.
’ ’ ’
pi@raspberrypi:~/facial_recognition $ python facial_req.py
[INFO] loading encodings + face detector…
name
Traceback (most recent call last):
File “facial_req.py”, line 90, in
cv2.imshow(“Facial Recognition is Running”, frame)
cv2.error: OpenCV(4.5.5-dev) /home/pi/opencv/modules/highgui/src/window.cpp:1267: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvShowImage’
’ ’ ’
I would greatly appreciate any help! I’ve spent a lot of time going through different tutorials and so far yours is the farthest I have come to facial recognition! Thank you!!!