Get RGB values of video frame's pixels

Hi all ! I’ve found several post on the forum, and some code in the OF examples but I’m still not sure if I’m doing things the right way…

I need to get the RGB values of each pixel of a video frame (Raspberry ofOmxPlayer)
I read them (on purpose) from the bottom to the top of each col, and proceed cols left to the right

The video is RGB (and not RGBA) and very small on (32x32 pixels), and I draw circles on screen just to check if I have retrieved the right values. So far, the frames drawn with circles doesn’t look likes the video frames content at all…

    v_width = omxPlayer.getWidth();
    v_height = omxPlayer.getHeight();
    int bpp = 3;
        for (int col = 0; col < v_width; col++) {
            for (int row = v_height - 1; row >= 0; row--) {
                base = (row * v_width + col) * bpp;
                unsigned char cRed = pixels[base];
                unsigned char cGreen = pixels[base + 1];
                unsigned char cBlue = pixels[base + 2];
                ofSetColor(cRed, cGreen, cBlue);
                ofCircle((col + 10) * 30, (row + 1) * 30, 5);
            }
        }

Is there anything wrong with these lines of code ?

Thanks for your help !

any particular reason you are looping through the rows backwards? That would make them also in reverse when you draw them

Yes, I translate them to Ola’s DMX buffers… Due to the hardware lights arrangement it’s easier to me to handle the rows/cols that way

Do you see something wrong in

base = (row * v_width + col) * bpp;
unsigned char cRed = pixels[base];

Because, even reversed the circles does not reflect the video content, at all ! The test video (32x32 pixels) is a simple expanding shape, I don’t get nothing looking the same when drawn on screen…

I though it could be caused by the way I compute the indice to access the ofOmxPlayer pixels.
BTW, I get the pixels like this

void ofApp::update() {
    omxPlayer.updatePixels();
    pixels = omxPlayer.getPixels();
}

Seems ok to me

Have you tried playing your movie in example-pixels? 32x32 is kind of a weird size so wondering if it has something to do with that

1 Like

Thanks ! Good idea, I’ll try with a ‘normal’ sized video stream…

1 Like