Get pixel color from ofVideoPlayer

Hi,

When I need to get pixel data of an image to color i am using this inside a for loop:

ofColor c = image.getColor(x, y);

Is there a similar method to get pixel data from ofVideoPlayer ??

ofColor c = video.getPixel(x,y);

?

You can do:

ofPixels pix = video.getPixels(); 
ofColor c = pix.getColor(x,y);

Or even ( but less efficient if querying a bunch of pixels )

ofPixels pix = video.getPixels().getColor(x,y);

I would also make sure to wrap that with

video.isFrameNew() so that you are waiting until there is a valid video frame

ie:

video.update(); 
if( video.isFrameNew() ){
  ofPixels pix = video.getPixels(); 
  ofColor c = pix.getColor(x,y);
}

hope that helps!
Theo

HI Theo,
Thanks for the help : )

I am getting this error when I try this method

[ error ] ofPixels: format doesn’t support channels
[warning] returning color not supported yet for UNKOWN format

Ah. Thats probably because the video frame is not ready yet - make sure to only call getPixels() when video.isFrameNew() is true.

void ofApp::update(){

	camera.update();
	ofPixels pix = camera.getPixels();
	if (camera.isFrameNew()) {
		for (int i = 0; i < cameraHeight; i++) {
			for (int j = 0; j < cameraWidth; j++) {
				ofColor c = pix.getColor(i, j);
			}
		}
	}
	
}

Unfortunately, this doesn’t work. It shows wrong values in debugger. The camera is working.