Muybridge grid / Camera capture help
in
Core Library Questions
•
1 years ago
Hello! I'm new to Processing, and am making an installation project based on Muybridge image sequences. I want to capture images of people jumping, and play the images back randomly in a grid. I have the basic code and steps outlined, I'm just not sure what the missing pieces are.
Steps:
-capture (saveFrame) is supposed to be set off by a tilt switch (Arduino)
-saved frames sent with naming convention to a folder called jump (would overwrite after 500 images)
-images are called back into a grid of 10 x 10 images. This is to display the jump states of various people together in a grid
My questions are:
- if it's possible to capture as well as call back images to display at the same time. I tried with a second camera.
- how to capture images at 640 x 480 and resize to the grid of 10 x 10 (64 x 48)
I'll copy both the code for the image capture/ serial event and the image grid below. Any help would be really appreciated. Thanks in advance.
GRID:
import processing.video.*; // video library
int maxImages = 16; // Total # of images (will be more)
int imageIndex = 0; // Initial image to be displayed is the first
// Declaring an array of images.
PImage[] images = new PImage[maxImages];
ImageGrid grid;
void setup() {
size(640, 480, P2D);
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage("jump" + nf(i,3) + ".jpg" );
}
frameRate(5);
grid = new ImageGrid(images,10,10);
}
void draw() {
background(0);
grid.draw(imageIndex);
// increment image index by one each cycle
// use modulo " % "to return to 0 once the end of the array is reached
imageIndex = (imageIndex + 1) % images.length;
}
class ImageGrid {
int xSize;
int ySize;
int xTiles;
int yTiles;
int xTile;
int yTile;
int xImagePos;
int yImagePos;
int offset;
PImage[] images;
int imageCount;
ImageGrid(PImage[] tempImages, int tempXtiles, int tempYtiles) {
images = tempImages;
xTiles = tempXtiles;
yTiles = tempYtiles;
}
void draw(int startOffset) {
// get the image size
xSize = images[0].width;
ySize = images[0].height;
imageCount = 0;
for (yTile = 0; yTile < yTiles; yTile++) {
for (xTile = 0; xTile < xTiles; xTile++) {
xImagePos = xTile * (xSize+10) + 10;
yImagePos = yTile * (ySize+10) + 10;
offset = (startOffset + imageCount) % images.length;
image(images[offset],xImagePos,yImagePos);
imageCount++;
}
}
}
}
CAPTURE/ SERIAL EVENT
import processing.video.*;
import processing.serial.*;
Serial myPort;
Capture myCapture;
int jumpThreshold;
void setup()
{
size(640, 480);
myCapture = new Capture(this, width, height, 30);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void captureEvent(Capture myCapture) {
myCapture.read();
}
void serialEvent(Serial myPort) {
int inByte = myPort.read();
println(inByte);
jumpThreshold=inByte;
if (jumpThreshold > 0);
saveFrame("jump/jump###.jpg");
}
}
Steps:
-capture (saveFrame) is supposed to be set off by a tilt switch (Arduino)
-saved frames sent with naming convention to a folder called jump (would overwrite after 500 images)
-images are called back into a grid of 10 x 10 images. This is to display the jump states of various people together in a grid
My questions are:
- if it's possible to capture as well as call back images to display at the same time. I tried with a second camera.
- how to capture images at 640 x 480 and resize to the grid of 10 x 10 (64 x 48)
I'll copy both the code for the image capture/ serial event and the image grid below. Any help would be really appreciated. Thanks in advance.
GRID:
import processing.video.*; // video library
int maxImages = 16; // Total # of images (will be more)
int imageIndex = 0; // Initial image to be displayed is the first
// Declaring an array of images.
PImage[] images = new PImage[maxImages];
ImageGrid grid;
void setup() {
size(640, 480, P2D);
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage("jump" + nf(i,3) + ".jpg" );
}
frameRate(5);
grid = new ImageGrid(images,10,10);
}
void draw() {
background(0);
grid.draw(imageIndex);
// increment image index by one each cycle
// use modulo " % "to return to 0 once the end of the array is reached
imageIndex = (imageIndex + 1) % images.length;
}
class ImageGrid {
int xSize;
int ySize;
int xTiles;
int yTiles;
int xTile;
int yTile;
int xImagePos;
int yImagePos;
int offset;
PImage[] images;
int imageCount;
ImageGrid(PImage[] tempImages, int tempXtiles, int tempYtiles) {
images = tempImages;
xTiles = tempXtiles;
yTiles = tempYtiles;
}
void draw(int startOffset) {
// get the image size
xSize = images[0].width;
ySize = images[0].height;
imageCount = 0;
for (yTile = 0; yTile < yTiles; yTile++) {
for (xTile = 0; xTile < xTiles; xTile++) {
xImagePos = xTile * (xSize+10) + 10;
yImagePos = yTile * (ySize+10) + 10;
offset = (startOffset + imageCount) % images.length;
image(images[offset],xImagePos,yImagePos);
imageCount++;
}
}
}
}
CAPTURE/ SERIAL EVENT
import processing.video.*;
import processing.serial.*;
Serial myPort;
Capture myCapture;
int jumpThreshold;
void setup()
{
size(640, 480);
myCapture = new Capture(this, width, height, 30);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void captureEvent(Capture myCapture) {
myCapture.read();
}
void serialEvent(Serial myPort) {
int inByte = myPort.read();
println(inByte);
jumpThreshold=inByte;
if (jumpThreshold > 0);
saveFrame("jump/jump###.jpg");
}
}
1