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.
Page Index Toggle Pages: 1
save and display frame from webcam (Read 2946 times)
save and display frame from webcam
Nov 10th, 2007, 10:02pm
 
help !!!!
I completely new (one week using processing)
I need to make a program for run a webcam.
then with a mouse click (i will actually use a sensor conected to arduino), capture a frame and display it in full screen.

I am allready using the jmyron library to display the webcam:

import JMyron.*;

JMyron m;//a camera object

void setup(){
 size(640,480);
 m = new JMyron();//make a new instance of the object
 m.start(width,height);//start a capture at 320x240
 m.findGlobs(0);//disable the intelligence to speed up frame rate
 println("Myron " + m.version());
 println("Forced Dimensions: " + m.getForcedWidth() + " " + m.getForcedHeight());
 loadPixels();
}
void draw(){
 m.update();//update the camera view
 m.imageCopy(pixels);//draw image to stage
 updatePixels();
}
public void stop(){
 m.stop();//stop the object
 super.stop();
}

I have added the folowing to capture a frame in a jpg format:

void mousePressed(){
saveFrame("####.jpg");

I attempting to use loadimage to display it...

my problem is that the webcam window (320,240) keeps running and don't allow me to display the image full screen.
I am also trying to do all of these in real time so people can be aproching the web cam, then capture the frame, display it and keep running the web cam to capture another...

i probably need to stop the web cam and then reiniciate it seconds after the display, but i don't really have a clue of how to do it.

can some one help me !!! this is really urgent..

Re: save and display frame from webcam
Reply #1 - Nov 11th, 2007, 9:08am
 
inside draw() do:

if ( mousePressed == false )
{
 m.update();
 m.imageCopy(pixels);
 updatePixels();
}

this will halt the current frame as long as the mouse is pressed (because it will only be updated if it's not pressed).

another idea woud be to create a variable of type boolean and switch that over if mouse was pressed like:

boolean webCamMode = true;

void draw ()
{
 if ( webCamMode ) {
// same as above
}
}

void mousePressed () {
webCamMode = !webCamMode; // the "!" inverts the boolean (true / false)
}


F
Re: save and display frame from webcam
Reply #2 - Nov 11th, 2007, 12:40pm
 
thanks fjen !! this is very clever!
i will explain better my situation (because i did't do it
well), perhaps i can get a bit more help..

complete description:

there is a pc monitor with a webcam ("running constantly"), when you approach to it a sensor will detect you presence and activate a "saveframe" to capture a jpg image of your face, then your photo will be display fullscreen in the monitor, then an animation to reduce the photo and place it in the bottom of the screen... photos will be acumulating in a reticular array.

I have different parts of the script:

- the one from jmyron to "run" the webcam
- the "saveframe" actions to save a jpg image in to the sketch folder. This is now provitionally activated with the click of the mouse (i expect to do it with a sensor signal from "arduino").
- the "loadimage" actions to load and display the image in the screen.
- the animation and placement of the image

my problem is their "asemblage in one script".

specific problem:

to work with jmyron the webcam is displayied in size(320,240), I can save the frame (no problem), but then to load it down and display it (full screen) it's probably needed to stop the webcam, setup again the window (in full screen size).. ?
(i think that the constant "running" of the webcam is not leting me to make the rest).

diagram:
running webcam - sensor or mouse signal - save frame - stop web cam - setup, load and display image - animation and placement of image.

conclution:
i don't know how to stop the web cam, make the rest and restart again the web cam.

notes:

I don't actually need to see the webcam live display,  I would rather have a full screen window showing the arrenge of photos. (the display of the photo full screen and then it's placement and acumulation).

sorry for this long explanation, i asume that forums ara not ment to be use this way, but I am lost.

probably there is a easiest way to do it, I have read this in other discution:

"I think your solution might be to copy the webcam input to a image castmember and display that on screen while constantly refreshing.  

At the moment you want to capture the webcam visual, stop refreshing and copy the image castmember to a new castmember.  

In this way you will always have the image on screen directly, while still be able to keep on viewing the webcam input after capturing. "

that sounds grate but I don undertand quite well what is a "castmember" and how to use it.

thanks !!!!
Page Index Toggle Pages: 1