Hello Processing Discourse!
I am trying to select a portion of video from a video capture by dragging a rectangle and then display that to a second window (a new PApplet). My question is how do I pass the captured cropped image from the first PApplet to the second, I’ve done a fair bit of googling and looking on here but can’t figure it out. Unfortunately my code is based on using the kinect library, I can’t get the video library working on my machine (OSX Catalina) or I would have provided something more generic.
I think there is probably an issue with how/where I am trying to store the selected pixels to PImage crop and then also how I am trying to display that in the second PApplet, what I find interesting and frustrating is that I can pass the variables for my selection rectangle to the second PApplet and display that no problem.
Any advice or pointers in the right direction much appreciated.
Ta
import org.openkinect.freenect.*;
import org.openkinect.freenect2.*;
import org.openkinect.processing.*;
Kinect2 kinect2;
int x, y, w, h; //x,y,w,h of crop rect
PImage full;
PImage crop = null;
void settings() {
size(960, 540);
pixelDensity(2);
}
void setup() {
x=0;
y=0;
w=0;
h=0;
kinect2 = new Kinect2(this);
kinect2.initVideo();
kinect2.initDevice();
String[] args = {"SecondFrame"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
void draw() {
full = kinect2.getVideoImage();
background(0);
//flip kinect video and scale to width/height
pushMatrix();
scale(-1, 1);
image(full, -map(kinect2.colorWidth, 0, kinect2.colorWidth, 0, width), 0, map(kinect2.colorWidth, 0, kinect2.colorWidth, 0, width), map(kinect2.colorHeight, 0, kinect2.colorHeight, 0, height));
popMatrix();
//this breaks the code when i try to draw crop rect
//i think it should be loading the crop rect pixels to PImage crop?
//crop = get(x, y, x + w, y + h);
noFill();
stroke(255, 0, 0);
rect(x, y, w, h);
}
void mousePressed() {
x = mouseX;
y = mouseY;
}
void mouseDragged() {
w = mouseX-x;
h = mouseY-y;
rect(x, y, w, h);
}
public class SecondApplet extends PApplet {
public void settings() {
size(960, 540);
pixelDensity(2);
}
public void draw() {
background(255);
noFill();
stroke(255, 0, 0);
//and this breaks the code :(
//image(crop, 0, 0);
rect(x, y, w, h);
}
}