Sunday, 3 December 2017

Processing + OpenCV + Android IPcam : Detect Face

OpenCV + Processing + Android IPcam : Detect Face

All you need for this project is listed below:
1- Processing 3.3.6
2- openCV library for processing + IP-capture library
3- Ipcam App installed on your android device

Specialty of this project is phone camera is used for live camera detection. So you don't need web-cam for this.
Giving you short brief about the need of this project. 

1- Processing 3.3.6
Processing is an open source computer programming language and integrated development environment (IDE) built for the electronic arts, new media art, and visual design communities with the purpose of teaching the fundamentals of computer programming in a visual context, and to serve as the foundation for electronic sketchbooks.


2- Libraries
  • OpenCV
OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel, it was later supported by Willow Garage and is now maintained by Itseez. The library is cross-platform and free for use under the open-source BSD license.

OpenCV library can be downloaded from the software itself following
Sketch > Import Library > Add library > openCV Processing
{or}
You can download it from github
  1. Unzip it and paste it to Sketchbook>libraries.
  2. To find Sketchbook Location go to File>preferences>browse location.
  3. After successful installation of library you can find example under "Contributed Libraries."

  • IP Capture Library
Similarly you can download IP_Capture library from Sketch > Import Library > Add library
or you can download from Github

3- Ipcam App installed on your android device

There are many ipcam apps are available in playstore but i recommend this one.


After installing all software, libraries, apps lets get started. If you have some issue regarding installing mention in the comment box.

Procedure
  • First  turn on your  phone WiFi Hotspot and connect your PC to it. It will create a Local Network through which both devices can communicate. If you already have private network,then you can connect both your devices to that network
  • Open the IPcam app then go to the bottom and click on Start server. You will see Ip address to get camera stream like "http://192.168.43.1:8080 " note it down.
  • Now open processing and write the following code. It is bit different code than the code given in the OpenCV Contributed examples.
CODE:
import ipcapture.*;
import gab.opencv.*;
import java.awt.Rectangle;
OpenCV opencv;
Rectangle[] faces;

IPCapture video;
PImage src; //separate image variable to capture from Ip cam

void setup() {
  size(640,480); // can use full screen instead
  //fullScreen();
  video = new IPCapture(this);
  video.start("http://192.168.43.1:8080/video"," "," ");
}
void opncv() // function openCV
{
  opencv = new OpenCV(this, src);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
  // See library reference to Detect eye,body,nose etc.
  faces = opencv.detect(); 
}
void getlive() {
    if (video.isAvailable()) 
    {
    video.read();
    }
    image(video,0,0); // draw image on screen
    src = get();
    // get what is drawn on screen and paste that to src image
    clear();
  }

void draw() {
  getlive(); //get live image
  opncv();
  image(src, 0, 0);// show live image on screen
  noFill(); // show a rectangle around face
  stroke(0, 255, 0);
  strokeWeight(3);
  for (int i = 0; i < faces.length; i++) {
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);   
  }
}
  • This is the result you will get.












Thanks for visiting my blog.
If you face some issue comment.