Pixel sorting of a video


#1

Hi all. I am trying to sort the pixels of each frame of a BW video but I am having some problems.

This is the code that I have so far developed:
OFAPP.H:

#pragma once

#include “ofMain.h”

class ofApp : public ofBaseApp {

public:
void setup();
void update();
void draw();

void muestreoDibujo(ofImage);

ofImage image;
ofImage ordenada;
ofFbo fbo;

ofPixels pixels2;

ofVideoPlayer video;
ofColor rojoAct;

int posOrdenada;
int contGrises;

int fotograma;

};

OFAPP.CPP:

#include “ofApp.h”

void ofApp::setup() {
fotograma = 0;
video.load(“MOAB.mp4”);
fbo.allocate(512, 288);
ordenada.allocate(512, 288, OF_IMAGE_COLOR);

//inicia variables
rojoAct = 0, 0, 0;
posOrdenada = 0;
video.play();
video.setPaused(true);

}

void ofApp::update() {
video.update();
video.getPixels();

fbo.readToPixels(pixels2);

image.setFromPixels(pixels2);

image.update();
image.getPixels();

muestreoDibujo(image);

}

void ofApp::draw() {
ordenada.draw(0, 0, 512, 288);
fbo.begin();
video.draw(0,0,512,288);
fbo.end();

fbo.draw(ofGetWidth()/2,0, 512, 288);

}

void ofApp::muestreoDibujo(ofImage) {
//MUESTREO
for (int i = 0; i < (image.getWidth() * image.getHeight()); i++) {
ofColor color = image.getColor(i);
if (color.r == rojoAct.r) {
//DIBUJO
ordenada.setColor(posOrdenada, color);
posOrdenada++;
}
}
//GUARDAR IMAGEN
ordenada.update();
rojoAct.r++;
//rojoAct.g++;
//rojoAct.b++;

if (rojoAct.r == 255) {
	//ofSaveImage(ordenada, ofToString(fotograma) + ".jpg", OF_IMAGE_QUALITY_MEDIUM);
	ofSaveScreen(ofToString(fotograma) + ".jpg");
	rojoAct = 0;
	posOrdenada = 0;
	cout << ofToString(fotograma) << "GUARDADO" << endl;	
	//video.nextFrame();
	video.setFrame(fotograma);
	fotograma++;
	//deja la imagen negra
	for (int i = 0; i < (image.getWidth() * image.getHeight()); i++) {
		ordenada.setColor(i, ofColor(255, 255, 255));
	}

}

}

it is processing each frame of the video as an ofIamge but for some reason the resulting sorted image only contains a quarter of the pixel size it should have. Another problem is that the sorting works only until 254 gray level, so it doesn’t really calculate the number of 255 whites. If someone can help me with this I will apreciate very much. Any questions or concerns I will answer.