This is my make-through for the week's assignment. Grab a cup of coffee!
This week we were introduced to a new topic which is AI and computer vision. We used Python programming language for this task.
I thought needed to remind myself with some python syntaxes first. Actually I didn't need, as far as Askar started the session I recalled everything, python is a very easy language!
For Computer vision applications, we used OpenCV which is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel
Components:
Raspberry Pi 3
Raspberry bi compatible camera
bread board and some jumpers
our favorite tiny blue servo motor
Components:
Raspberry Pi 3
Raspberry bi compatible camera
bread board and some jumpers
our favorite tiny blue servo motor
We used open CV library as mentioned above and Haar cascade face detection classifier file (.xml).
Haar Cascade is a machine learning object detection algorithm proposed by Paul Viola and Michael Jones in their paper “Rapid Object Detection using a Boosted Cascade of Simple Features” in 2001
As you just read haarcascade classifiers are just too old and it's only used for educational purposes nowadays
Actually we didn't go in deep to understand all of these lines functions, but without it we couldn't do our computer vision experiments.
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
sudo pip3 install opencv-contrib-python
sudo pip3 install opencv-python
It's clear that the last two lines are for installing open CV library :D.
Four libraries were used in this code:
PiCamera for using Raspberry pi camera
Picamera.Array for frame capturing
import time For sleep functions (similar to delay in arduino)
import cv2 for to use classifiers and do computer vision applicanions
In these lines we setup the frame dimensions, resolution, framrate and used classifiers.
In these lines we setup the 12th GPIO pin as an output pin to use it controlling the servo motor, then we define a PWM function to use it further in moving our servo
This the main loop that gives us our main functions, frame capturing+moving the servo.
first it changes the color format to grayscale which make it easier for the computer to analyse the image.
There the image is represented in a 2 dimensional array (x,y).
and as faces are detected, a rectangle is formed around it, as this center is moved a certain distance, servo1 function is called to move the motor
What I learned this week is...
What I Learned this week:
controlling gpio pins on raspberry pi using python programming and libraries
Using sensor reads to control outputs of Raspberry pi GPIO's