I’m working with Nico on this problem, and I think I have kind of isolated where the problem comes from.
Actually it has nothing to do with libraries or dlls. OpenCV 2.0 comes with precompiled libraries for MinGW on windows that are perfectly working. Also I’m pretty sure the version of ofxOpencv coming with 0.6 is 100% compatible with OpenCV 2.0 …
I’ve made some test and it seems that the problem comes from how OF is handling the main loop but I have no idea why it is doing that and how to solve it!
Here’s some code to illustrate what’s working and what is not:
testApp.h :
#ifndef _TEST_APP
#define _TEST_APP
#include "cv.h"
#include "highgui.h"
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
testApp();
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
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 resized(int w, int h);
IplImage* pImg;
IplImage* gray;
};
#endif
testApp.cpp :
#include "testApp.h"
#include "stdio.h"
//--------------------------------------------------------------
void testApp::setup(){
gray = cvCreateImage( cvSize(512,512), IPL_DEPTH_8U, 1 );
if((pImg = cvLoadImage("lena.jpg", 1)) != 0){
cvNamedWindow( "Image", 1 );
cvNamedWindow( "Image2", 1 );
cvCvtColor( pImg, gray, CV_RGB2GRAY );
cvThreshold( gray, gray, 40, 255, CV_THRESH_BINARY_INV );
cvShowImage( "Image", pImg );
cvShowImage( "Image2", gray );
}
}
//--------------------------------------------------------------
void testApp::update(){
// cvCvtColor( pImg, gray, CV_RGB2GRAY );
// cvThreshold( gray, gray, 40, 255, CV_THRESH_BINARY_INV );
}
//--------------------------------------------------------------
void testApp::draw(){
// cvCvtColor( pImg, gray, CV_RGB2GRAY ); // doesn't work
// cvThreshold( gray, gray, 40, 255, CV_THRESH_BINARY_INV ); // doesn't work
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
cvCvtColor( pImg, gray, CV_RGB2GRAY );
cvThreshold( gray, gray, mouseX, 255, CV_THRESH_BINARY_INV );
cvShowImage( "Image", pImg );
cvShowImage( "Image2", gray );
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
cvCvtColor( pImg, gray, CV_RGB2GRAY );
cvThreshold( gray, gray, mouseX, 255, CV_THRESH_BINARY_INV );
cvShowImage( "Image", pImg );
cvShowImage( "Image2", gray );
}
All the uncommented code is working perfectly but the commented code you can see inside testApp::update() makes the application crash without any message. At first I thought that something was happening after the setup that blocks any opencv calls but then I discovered that you could execute the same code inside mousePressed and keyPressed without any problem.
All this make me thing that there is a problem maybe on how ofAppGlutWindow is calling the update and draw methods, maybe something to do with the appPtr, or even with glutMainLoop() … this is really weird! I don’t understand! I can’t find any leads on google and it seems that nobody is talking about the same problem … so I’m kind of stuck here, without any clue!
Any help or suggestions would really save us!
(Also I would love to hear is there is any reason to stay with the old version of OpenCV? I searched the forum about that but I did not find anything)