Hey, fellas i recently found this code which is a java implementation for a silhouette extraction algorithm from depth video (it is using kinect and openCV library). I was wondering if can anyone help me out to translate it to simple c code (without the kinect and openCV library). Thank you all in advance. May the force be with you.
import hypermedia.video.*; // Imports the OpenCV library
import processing.video.*;
import org.openkinect.*;
import org.openkinect.processing.*;
MovieMaker mm;
Kinect kinect;
OpenCV opencv; // Creates a new OpenCV Object
PrintWriter pw = null;
PImage depth,copia;
PImage img;
int x=-10,y=-35;
void simplify(PVector[] d, float tol,int s, int e, boolean[] out) {
out[s]=out[e]=true;
if(abs(s-e)<=1) return;
float distance,area, m=0.0;
int who=-1;
PVector a = d[s];
PVector b = d[e];
PVector c = null;
for(int i=s+1;i<e;i++) {
c=d[i];
area=abs(a.x*b.y+b.x*c.y+c.x*a.y - b.x*a.y-c.x*b.y-a.x*c.y);
distance = area/a.dist(b);
if(distance>m && distance>tol) {
m=distance;
who=i;
}
}
if(who==-1) return;
simplify(d,tol,s,who,out);
simplify(d,tol,who,e,out);
}
void setup() {
String filename = sketchPath("out.txt");
try {pw = new PrintWriter(new FileOutputStream(filename));} catch(Exception e) {println("FNFE"); }
size( 640, 480 );
depth = createImage(640,480,RGB);
img = createImage(640,480,RGB);
copia = createImage(640,480,RGB);
kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(true);
kinect.enableRGB(true);
// mm = new MovieMaker(this, width, height, "silueta.mov");
opencv = new OpenCV( this );
}
void draw() {
background(0);
int histo[] = new int[256];
img = kinect.getRGBImage();
//img.updatePixels();
// opencv.loadImage( "depth.png",width, height ); // Opens a video capture stream
opencv.allocate(640,480);
//opencv.read();
//image( opencv.image(), 0, 0 ); // Displays the image in the OpenCV buffer to the screen
//depth.pixels = NativeKinect.getDepthMap();
depth = kinect.getDepthImage();
copia=depth.get();
for(int i=0;i<640*480;i++) { histo[int(brightness(depth.pixels[i]))]++;
if(brightness(copia.pixels[i])>=135 && brightness(copia.pixels[i])<=140) /* copia.pixels[i]=color(200) */ ; else copia.pixels[i]=color(0);
}
//depth.updatePixels();
opencv.copy(copia);
image(img,x,y);
stroke(255);
Blob[] blobs = opencv.blobs( 15000, width*height/2, 100, true, OpenCV.MAX_VERTICES*4 );
if( blobs.length>0) {
PVector[] d = new PVector[blobs[0].points.length];
for( int j=0; j<blobs[0].points.length; j++ ) {
d[j]=new PVector(blobs[0].points[j].x,blobs[0].points[j].y);
}
boolean out[] = new boolean[blobs[0].points.length];
simplify(d,5,0,blobs[0].points.length-1,out);
stroke(250,0,0);
//background(0);
int i=0;
strokeWeight(2);
noFill();
beginShape();
for( int j=0; j<blobs[i].points.length; j++ ) {
if(out[j]==true) {
vertex( blobs[i].points[j].x, blobs[i].points[j].y );
pw.print(blobs[i].points[j].x +" "+ blobs[i].points[j].y + " ");
}
}
endShape(CLOSE);
pw.println();
// mm.addFrame();
}
}
/*
void keyPressed() {
if (key == ' ') {
// Finish the movie if space bar is pressed
// mm.finish();
// Quit running the sketch once the file is written
exit();
}
}
*/
void stop() {
kinect.quit();
super.stop();
}
void keyPressed() {
if (key == 'd') {
x--;
}
else if (key == 'r') {
y--;
}
println (x+","+y);
if (key == ' ') {
// Finish the movie if space bar is pressed
// mm.finish();
// Quit running the sketch once the file is written
exit();
}
}