Compare ofPixels are equal

So I am hoping there is a way to check to see if a set of pixels have changed. I am sending 910 pixels over TCP. I would like to only send if the pixels have changed. I am getting the pixels from an ofFBO object. I was hoping something like:
this->sendPx is the newest set, px is the last frames set.

 if(strcmp (this->sendPx.getData(),this->px.getData()) != 0){
     this->px = this->sendPx;

This fails though. Are there any quick ways to check if one set of ofPixels is not equal to the last set of ofPixels?

Hi, there is a “not equal” operator implemented for Pixel, so the first solution which comes to mind is comparing all the Pixel of an ofPixels in a for loop.

Best, Felix

get the memory address of the specific pixels you want to compare, dump them to strings, get an algorithm for implementing some sort of feature extraction out of the content of the variable and then make some conditions to compare both things. i know that this sounds more like middle ware/low ware approach. but this can work as well

So even though it isn’t what I was hoping for, a single comparison method of the raw byte data, @fxlange method didn’t slow the program down more than a couple ms, I am still running at 60 fps. Before I send the pixels to the threads I check to see if it is a new frame. That way the APA102C pixels don’t blink at all due to constant updating.

The function I call is:

bool ofApp::pxCmp(ofPixels latest, ofPixels last){
    for(int i = 0; i<latest.getTotalBytes()/latest.getNumChannels(); i++){
        if(latest.getColor(i) != last.getColor(i)){
            return true;
    return false;

The call is made before updating the threads.

if((isNewFrame = pxCmp(px,lastPx))){
    lastPx.operator =(px);
for(unsigned int i = 1; i < sizeof(structure)/sizeof(structure[0]); i++ ){ //sizeof(structure)/sizeof(structure[0])
        dataHandler[i].isNewFrame = isNewFrame;
            dataHandler[i].px.operator =( px );
1 Like

i think this can work. and i will grab the code for myself :wink:

1 Like :wink:

1 Like

I added an extension to ofPixels named ofPixelsExtended that adds this compare functionality as well as a getTotalPixels functionality. I plan to add more to it as I go along, but thats it for now.