New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pixels[] array not updated with Capture and P2D/P3D #1852
Comments
I have an issue probably due to the same problem : the function Capture.get() don't work with the P2D renderer. |
Yes, accessing the pixels array of a video frame (either with Movie or Capture) is broken in 2.0. The get() function is just another way of accessing the pixels array. You can currently use Movie and Capture with the P2D/P3D renderers (which will give you better performance) as long as you don't need the pixels. |
In general, this will affect any sketch or library that tries to use the pixels from a video frame under P2D/P3D. |
Eek. This is a major problem for me. I been trying to track down why my sketch didn't work after I updated to 2.0 (from beta 8). It uses video and loads the pixel array for each frame. I'm using OPENGL and still having this issue. I hope it's fixed soon. |
Something else i'm noticing. My filters, applied to movies, are not recognized. Such as... myMovie.filter(GRAY); ... They just don't work. |
I'm not sure but I found: And it seems like copyPixels is never set to hold any values except creating the array. |
Fixed with fc0a8fd |
I tried the following sketch to validate the problem. I run this on Mountain Lion with Processing 2.0.3. import processing.video.*;
Capture cam;
PImage img;
void setup() {
size(640, 480); // OK
// size(640, 480, P2D); // NG
// size(640, 480, P3D); // NG
String[] cams = Capture.list();
if (cams.length == 0) {
println("No camera.");
exit();
}
else {
cam = new Capture(this, cams[0]);
cam.start();
}
}
void draw() {
background(0);
// Draw the image.
if (img != null) {
image(img, 0, 0);
}
}
void captureEvent(Capture c) {
c.read();
// Create an image.
if (img == null || img.width != c.width || img.height != c.height)
img = createImage(c.width, c.height, ARGB);
// Just taking a copy.
int num = img.width * img.height;
for (int i = 0; i < num; i++) {
img.pixels[i] = c.pixels[i];
}
img.updatePixels();
} |
You need to call loadPixels() before accessing the pixels array, otherwise is not guaranteed to contain the image: c.loadPixels();
int num = img.width * img.height;
for (int i = 0; i < num; i++) {
img.pixels[i] = c.pixels[i];
}
img.updatePixels(); |
I think this issue may still persist for some hardware configurations. I am having this issue on my laptop. This code works fine on my desktop but gives me issues on my laptop. On my laptop the camera displays fine but when I try and copy it through the copy method or by pixel like in my example code all I get back is black. import processing.video.*;
Capture video;
PImage prevFrame;
float threshold = 50;
int diffWidth = 320;
int diffHeight = 240;
PFont f;
void setup() {
size(1024,768, P2D);
video = new Capture(this, diffWidth, diffHeight);
// Create an empty image the same size as the video
prevFrame = createImage(video.width,video.height,RGB);
video.start();
}
int fcount = 0;
void draw() {
background(0);
// Capture video
if(video.available())
{
// Save previous frame for motion detection!!
prevFrame.loadPixels();
video.loadPixels();
int len = video.width* video.height;
for(int i = 0; i < len; i++)
{
prevFrame.pixels[i] = video.pixels[i];
}
prevFrame.updatePixels();
video.read();
println("got a frame");
}
image(prevFrame, 0, 0, diffWidth, diffHeight);
image(video, 0, diffHeight, diffWidth, diffHeight);
} |
@Wavewash did you consider plugging in a webcam on your desktop computer? |
@nadineprigann Thank for your reply - I don't remember the problem anymore (it was 3 years ago) but I must've got past it. I still play with processing and video integration - and I don't have issues like this anymore so it must've gotten cleared up. Thanks! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Capture examples like AsciiVideo, Mirror, Mirror2 (possibly all the ones that access the pixels array) don't work when using P2D as the renderer, they only show a black screen. This is most likely due to the recent changes in the handling of the pixels array, which conflicts with the optimizations implemented in the video library when the renderer is GL (the video frames go directly into the texture of the Capture object, so the pixels array doesn't contain any valid data).
The text was updated successfully, but these errors were encountered: