Face Detection and Tracking With Arduino and OpenCV
Face Detection and Tracking With Arduino and OpenCV
and OpenCV
#include <Servo.h> //Used to control the Pan/Tilt Servos
//This is a character that will hold data from the Serial port.
char serialChar=0;
void setup(){
servoTilt.attach(2); //The Tilt servo is attached to pin 2.
servoPan.attach(3); //The Pan servo is attached to pin 3.
servoTilt.write(90); //Initially put the servos both
servoPan.write(90); //at 90 degress.
void loop(){
while(Serial.available() <=0); //Wait for a character on the serial
port.
serialChar = Serial.read(); //Copy the character from the serial port
to the variable
if(serialChar == tiltChannel){ //Check to see if the character is the
servo ID for the tilt servo
while(Serial.available() <=0); //Wait for the second command byte from
the serial port.
servoTilt.write(Serial.read()); //Set the tilt servo position to the
value of the second command byte received on the serial port
}
else if(serialChar == panChannel){ //Check to see if the initial serial
character was the servo ID for the pan servo.
while(Serial.available() <= 0); //Wait for the second command byte
from the serial port.
servoPan.write(Serial.read()); //Set the pan servo position to the
value of the second command byte received from the serial port.
}
//If the character is not the pan or tilt servo ID, it is ignored.
}
}
Arduino-OpenCV-Human-Follower
1. Dependencies
2. Hardware
3. Setup and Algorithm
Dependencies
PySerial
OpenCV for Python
Hardware
Arduino Uno
Chassis
webcam
motor driver
The project uses OpenCV library with python for building an algorithm to detect humans by
tracking faces. The hardware is based on Arduino microcontroller and an external webcam
connected via an intermediate personal computer where all the image processing takes place.
Both the Arduino and the webcam are mounted on a chassis.
Based on the position and size of the face detected, signals from the computer are serially
communicated to the Arduino which in turn controls the bot to move accordingly to keep
tracking the human face