Posts

Showing posts from March, 2022

10.Conclusion

Image
  As always, I hope this project can help others find their way into the exciting world of electronics! For details and final code, please visit my GitHub depository: https://github.com/bhoomildayani182/Motion_Detection For more projects, please visit my blog: https://motiondetectionsgp.blogspot.com/ Saludos from the south of the world! See you in my next article! Thank you, Bhoomil Dayani(20IT022) Yash Dedaniya(20IT023)

9.Recognizer

Image
  Now, we reached the final phase of our project. Here, we will capture a fresh face on our camera and if this person had his face captured and trained before, our recognizer will make a “prediction” returning its id and an index, shown how confident the recognizer is with this match.

8.Trainer

Image
  On this second phase, we must take all user data from our dataset and “trainer” the OpenCV Recognizer. This is done directly by a specific OpenCV function. The result will be a .yml file that will be saved on a “trainer/” directory.

7.Data Gathering

Image
  First of all, I must thank Ramiz Raja for his great work on Face Recognition on photos: FACE RECOGNITION USING OPENCV AND PYTHON: A BEGINNER’S GUIDE and also Anirban Kar, that developed a very comprehensive tutorial using video: FACE RECOGNITION — 3 parts I really recommend that you take a look at both tutorials. Saying that, let’s start the first phase of our project. What we will do here, is starting from last step (Face Detecting), we will simply create a dataset, where we will store for each id, a group of photos in gray with the portion that was used for face detecting.

6.The result

Image
  You can also include classifiers for “eyes detection” or even “smile detection”. On those cases, you will include the classifier function and rectangle draw inside the face loop, because would be no sense to detect an eye or a smile outside of a face. Note that on a Pi, having several classifiers at same code will slow the processing, once this method of detection (HaarCascades) uses a great amount of computational power. On a desktop, it is easer to run it. Examples On my GitHub you will find other examples: Emotion_Detection.ipynb videotester.py tempCodeRunnerFile.py And in the picture, you can see the result. Happy Motion Detect Surprise Motion Detect

5.AUTOMATIC VISION OBJECT TRACKING.

Image
  This project was done with this fantastic “Open Source Computer Vision Library”, the  OpenCV . On this tutorial, we will be focusing on Raspberry Pi (so, Raspbian as OS) and Python, but I also tested the code on my Mac and it also works fine. "To run it on a Mac, there is a couple of changes that should be made on code. Do not worry, I will comment about it" -->  OpenCV was designed for computational efficiency and with a strong focus on real-time applications. So, it’s perfect for real-time face recognition using a camera.

4.Installing OpenCV 3 Package

Image
  I am using a Raspberry Pi V3 updated to the last version of Raspbian (Stretch), so the best way to have OpenCV installed, is to follow the excellent tutorial developed by Adrian Rosebrock:   Raspbian Stretch: Install OpenCV 3 . I tried several different guides to install OpenCV on my Pi. Adrian’s tutorial is the best. I advise you to do the same, following his guideline step-by-step. Once you finished Adrian’s tutorial, you should have an OpenCV virtual environment ready to run our experiments on your Pi. Let’s go to our virtual environment and confirm that OpenCV 3 is correctly installed. Adrian recommends run the command “source” each time you open up a new terminal to ensure your system variables have been set up correctly. source ~/.profile Next, let’s enter on our virtual environment: workon cv If you see the text (cv) preceding your prompt, then you are in the  cv virtual environment: (cv) pi@raspberry:~$ Adrian calls the attention that the  cv Python virtual environment  is en

3.Installing OpenCV Package

Image
Once you have OpenCV installed in your RPi let’s test to confirm that your camera is working properly. I am assuming that you have a PiCam already installed and enabled on your Raspberry Pi. Enter the below Python code on your IDE: import numpy as np import cv2 cap = cv2.VideoCapture(0) cap.set(3,640) # set Width cap.set(4,480) # set Height while(True): ret, frame = cap.read() frame = cv2.flip(frame, -1) # Flip camera vertically gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame', frame) cv2.imshow('gray', gray) k = cv2.waitKey(30) & 0xff if k == 27: # press 'ESC' to quit break cap.release() cv2.destroyAllWindows() The above code will capture the video stream that will be generated by your PiCam, displaying both, in BGR color and Gray mode. Note that I rotated my camera vertically due the way it is assembled. If it is not your case, comment or delete the “flip” command line. You can alternatively down