We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My code takes a screenshot of the window; the goal is to take a screenshot of the webcam feed, which is smaller than the program window, which is necessary for what my end goal. It then loads the screenshot into the program as a PImage. Is there a way to only capture the image from the dimensions of the webcam feed? Or is there a way to crop the .jpg in the data folder without leaving the program?
import processing.video.*;
Capture cam;
PImage capture;
void setup() {
//window size
size(1280, 720, P3D);
background (0);
noCursor();
//webcam feed
capture = loadImage ("capture.jpg");
imageMode (CENTER);
String[] cameras = Capture.list();
//webcam feed
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
cam = new Capture(this, cameras[0]);
cam.start();
}
}
void draw() {
if (cam.available() == true) {
cam.read();
}
//web cam feed position, size
image(cam, 640, 360, 320, 180);
}
void mousePressed() {
//image capture
saveFrame("data/capture.jpg");
cam.read();
//loads image capture in
image (capture, 200, 200, 480, 270);
image (capture, 1000, 500, 480, 270);
}
Answers
https://processing.org/reference/get_.html
Kf
please don't post duplicates
what's up with the answers on this other thread?
https://forum.processing.org/two/discussion/19260/resizing-a-captured-image
It's not a duplicate. Turns out I had the opposite problem, so I made a new post. And the answer to the other didn't help anything at all, just sent me backwards in my work.
Thanks Kf
Ok, so the other posts were closed. I figure your problem why the second screenshot is not being shown. That is because you load your screen capture image in setup. You should do that in mousePressed instead after you save your current frame. Add the following line there and remove the one in setup:
Also, you need to remove cam.read() in mousePressed. Please review the reference to find out why.
Kf
In general, when you have a PImage or PGraphics pixel array...
If you want to display the image at a different size, use
image()
to draw it at the new size:This will display your image at the new width and height. See the image() reference for details.
If you want to crop the image to a different size, use
get()
orcopy()
:See the get() reference or the copy() reference for details.