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
See if lights are on (Read 1020 times)
See if lights are on
Mar 2nd, 2010, 3:29pm
 
Hey everyone  -

Sorry if I post this in the wrong section.  I am currently working on a project that will have the user sitting in the dark watching a video.  Then, at a certain point, if they turn the lights on, then it will play ending A video.  If they don't turn the lights on, then it will play ending B video.  I don't know what the easiest way is to go about this.  Currently I am using OpenCV to play the video, Minim to play the voiceover, and was trying to get JMyron to test for light.  But with JMyron I am clueless on how to get it to just see "is it light, or is it dark?"  Any help would be appreciated on what I should do and if there's a better way I can do it.  Thanks!

Code:

import ddf.minim.*;
import fullscreen.*;
import japplemenubar.*;
import hypermedia.video.*;

AudioPlayer player;
Minim minim;
OpenCV opencv;
boolean remember = false;
FullScreen fs;



void setup() {

size( 640, 480 );
fs = new FullScreen(this);
fs.enter();
minim = new Minim(this);

opencv = new OpenCV( this );
opencv.movie( "video.mpg" );

player = minim.loadFile("song.mp3", 2048);

noCursor();

}

void draw() {

opencv.read();
if ( remember ) opencv.absDiff();
//sopencv.threshold( 200 );
player.play();
image( opencv.image(), 0, 0 );



}

void stop()
{
// always close Minim audio classes when you are done with them
player.close();
minim.stop();
opencv.stop();
super.stop();
}

Re: See if lights are on
Reply #1 - Mar 2nd, 2010, 3:46pm
 
yes, it is in the wrong section. belongs in "programs"
anyway. You could try using http://processing.org/reference/libraries/video/Capture.html to get a frame from your webcam. Low resolution and slow frameRate will work here. you can now calculate the average color and get the brightness using brightness(). if the brightness changes a certain degree light is turned on/off...
Re: See if lights are on
Reply #2 - Mar 2nd, 2010, 11:51pm
 
This Topic was moved here from Exhibition by antiplastik.
Re: See if lights are on
Reply #3 - Mar 3rd, 2010, 12:09am
 
alright Smiley antiplastik thinks it belongs to "Vision Libraries"
Re: See if lights are on
Reply #4 - Mar 3rd, 2010, 1:09am
 
the most precise way would be to use an arduino with a light sensor on it: this way you'd be able to mesure exactly the amount of light in the room.

anyway also looking for brightness (or blob dimesnion, or threshold white area, ecc) change would probably work pretty fine.
Page Index Toggle Pages: 1