Hi underdog , here is the code.
if you have the variable “number_of_windows” set to 0 the program works fine. But when i try to have more windows the app crashes or i get empty screens.
please try the “number_of_windows = 0 ;” and then “number_of_windows = 1;” and you will notice the problem
any idea why is not working ofxFenster with camera input?
#include "ofMain.h"
#include "testApp.h"
#include "ofxFensterManager.h"
#include "ofAppGlutWindow.h"
//========================================================================
int main( ){
ofSetupOpenGL(ofxFensterManager::get(), 1024,768, OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunFensterApp(new testApp());
}
#include "testApp.h"
ofColor aColor;
ofColor c;
// for demonstrating adding any drawable object (that extends ofBaseDraw);
ofVideoGrabber vidGrabber;
unsigned char * videoInverted;
ofTexture videoTexture;
int number_of_windows = 2;
bool randomizeButton = true;
ofPoint *points;
ofPoint v[300];
int movieIndex = 0;
//--------------------------------------------------------------
void testApp::setup()
{
ofSetFrameRate(60);
videoIn.setDeviceID(2);
switch_gui = 0;
switch_track_color = 0;
switch_fondo = 0;
ofBackground(0, 0, 0);
ofSetVerticalSync(true);
////////
//ofEnableAlphaBlending();
camWidth = 1024;
camHeight = 768;
humbral = 165;
hCycle = 50;
vFlip = false;
hFlip = true;
red = 250;
green = 0;
blue = 0;
counter = 0;
ofSetWindowShape(camWidth, camHeight);
videoIn.setVerbose(true);
videoIn.initGrabber(camWidth,camHeight, GL_RGB);
entrada.allocate(camWidth,camHeight);
filtro.allocate(camWidth,camHeight);
film.allocate(camWidth, camHeight);
temporal.allocate(camWidth, camHeight);
bDrawDiagnostic = false;
//colorImg.allocate(camWidth,camHeight);
grayImage.allocate(1024,768);
grayBg.allocate(1024,768);
grayDiff.allocate(1024,768);
bLearnBakground = true;
threshold = 80;
graba = 0;
switcher = 0;
int winW=1024;
for(int i=0; i<number_of_windows; i++) {
ofxFenster* win=ofxFensterManager::get()->createFenster(800+(i*winW), 0, winW, 768, OF_WINDOW);
win->addListener(new testApp());
win->setBackgroundColor(ofRandom(255), ofRandom(0), ofRandom(255));
}
//setup of fensterListener does not get called automatically yet
imgWin.setup();
}
//--------------------------------------------------------------
void testApp::update()
{
videoIn.grabFrame();
if (videoIn.isFrameNew()){
entrada.setFromPixels(videoIn.getPixels(),camWidth,camHeight);
filtro = entrada;
updateFilm(filtro.getPixels());
}
bool bNewFrame = false;
#ifdef _USE_LIVE_VIDEO
//cambiar videoIn por vidGrabber
// videoIn.grabFrame();
bNewFrame = videoIn.isFrameNew();
//#else
// vidPlayer.idleMovie();
// bNewFrame = vidPlayer.isFrameNew();
#endif
if (bNewFrame){
#ifdef _USE_LIVE_VIDEO
//entrada
entrada.setFromPixels(videoIn.getPixels(), 1024,768);
#endif
grayImage = entrada;
if (bLearnBakground == true){
grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
bLearnBakground = false;
}
}
}
void testApp::cleanFilm(){
unsigned char * filmPixels = temporal.getPixels();
int lenght = camWidth * camHeight * 3;
for( int i=0; i < lenght; i++ ) filmPixels[i] = 0;
temporal.setFromPixels( filmPixels, camWidth, camHeight );
}
void testApp::updateFilm(unsigned char *mskPixels){
unsigned char * filmPixels = temporal.getPixels();
int lenght = camWidth * camHeight * 3;
temporal.setFromPixels( filmPixels, camWidth, camHeight );
}
//--------------------------------------------------------------
void testApp::draw()
{
entrada.draw(0,0,ofGetWidth(),ofGetHeight());
}
//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
if(key == 'c')
cout << "CLIPBOARD DATA: " << ofxFensterManager::get()->getClipboard() << endl;
}
//--------------------------------------------------------------
void testApp::keyReleased(int key, ofxFenster* win)
{
//cout << (0x0400) << endl;
//cout << (101 | OF_KEY_MODIFIER) << " " << key << endl;
if(key=='f')
win->toggleFullscreen();
if(key==' ')
ofxFensterManager::get()->createFenster(0, 0, 400, 300, OF_WINDOW)->addListener(&imgWin);
//Esto de abajo lo uso para cambiar entre camaras.
//funciona bien pero porque no lo puedo hacer con el gui en vez de con key?
if (key=='o') switcher = switcher + 1;
//este if le he agregado para poder grabar un archivo nuevo en vez de sobreescribir. funciona bien
switcher = switcher % 2;
if (key=='g') switch_gui = switch_gui + 1;
switch_gui = switch_gui % 2;
}
//this only works if testApp is extending ofxFensterListener and not ofBaseApp
void testApp::mouseMoved(int x, int y, ofxFenster* win)
{
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y)
{
mousePos.set(x, y);
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h)
{
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg)
{
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo)
{
cout << "GOT SOME FILES: "<<endl;
std::vector<string>::iterator it = dragInfo.files.begin();
while(it != dragInfo.files.end()){
cout << *it << endl;
++it;
}
}
void testApp::mouseMovedEvent(ofMouseEventArgs &args)
{
//cout << "MOUSE WAS MOVED" << endl;
}
#pragma once
#include "ofMain.h"
#include "ofxFensterManager.h"
#include "ofxOpenCv.h"
class imageWindow: public ofxFensterListener {
public:
~imageWindow() {
cout << "Image Listener destroyed" << endl;
}
void setup() {
cout << "LOADING IMAGE" << endl;
img.loadImage("someImage.JPG");
}
void draw() {
img.draw(0,0);
}
void keyReleased(int key, ofxFenster* window) {
if(key==' ')
ofxFensterManager::get()->deleteFenster(window);
}
ofImage img;
};
class boxWindow: public ofxFensterListener {
public:
boxWindow() {
rotX = ofRandom(-20, 20);
rotY = ofRandom(-10, 10);
}
void draw() {
ofNoFill();
ofTranslate(ofGetWidth()*.5, ofGetHeight()*.5, 0);
ofRotateX(rotX);
ofRotateY(rotY);
ofBox(0, 0, 0, 100);
}
void mouseMoved(int x, int y) {
rotY = ofMap(x, 0, ofGetWidth(), -20, 20);
rotX = ofMap(y, 0, ofGetHeight(), 60, -60);
}
void dragEvent(ofDragInfo dragInfo) {
cout << "GOT SOME FILES: "<<endl;
std::vector<string>::iterator it = dragInfo.files.begin();
while(it != dragInfo.files.end()) {
cout << *it << endl;
++it;
}
}
float rotX;
float rotY;
};
class testApp : public ofxFensterListener {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key, ofxFenster* win);
void mouseMoved(int x, int y );
void mouseMoved(int x, int y, ofxFenster* win);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
void mouseMovedEvent(ofMouseEventArgs &args);
ofVec2f mousePos;
imageWindow imgWin;
ofxFenster* test;
int iconCount;
ofVideoGrabber videoIn;
ofxCvColorImage entrada;
ofxCvGrayscaleImage filtro;
ofxCvColorImage temporal;
ofxCvColorImage film;
int camWidth, camHeight;
int humbral;
bool vFlip, hFlip;
int counter;
int red;
int green;
int blue ;
float hCycle;
ofColor color;
// ofColor c;
ofImage img;
ofPoint firstpoint;
//ofxQtVideoSaver saver;
int graba ;
int switcher;
bool bDrawDiagnostic;
//#ifdef _USE_LIVE_VIDEO
// ofVideoGrabber vidGrabber;
//#else
// ofVideoPlayer vidPlayer;
//#endif
ofxCvColorImage colorImg;
ofxCvGrayscaleImage grayImage;
ofxCvGrayscaleImage grayBg;
ofxCvGrayscaleImage grayDiff;
ofxCvContourFinder contourFinder;
int threshold;
bool bLearnBakground;
int switch_gui ; // esto es para hacer aparecer y desaparecer el gui
int switch_track_color ; // esto es para hacer rastree el color y lo aplique al trail o no
int switch_fondo ; // esto es para prender y apagar el findo
void cleanFilm();
void updateFilm(unsigned char *pixels);
void superFastBlur(unsigned char *pix, int w, int h, int radius);
void changeCamera (int key);
};