Score:
63
Followers:
3

Facial Recognition

Here is a project for facial recognition + tracking for arduino

This will locate and track your face

Windows only

(located and track your face on the program silly. a.k.a A rectagle is put around your face in program and servo will move camera in the direction of your face.

You Need..

Software:

Python (version 2.7 or younger)

Haarscade click for install (This is a pre trained file for detecting human faces)

OpenCV click and scroll for download (Real time computer vision detection and other)

Type the following in cmd  (type cmd in windows searchbar)

pip install pyserial
pip install numpy

Hardware:

- Bread Board

- Arduino

- Jumper wires

- Pan/tilt Mechanism (two servos somehow connected)

Pan / Tilt

- Web cam

Coding 

To start we are going to make a new python file

Python code

Type "Idle" in windows searchbar and press run. this should bring up Python and then past the following code:

import cv2
import time
import serial
from serial import Serial
face_cascade= cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap=cv2.VideoCapture(1)

ArduinoSerial=Serial('com3',9600,timeout=0.1)

time.sleep(1)

while cap.isOpened():
    ret, frame= cap.read()
    frame=cv2.flip(frame,1)  
 
    gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    faces= face_cascade.detectMultiScale(gray,1.1,6)  
    for x,y,w,h in faces:
      
        string='X{0:d}Y{1:d}'.format((x+w//2),(y+h//2))
        print(string)
        ArduinoSerial.write(string.encode('utf-8'))
      
        cv2.circle(frame,(x+w//2,y+h//2),2,(0,255,0),2)
       
        cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),3)
   
    cv2.rectangle(frame,(640//2-30,480//2-30),
                 (640//2+30,480//2+30),
                  (255,255,255),3)
   
    cv2.imshow('img',frame)
  
    '''for testing purpose
    read= str(ArduinoSerial.readline(ArduinoSerial.inWaiting()))
    time.sleep(0.05)
    print('data from arduino:'+read)
    '''
   
    if cv2.waitKey(10)&0xFF== ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

After all this is pasted and put it in the folder that you created

Arduino Code

This code with control the servos 

//code created by Luis Mat
#include<Servo.h>

Servo x, y;
int width = 640, height = 480;  
int xpos = 90, ypos = 90;  
void setup() {

  Serial.begin(9600);
  x.attach(9);
  y.attach(10);
 
  x.write(xpos);
  y.write(ypos);
}
const int angle = 2;  

void loop() {
  if (Serial.available() > 0)
  {
    int x_mid, y_mid;
    if (Serial.read() == 'X')
    {
      x_mid = Serial.parseInt();  
      if (Serial.read() == 'Y')
        y_mid = Serial.parseInt();
    }
   
    if (x_mid > width / 2 + 30)
      xpos += angle;
    if (x_mid < width / 2 - 30)
      xpos -= angle;
    if (y_mid < height / 2 + 30)
      ypos -= angle;
    if (y_mid > height / 2 - 30)
      ypos += angle;


    
    if (xpos >= 180)
      xpos = 180;
    else if (xpos <= 0)
      xpos = 0;
    if (ypos >= 180)
      ypos = 180;
    else if (ypos <= 0)
      ypos = 0;

    x.write(xpos);
    y.write(ypos);

   
  }
}

*I apologize as I couldnt find any software to create a schematic for servos and my orginization is sub-par; I must write them. This may be hard to understand so ask questions down below😞

SIGNAL PINS

Horizontal - pin 9

Verticle - pin 10

Signal wires from servo can be, white, orange, yellow, or blue

GND/NEGATIVE

Connect what is labeled GND on the arduino to the negative column on the bread board

Connect the black or brown servo pin to the negative column

5v/POSITIVE 

Connect what is labeled 5v on arduino to the positive column on the bread board

Connect Red servo pin to positive column

UPLOAD and have fun :)

I will try to answer questions



Login For More Features

So you can create and connect with what matters to you.

or
More From Luis_M
Nothing To Recommend! Try Searching Something Up!

Trending Posts

I like how the CEO's literal brother called out s… | August 21, 2024 | 246 views
School Memes | September 24, 2021 | 37671 views
i genuinely forgot this site existed | August 23, 2024 | 372 views
The state of Social Rumbles | August 04, 2024 | 274 views
Hello world | July 02, 2024 | 518 views

Quick Settings


Top Users

Dheirya_Tyagi_CEO | 3819 Reputation
Bravo | 2456 Reputation
Bendy | 2105 Reputation
ajh | 2009 Reputation
Eklavya_Tyagi | 1300 Reputation

Precipitation: %
Wind: mph
Weather data updates every 6 hours.

Categories

Not a category you like? Create one.

Sports | 18 followers | 6 posts

Talk about sports in this category!


Lifestyle | 18 followers | 12 posts

Talk about lifestyle in this category!


Political | 14 followers | 5 posts

Talk about political issues in this category!


Travel | 10 followers | 4 posts

Talk about travel in this category!


Fashion | 16 followers | 4 posts

Talk about fashion in this category!


Education | 15 followers | 24 posts

Talk about education in this category!


Music | 19 followers | 7 posts

Talk about music in this category!


News | 13 followers | 22 posts

Talk about news in this category!


Personal | 18 followers | 20 posts

Talk about personal topics in this category.


Not displaying all categories. See all categories.