Skip to content
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

Closed
codeanticode opened this issue Jun 3, 2013 · 13 comments
Closed

pixels[] array not updated with Capture and P2D/P3D #1852

codeanticode opened this issue Jun 3, 2013 · 13 comments
Assignees
Labels
high We'd like to fix this as soon as possible opengl video

Comments

@codeanticode
Copy link
Member

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).

@ghost ghost assigned codeanticode Jun 3, 2013
@P0ulp
Copy link

P0ulp commented Jun 4, 2013

I have an issue probably due to the same problem : the function Capture.get() don't work with the P2D renderer.
Tested with the Processing 2 version on win 7.

@codeanticode
Copy link
Member Author

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.

@codeanticode
Copy link
Member Author

In general, this will affect any sketch or library that tries to use the pixels from a video frame under P2D/P3D.

@spelljammed
Copy link

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.

@spelljammed
Copy link

Something else i'm noticing. My filters, applied to movies, are not recognized. Such as... myMovie.filter(GRAY); ... They just don't work.

@clankill3r
Copy link

I'm not sure but I found:
pixels = copyPixels;
In https://github.com/processing/processing/tree/master/java/libraries/video/src/processing/video -> capture.java

And it seems like copyPixels is never set to hold any values except creating the array.
I think it should be fixed somewhere around line 954. But i'm probably wrong.

@codeanticode
Copy link
Member Author

Fixed with fc0a8fd

@comoc
Copy link

comoc commented Sep 14, 2013

I tried the following sketch to validate the problem. I run this on Mountain Lion with Processing 2.0.3.
When I choose P2D or P3D, the img is never updated.

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(); 
}

@codeanticode
Copy link
Member Author

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();

@Wavewash
Copy link

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.
My desktop has a Radeon 5770.
My laptop has a Radeon 6750M.

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);
}

@npnpnpnpnpnp
Copy link

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.

@Wavewash did you consider plugging in a webcam on your desktop computer?

@Wavewash
Copy link

Wavewash commented Apr 8, 2017

@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!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
high We'd like to fix this as soon as possible opengl video
Projects
None yet
Development

No branches or pull requests

7 participants