We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Does anyone know how to get this video capture code working at fullScreen( )? When I change it to full screen it does not work at all and I know it is based on the fact this code was written for a specific size and a lot is based on that size.
This is a modification of Daniel Shiffman's Video - Software Mirrors code. https://processing.org/tutorials/video/
Thanks!
import processing.video.*;
// Size of each cell in the grid, ratio of window size to video size
int videoScale = 20;
// Number of columns and rows in the system
int cols, rows;
// Variable to hold onto Capture object
Capture video;
// used for the noise randomness
float xoff = 0.0;
float yoff = 0.0;
float coff = 0.0;
void setup() {
size(1280, 720);
//fullScreen( );
// Initialize columns and rows
cols = width/videoScale;
rows = height/videoScale;
background(0);
video = new Capture(this, cols, rows);
video.start();
}
// Read image from the camera
void captureEvent(Capture video) {
video.read();
}
void draw() {
video.loadPixels();
// Begin loop for columns
for (int i = 0; i < cols; i++) {
// Begin loop for rows
for (int j = 0; j < rows; j++) {
int x = i*videoScale;
int y = j*videoScale;
color c = video.pixels[i + j*video.width];
fill(c);
stroke(0);
//rotate the rect
xoff = xoff + .01;
float n = noise(xoff) * width;
pushMatrix( );
translate(x + videoScale/2, y + videoScale/2);
rotate(radians(45 + n));
translate(-(x + videoScale/2), -(y + videoScale/2));
// draw the rect with the video color
rect(x, y, videoScale/1.9, videoScale/1.9);
popMatrix( );
}
}
}
Answers
Can you add more details? Do you get an error by any chance? Are you familiar with Capture.list()?
Kf
It works great at size(1280, 720) but if you comment that out and use fullSCreen( ) then it is just black. width and height both are divided by videoScale which I realize would result in a float being returned at the new fullSCreen resolution and it is expecting an int. But the error is not that. I get the error: (Processing core video:3479): GStreamer-CRITICAL **: Trying to dispose element Video Capture, but it is in PAUSED instead of the NULL state. You need to explicitly set elements to the NULL state before dropping the final reference, to allow them to clean up. This problem may also be caused by a refcounting bug in the application or some element.
I did use Capture.list() initially but got rid of it later once I verified that my camera was available and it worked fine without seeking this information from the system.
Do you get that same error line when working with the working version of the sketch? (aka no when running at fulScreen?) Then, it is probly not an error but a warning. I said to use Capture.list because you define your Capture object based on your screen resolution. You need to make sure the screen resolution defined in the constructor is available in your device. If you have verified that, then it is hard to figure what else the problem could be... at least from this side.
A possible solution is to get the Capture working with 1280 x 720 resolution and then display the video using the image() function with 5 parameters. Please check the reference.
Kf
It works fine at 1280 x 720. That screen resolution is available in my camera device. I need it to be full screen and my computer does not have 1280 x 720 as an option on its display in the System Preferences. Its a strange resolution but the best one to to fill the space (I am projecting this) is 1366 x 768. But that is irrelevant. Basically I know that I must capture the image at the resolution of the capture device. It works fine when I do. When I put it in fullscreen mode, it does not work at all because the screen resolution has changed and the new Capture gets sent the width and height of the fullscreen and it does not like that. So basically I need to know how to resize the whole window to fullscreen (scale it up) without affecting the width and height variable. Is there a way to do this?
Thanks kfrajer for your suggestions, they got me thinking. I solved it. I just replaced:
with:
and then added:
scale(1.2)
to my draw( )
The basic problem was that the Capture device was getting a width and height it could not deal with when I went into fullScreen( ). So by using the literal sizes I wanted instead of getting the width and height from the screen size, it stopped complaining and works great.