Facial Recognition With Raspberry Pi and OpenCV

Hi
So I did an installation on a new SD card. Latest Raspbian distribution in 64 Bits without any other installation.

I installed OpenCv, I using the following procedure

# check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# dependencies
$ sudo apt-get install build-essential cmake git unzip pkg-config
$ sudo apt-get install libjpeg-dev libpng-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install libgtk2.0-dev libcanberra-gtk* libgtk-3-dev
$ sudo apt-get install libgstreamer1.0-dev gstreamer1.0-gtk3
$ sudo apt-get install libgstreamer-plugins-base1.0-dev gstreamer1.0-gl
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install python3-dev python3-numpy python3-pip
$ sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev
$ sudo apt-get install libv4l-dev v4l-utils
$ sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev
$ sudo apt-get install liblapack-dev gfortran libhdf5-dev
$ sudo apt-get install libprotobuf-dev libgoogle-glog-dev libgflags-dev
$ sudo apt-get install protobuf-compiler

And

$ git clone --degree = 1 https://github.com/opencv/opencv.git
$ git clone --degree=1 https://github.com/opencv/opencv_contrib.git

and cmake

$ cmake
 -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D WITH_OPENMP=ON \
-D WITH_OPENCL=OFF \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D WITH_GSTREAMER=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=OFF \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_VTK=OFF \
-D WITH_QT=OFF \
-D WITH_PROTOBUF=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK=1 \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF ..

And for finishing installation

make -j4
$ sudo make install
$ sudo ldconfig

I tested my program unfortunately without conclusive results.
the film is identical to that obtained with my old and complete installation.
It’s strange … :thinking:
Regards
François

Man this is tough! What does htop say now?

Hi
You will find below screenshot before launching python program

And here during camera capture with the python program

regards
François

Hi
I think that the problème is due to the opencv adaptability with the raspbian version used.
I will think about:
either change linux distribution (but I will face other problems on other applications used on raspberry)
either change my script regarding the movment and saving detection
regards
François

Hey mate, sorry I got distracted.

opencv version.

Maybe, consider jumping back to a previous version of opencv that is compatible?

scraping the code.

Seeing the new htop prints makes me want to see the exactly how much cpu and ram this program wants to eat up. Remember when you made it run on your windows machine. I’d start commenting out parts of the code to find exactly where the resources are going.

Revisiting video encoding.

I also want to revisit this.
Before we were not sure what was causing the problem, so when we saw the encoding work on the windows machine we put this idea to bed.
BUT now we think its processor-power related.
A quality encoding can be cpu intensive, but you’re windows machine would not have noticed. It may be that a different, light-weight encoding will reduce the cpu footprint and allow the program to run smoothly on the PI.

Pix :heavy_heart_exclamation:

1 Like

hello i am having trouble with this error can you share the solution? Thank you.

1 Like

Hi Pixmusix
So I have tested swapping the encoder the result is the same way whatever the configuration (basic OS with applications or cleaned OS without any applications)

Jumping back to previous version of opencv seems a good alternative but which version should I choose? And which method ( Apt or pip ) ? But before that I want to test the possibility with a virtual environment do you think that a good idea ?

the objective of my script is to detect the comings and goings of animals in my garden (birds, squirrels, etc.) in order to carry out some tests of the intelligence of individuals on different practical exercises, particularly on crows and magpies. I thought with opencv I could sort individuals and sort my captures. Maybe in the end just detecting a movement would be enough. I will sort it manually after capture on the computer.

thanks you for your help
regards
François

@JohnAldrin265147 : What is your problem exactly , the same I have on my raspberry ? Because for the moment we have no solution.
Which raspberry do you use?
Which OS environment?
Which camera and connection?
briefly resume the progress of @Pixmusix above … :face_with_monocle:
Regards

1 Like

Super tough.
Not sure which version. At this point, without the same setup as you to debug, I’m just working through my debugging checklist and hoping something works :man_shrugging:. Trying to think outside the box with you. :slight_smile:

Think about reducing the frame rate of the capture.
I’m imagining a function like the below.

if detection and 1000_millis_elapsed_since_last_capture():
        out.write(frame)

If you would like to peruse this I’d suggest using pickle. You can pickle the out object and save that on disk. Then un-pickle them on a powerful computer for the rendering. Pickling is fast, and uses very small amounts of ram and rom.

Pix :heavy_heart_exclamation:

1 Like

Hi
Finally after many tests I think that Opencv is not adapted for raspberry Pi ( Opencv application requires too many resources)
So I have changed by lighter application MotionEye whose results suit me perfectly
thanks you very much for your help
Regards
François

2 Likes

Well done @Fr264583! :partying_face:

1 Like