Delayed camera capture
in
Programming Questions
•
2 years ago
Hi all...
First post here, though I've been using the forum for help for a while. Couldn't think of a suitable title for the thread...
I've got a camera and projector set up pointing at a surface and part of what I need to do is (on a key press) project a black filled window for a moment, so that the projector projects nothing, and in this time have the camera capture a still image of whatever is in the frame. Then I want to project that image afterwards. This is just a small part of a bigger project so it might not make sense why I would want to do that.
Anyway, the problem I'm having is getting the camera to capture during this time period (which is set to 1 second for the moment). The way it's working currently is that it's capturing the frame immediately before the black second is projected.
This is the code so far. I have made several attempts trying to get cam.read(); to work at 500 milliseconds but it hasn't worked. Any help would be greatly appreciated. Thanks!
- import processing.video.*;
- int captureTimerStart;
- int delaytime = 1000;
- boolean timer = false;
- Capture cam;
- PImage scene; // "scene" is the main projected image that will be updated with each new capture
- void setup()
- {
- size(1400, 1050); // 1400 by 1050 is the correct size for setup uding MacBookPro laptop and InFocus projector
- scene = loadImage("sceneTest.jpg");
- image(scene, 0, 0);
- cam = new Capture(this, 1400, 1050);
- cam.settings(); // choose camera and quality settings
- }
- void draw()
- {
- if(keyPressed)
- {
- if (key == 'b' || key == 'B' && timer == false) // if 'b' is pressed and timer is not running
- {
- captureTimerStart = millis();
- //captureTimer = millis();
- timer = true; // start the timer
- fill(0); // set colour to black
- rect(0, 0, 1400, 1050); //project a blank frame
- cam.read(); //capture the current frame
- }
- }
- if (millis() - captureTimerStart >= delaytime) // when timer reaches zero
- {
- image(cam, 0, 0);
- }
- }
1