-
December 4th, 2011, 04:17 PM
#1
Translate Java to C code
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();
}
}
-
December 5th, 2011, 02:26 AM
#2
Re: Translate Java to C code
Originally Posted by chezmark
May the force be with you.
The best force in this case is money. Contact a consulting firm and offer to pay what it costs to get this job done for you.
-
December 5th, 2011, 08:06 AM
#3
Re: Translate Java to C code
what the hell... Does C have the potency to do that? Siluette detection might be a little too advanced
-
December 5th, 2011, 09:22 AM
#4
Re: Translate Java to C code
Does C have the potency to do that?
Actually, you can write pretty much anything in C if you have the skill - that and it's execution speed is why it became so popular. The problem is you can also do an awful lots of things that you shouldn't be allowed to do which is why C programs are so prone to bugs.
-
December 6th, 2011, 12:08 PM
#5
Re: Translate Java to C code
haha...*cough* goto *cough*
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|