We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Draw lines over image from webcam
Page Index Toggle Pages: 1
Draw lines over image from webcam (Read 1009 times)
Draw lines over image from webcam
Dec 17th, 2008, 12:02am
 
Hello all!

I'm trying to draw a grid 3x3 over an image I'm capturing with my webcam, but unfortunatelly I'm only being able to draw some points on the first line of the image.

I'm also flipping my acquired image over the x-axis in order to see me moving to the right if I'm moving to the right, and to the left if I'm moving left. If I don't flip the image I can get a framerate around 35 fps, and flipping it I can get around 25 fps. Is it possible to speed up my code or do this flip by other faster means?

Any help on this subjects?

Thank you very much in advance.

Best regards!

My code is as follows:

import processing.opengl.*;
import JMyron.*;

JMyron m;
PImage img;

void setup() {
 size(320,240,OPENGL);
 m = new JMyron();
 m.start(width,height);
 img = createImage(width,height,ARGB);
 noFill();
 stroke(255,0,0);
}

void draw() {
 background(0);
 
// code for drawing the lines
 for(int i=1; i<3; i++){
   stroke(255,0,0);
   line(width/3*i,0,width/3*i,height);
 }

 m.update();

//code for flipping
 int[] imgNormal = m.cameraImage();
 this.loadPixels();
 for(int i=1; i<width;i++){
   for(int j=1;j<height;j++){
     this.pixels[(m.width() - i - 1) + j * m.width()] = imgNormal[(i) + j * m.width()];
   }
 }
 this.updatePixels();

 arraycopy(m.cameraImage(),img.pixels);
 img.updatePixels();

 image(img,0,0);
 print(frameRate +"\n");
}
Re: Draw lines over image from webcam
Reply #1 - Dec 17th, 2008, 2:13am
 
Hi, i've modified your code and i can get 40fps with it.

What are your computer's specs ?


Code:
import JMyron.*; 

JMyron m;
PImage img;

void setup() {
size(320,240,P3D);
m = new JMyron();
m.start(width,height);
img = createImage(width,height,ARGB);
noFill();
stroke(255,0,0);
}

void draw() {
//background(0);

m.update();

//code for flipping
int[] imgNormal = m.cameraImage();
this.loadPixels();
for(int i=1; i<width;i++){
for(int j=1;j<height;j++){
this.pixels[(m.width() - i - 1) + j * m.width()] = imgNormal[(i) + j * m.width()];
}
}
this.updatePixels();

arraycopy(m.cameraImage(),img.pixels);
img.updatePixels();

// image(img,0,0);

// code for drawing the lines
for(int i=1; i<3; i++){
stroke(255,0,0);
line(width/3*i,0,width/3*i,height);
line(0,height/3*i,width,height/3*i);
}

print(frameRate +"\n");
}
Re: Draw lines over image from webcam
Reply #2 - Dec 17th, 2008, 10:39am
 
Hello!

Thank you very much for your help.

I'm now achieving ~38 fps, but you did not change the code for flipping the image, right?

My computer has a Intel Core 2 Duo CPU @ 2.50GHz with 3GB of RAM.
Re: Draw lines over image from webcam
Reply #3 - Dec 18th, 2008, 9:52am
 
I just changed the rendering to P3D, removed image(), then corrected and moved the for loop that draws lines at the end of draw() so they are drawn on top of the video.
Page Index Toggle Pages: 1