hi, im trying to take the video of the webcam and get the colors of all the pixels and change them to black and just stay the white color, for have some kind of figure of the body. But i have some problems, i think that is for the rgb, or something that im not counting.
the code:
ofApp.h:
#pragma once
#include “ofMain.h”
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
//void exit();
ofVideoGrabber webcam; //inicializo la camara q es la webcam
unsigned char* changeVideoData;
ofPixels pixelData;
ofTexture pixelTexture;
int camWidth, camHeight; //valores de ancho y alto de la camara.
};
ofApp.cpp:
#include “ofApp.h”
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0); //color fondo
camWidth = 640; //ancho de la cam
camHeight = 480; //alto de la cam
webcam.setVerbose(true);
webcam.setup(camWidth, camHeight); //inicializa la cam en con los parametros de camWidth y camHeight
changeVideoData = new unsigned char[camWidth * camHeight * 3];
pixelTexture.allocate(camWidth, camHeight, GL_RGB);
}
//--------------------------------------------------------------
void ofApp::update(){
webcam.update();
if (webcam.isFrameNew()) { //si la cam esta tomando los datos actuales
unsigned char* pixelData = webcam.getPixels().getData(); //toma pixeles de la imagen y la data
}
int totalPixels = camWidth * camHeight * 3; //total de pixeles de la camara + rgb
for (int i = 0; i < totalPixels; i+= 3) {
if (changeVideoData[i] == 250 ) changeVideoData[i] = 255;
else changeVideoData[i] = 0;
}
pixelTexture.loadData(changeVideoData, camWidth, camHeight, GL_RGB);
}
//--------------------------------------------------------------
void ofApp::draw(){
//webcam.draw(0,0,1393 ,710); //dibuja la cam
pixelTexture.draw(0,0,1360,730);
}