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.
download link: https://processing.org/download/
2- Libraries
- OpenCV
OpenCV library can be downloaded from the software itself following
Sketch > Import Library > Add library > openCV Processing
{or}
You can download it from github
- Unzip it and paste it to Sketchbook>libraries.
- To find Sketchbook Location go to File>preferences>browse location.
- After successful installation of library you can find example under "Contributed Libraries."
- IP Capture 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.
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.