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 › OPENGL, WEBCAM, and PIMAGE
Pages: 1 2 
OPENGL, WEBCAM, and PIMAGE (Read 6219 times)
OPENGL, WEBCAM, and PIMAGE
Mar 2nd, 2006, 12:07am
 
Wondering if anyone can help me with this problem I'm in having OPENGL. It seems when I use "import processing.video.*;" to capture webcam images, I cant display any images loaded into a PImage object at the same time. Ill get either the background turning completely white, or sometimes I get a webcam image showing where I want the PImage to show. It happens specifically when loading an Image into a PImage object and trying to display that PImage object. For example if i create a PImage object and copy the copy a the webcam capture into it, and manipulate the pixels in the PImage object, everything runs smooth. But if I try to display a WEbcam Image and an image loaded into PImage from the data folder everything goes nuts and images display mixed up, the background goes white, when it was supposed to be black, images show as solid rects instead of displaying the data theyre supposed to hold.


Fry mentions a similar problem in this thread
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_3DOpenGL;action=display;num=1138041434

"...other than that, if it's truly showing up in random places (like if you load a font and some of the characters are a webcam image) then you might have a texture binding problem which might require another solution... "


It seems to me this is some weird OPENGL bug. I would really apprecriate any help anyone could give with this

thanks
Re: OPENGL, WEBCAM, and PIMAGE
Reply #1 - Mar 8th, 2006, 12:55pm
 
Hi Dylan,

I'm not sure if this will work in your case, I had similar problems and this seems to be a solution. In OPENGL, always call (yourImage.loadPixels() and) yourImage.updatePixels() before drawing them to the screen. Even if you do not do any pixel operations (like when just displaying an image that is loaded from your disk). If you draw an image twice in one frame then also call yourImage.updatePixels() twice. When you forget to do this the images get mixed up. It might also be a good idea to call image1.updatePixels() right before image(image1..), and not image1.updatePixels(), image2.updatePixels(), image(image2..), image(image1..)
I'm not sure if the latter really matters though. Good luck!
Re: OPENGL, WEBCAM, and PIMAGE
Reply #2 - Mar 8th, 2006, 2:09pm
 
Also try replacing PImage with PGraphics3. Though not supported, you may have luck with that technique.

Remember to do .updatePixels() after writing to it, and before displaying it, though!
Re: OPENGL, WEBCAM, and PIMAGE
Reply #3 - Mar 8th, 2006, 7:39pm
 
THANK YOU!

IT WORKS!

Im updating a PImage for now. I've had lots of trouble trying to use PGraphics3 before.
Re: OPENGL, WEBCAM, and PIMAGE
Reply #4 - Apr 22nd, 2009, 2:21pm
 
can someone give a example script, I can't get the damn thing to work under OPENGL and I tryd loadPixels and updatePixels before drawning the image.
Re: OPENGL, WEBCAM, and PIMAGE
Reply #5 - May 6th, 2009, 4:04pm
 
someone plz?

I got this not working so far:

also how doI use a PImage for putting out a webcam image?
(or PGraphics3 / PGraphics3D)

Code:
 
import processing.video.*;
import processing.opengl.*;

Capture cam;

void setup() {
size(640, 480, OPENGL);

cam = new Capture(this, 320, 240);

}


void draw() {
if (cam.available() == true) {
cam.read();
cam.loadPixels();
cam.updatePixels();
image(cam, 160, 100);
}
}
Re: OPENGL, WEBCAM, and PIMAGE
Reply #6 - May 8th, 2009, 10:28am
 
I don't have a webcam to test here, but would putting loadPixels() before cam.read() work? Since read() alters the pixel array...
Re: OPENGL, WEBCAM, and PIMAGE
Reply #7 - May 9th, 2009, 8:53am
 
Like NoahBuddy I don't have a webcam to use.

I maybe missing the point here but why are you using OPENGL? The only reason I know of to use P3D or OPENGL is if you want to use 3D graphics but I could be wrong about that and if I am I would be interested in hearing from you.

So why not try

Code:
size(320,240,P2D) 



With respect to the code I have looked at the reference for the Camera class (rather sparse) and the read() method needs to be executed first so as to get the image. The loadPixels() is needed if and only if you wish to examine and/or modify the pixel array data. If you modify the pixel array data then you need to follow any modifications with updatePixels()

Smiley
Code:

import processing.video.*;
import processing.opengl.*;

Capture cam;

void setup() {
 size(640, 480, OPENGL);

 cam = new Capture(this, 320, 240);

}


void draw() {
 if (cam.available() == true) {
   cam.read();
   cam.loadPixels(); // I want to modify some piexels
   // My modifications go here
   cam.updatePixels(); // Save my modifications
   image(cam, 160, 100);
 }
}  

Re: OPENGL, WEBCAM, and PIMAGE
Reply #8 - May 9th, 2009, 4:42pm
 
I don't see any difference with your code but your code works, what is the difference?

thx btw

edit:

it worked once, even after restarting processing it didn't work again.
Maybe after a reboot but I don't want to try now.

edit:

it only prints 1,
so this line make's it hanging right?

 cam = new Capture(this, 320, 240);

Code:

import processing.video.*;
import processing.opengl.*;

Capture cam;

void setup() {
size(640, 480, OPENGL);
println("1");
cam = new Capture(this, 320, 240);
println("2");

}


void draw() {
if (cam.available() == true) {
println("3");
cam.read();
cam.loadPixels(); // I want to modify some piexels
// My modifications go here
cam.updatePixels(); // Save my modifications
//image(cam, 160, 100);
set(160, 100, cam);
}
}

Re: OPENGL, WEBCAM, and PIMAGE
Reply #9 - May 11th, 2009, 1:40am
 
I suspect that it didn't recognise the web cam the second time you ran the program.

In most cases if Processing experiences a problem running a program it will display some info about the problem in the bottom window below the sketch. Did you get messages?
Re: OPENGL, WEBCAM, and PIMAGE
Reply #10 - May 11th, 2009, 9:23am
 
No nothing.

Is there an alternative way for:

 cam = new Capture(this, 320, 240);

like can I replace this with something else for example?
Re: OPENGL, WEBCAM, and PIMAGE
Reply #11 - May 11th, 2009, 12:24pm
 
Can you load a video file in its place?
Re: OPENGL, WEBCAM, and PIMAGE
Reply #12 - May 11th, 2009, 1:19pm
 
how do I do that?
Re: OPENGL, WEBCAM, and PIMAGE
Reply #13 - May 11th, 2009, 2:38pm
 
In other words, can you play a video instead of from a web cam but in OpenGL?

Code:
/*
* Modified from Loop example
*
*/
import processing.opengl.*;
import processing.video.*;

Movie myMovie;

void setup() {
size(640, 480, OPENGL);
background(0);
// Load and play the video in a loop
myMovie = new Movie(this, "station.mov");
myMovie.loop();
}

void movieEvent(Movie myMovie) {
myMovie.read();
}

void draw() {
set(160, 100, myMovie);
}
Re: OPENGL, WEBCAM, and PIMAGE
Reply #14 - May 11th, 2009, 3:39pm
 
No I can not play a video instand of a movie.

what can be causing this?

btw that's a dutch train  Cool
Pages: 1 2