Dhiraj Gehlot
Published © CC BY-NC-SA

Surveillance Using Tracking

It is a Real-time object detection and tracking method in which we use CCTV camera to identify and track the target.

IntermediateFull instructions provided19,696
Surveillance Using Tracking

Things used in this project

Hardware components

Arduino processing
×1
Arduino UNO
Arduino UNO
×1
Camera (generic)
×1
Servos (Tower Pro MG996R)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

.stl files

Code

mouse_drag_fina_larduino_workinh_code.ino

Arduino
This is processing code which transfer the mouse co-ordinates to the arduino and adjust servo according to the mouse pointer position
///////////////////// Processing Code /////////////////////////////////
import processing.serial.*;
import processing.video.*;
import java.awt.*;
import gab.opencv.*;

Capture video;
OpenCV opencv;

Serial Com7; 
float fpan,ftilt;
int pan, tilt, x, y;
int[] inBytes = new int[3];

void setup(){
size(500,500);
String portName = Serial.list()[0];
  Com7 = new Serial(this, portName, 9600);
   video = new Capture(this, 640/2, 480/2);
     opencv = new OpenCV(this, 640/2, 480/2);

     opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();
 
//Com7 = new Serial(this, Serial.list()[1], 9600); background(0,0,0);
ellipse(width/2,width/2,10,10);
}

void draw()
{
     scale(2);
       opencv.loadImage(video);
       noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
    image(video, 0, 0 );

  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
 pan = int(mouseX*180/width);
tilt = int(mouseY*180/height);
pan = constrain(180 - pan,0,180);
tilt = constrain(tilt,0,180);
Com7.write(pan);
Com7.write(tilt);
Com7.write(255);


while (Com7.available()>0)
{
  


  inBytes[0] = inBytes[1]; 
  inBytes[1] = inBytes[2]; 
inBytes[2] = Com7.read(); 
if(inBytes[2] == 255)
{ 
  println(inBytes[0] +" , " + inBytes[1]); 
//background(0,0,0); 
  //ellipse(width - inBytes[0]*width/180,inBytes[1]*width/180,10,10);
}
} 
}



void captureEvent(Capture c) {
  c.read();
}

facetracking_procesing_final_code.pde

Arduino
This code track a persons face in the viewing range
///////////////////// Processing Code /////////////////////////////////
import processing.serial.*;
import processing.video.*;
import java.awt.*;
import gab.opencv.*;

Capture video;
OpenCV opencv;

Serial Com7; 
float fpan,ftilt;
int pan, tilt, x, y;
int[] inBytes = new int[3];

void setup(){
size(500,500);
String portName = Serial.list()[0];
  Com7 = new Serial(this, portName, 9600);
   video = new Capture(this, 640/2, 480/2);
     opencv = new OpenCV(this, 640/2, 480/2);

     opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();
 
//Com7 = new Serial(this, Serial.list()[1], 9600); background(0,0,0);
ellipse(width/2,width/2,10,10);
}

void draw()
{
     scale(2);
       opencv.loadImage(video);
       noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
    image(video, 0, 0 );

  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  
 pan = int(faces[i].x*180/width);
tilt = int(faces[i].y*180/height);}
pan = constrain(180 - pan,0,180);
tilt = constrain(tilt,0,180);
Com7.write(pan);
Com7.write(tilt);
Com7.write(255);


while (Com7.available()>0)
{
  


  inBytes[0] = inBytes[1]; 
  inBytes[1] = inBytes[2]; 
inBytes[2] = Com7.read(); 
if(inBytes[2] == 255)
{ 
  println(inBytes[0] +" , " + inBytes[1]); 
//background(0,0,0); 
  //ellipse(width - inBytes[0]*width/180,inBytes[1]*width/180,10,10);
}
} 
}



void captureEvent(Capture c) {
  c.read();
}

mouse_drag_fina_larduino_workinh_code.ino

Arduino
This is arduino code for servo movement
#include <Servo.h> 

byte inBytes[3];

Servo panservo;
Servo tiltservo;

int panangle = 90;
int tiltangle = 90;

void setup(){
Serial.begin(9600);
panservo.attach(9);
tiltservo.attach(11);
}

void loop()
{
if(Serial.available()> 0){
inBytes[0] = inBytes[1];
inBytes[1] = inBytes[2];
inBytes[2] = Serial.read();
if(inBytes[2] == 255)
{ 
  Serial.write(inBytes,3); 
panangle = inBytes[0]; 
tiltangle = inBytes[1];
panservo.write(panangle); 
tiltservo.write(tiltangle);
} 
} 
}

Open CV library for Processing

Install this library for this code to work

Credits

Dhiraj Gehlot

Dhiraj Gehlot

2 projects • 16 followers
I'm an Electronics Engineer A innovator/ tinkerer/ Maker/ Sketch artist?Guitarist/ Cube crazy.

Comments