Help me!
in
Core Library Questions
•
11 months ago
Hi Guys,
I'm very new in processing world. So sorry if my question is a bit silly.
I'm trying to write a code that actually sectionned an instant movie (from the camera of your computer for instance) in several images and put it in a grid, and for this I found this code:
// P_4_2_2_01.pde
//
// Generative Gestaltung, ISBN: 978-3-87439-759-9
// First Edition, Hermann Schmidt, Mainz, 2009
// Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
// Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* simple overview of a video file.
*
* KEYS
* s : save png
*/
import processing.video.*;
Movie movie;
// horizontal and vertical grid count
// take care of the aspect ratio ... here 4:3
int tileCountX = 12;
int tileCountY = 16;
float tileWidth, tileHeight;
int imageCount = tileCountX*tileCountY;
int currentImage = 0;
int gridX = 0;
int gridY = 0;
void setup() {
size(1024, 1024);
smooth();
background(0);
// select path and load video
String path = selectInput("select a video file ...");
movie = new Movie(this, path);
tileWidth = width / (float)tileCountX;
tileHeight = height / (float)tileCountY;
}
void draw() {
float posX = tileWidth*gridX;
float posY = tileHeight*gridY;
// calculate the current time in movieclip
float moviePos = map(currentImage, 0,imageCount, 0,movie.duration());
movie.jump(moviePos);
movie.read();
image(movie, posX, posY, tileWidth, tileHeight);
// new grid position
gridX++;
if (gridX >= tileCountX) {
gridX = 0;
gridY++;
}
currentImage++;
if (currentImage >= imageCount) noLoop();
}
void keyReleased() {
if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");
}
// timestamp
String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
Than I found that code that actually take a picture from the camera of your computer every 5 minutes.
// P_4_2_2_02.pde
//
// Generative Gestaltung, ISBN: 978-3-87439-759-9
// First Edition, Hermann Schmidt, Mainz, 2009
// Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
// Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* timelapse camera. after each intervalTime a picture is saved to the sketch folder
*
*/
import processing.video.*;
Capture myCam;
// intervalTime in sec. here 5 min
int intervalTime = 5*60;
int secondsSinceStart = 0;
String startTime = getTimestamp();
int counter = 0;
boolean doSave = true;
void setup() {
size(640, 480);
println(Capture.list());
//String s = "Logitech QuickCam Messenger-WDM";
//myCam = new Capture(this, s, width, height, 30);
myCam = new Capture(this, width, height, 30);
noStroke();
}
void draw() {
if(myCam.available()) {
myCam.read();
image(myCam, 0, 0);
secondsSinceStart = millis() / 1000;
int interval = secondsSinceStart % intervalTime;
if (interval == 0 && doSave == true) {
String saveFileName = startTime+"-"+nf(counter,5);
saveFrame(saveFileName+".png");
doSave = false;
counter++;
}
else if (interval != 0) {
doSave = true;
}
// visualize the time to the next shot
fill(random(0,255),random(0,255),random(0,255));
rect(map(interval, 0,intervalTime, 0,width),0, 5,5);
}
}
String getTimestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
Basically, I want to mix those two codes. I want to tell the computer "take a picture from your camera every minute and put it a grid".
I'm tried to re-work those codes together but impossible to get something at the end. I think that I actually have issues with the timeframe of my code.
Can Anybody help me, or give me a piece of advice about how I should process?
Thanks a lot in advance.
1