We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › openCV.pixels() - or is there another way
Page Index Toggle Pages: 1
openCV.pixels() - or is there another way? (Read 2482 times)
openCV.pixels() - or is there another way?
Jul 10th, 2009, 7:49am
 
Hello,

I'm trying to do some analysis on a movie using openCV. I'm using opencv.absDiff() to generate an image that contains differences from a reference frame, and I want to sum the differences (ie, all the pixels that are not black) and tally them frame by frame to measure the change over time (if that makes sense!).

I'm struggling to find the correct syntax to actually get a hold of the pixels in the difference image. Here's an edit of what I'm trying:

Quote:
  opencv.image().loadPixels();
  for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
    color currColor = opencv.image().pixels[i];
    // Extract the red, green, and blue components from current pixel
    int currR = (currColor >> 16) & 0xFF; // Like red(), but faster
    int currG = (currColor >> 8) & 0xFF;
    int currB = currColor & 0xFF;
  }



The bit that seems to not work properly is the Quote:
    color currColor = opencv.image().pixels[i];

although, to be fair, it does seem to work but it's astonishingly slow. I know there is an opencv.pixels() function, but I don't know how to use it. Can anyone help me with this?

Thanks in advance for any advice.
Re: openCV.pixels() - or is there another way?
Reply #1 - Jul 15th, 2009, 10:04am
 
you're calling opencv.image() numPixels times.
should probably only be called once per frame.
so try this

PImage ourimage;

global variable. then

ourimage = opencv.image();
ourimage.loadPixels();

outside your loop there. and then

color currColor = ourimage.pixels[i];

inside the loop. should speed things up.

actually in practice i've noticed that you dont always need to do loadPixels() to access the pixels buffer. so you should probably try commenting it out and see how it behaves.

also, there is a pixels() function in opencv
http://ubaa.net/shared/processing/opencv/opencv_pixels.html
which might or might not do what you're aiming for. havent really used opencv much.
Page Index Toggle Pages: 1