still trying to send events to osx.
i ve some progress. ive managed to send events to system. move the cursos and press and release button. but when i exit the app i get this error code that worries me:
“openFrameworks(1283,0xa0695fa0) malloc: *** error for object 0xbffff0e0: Non-aligned pointer being freed (2)
*** set a breakpoint in malloc_error_break to debug
The Debugger has exited with status 0.”
here is my code
#include “testApp.h”
void testApp::setup() {
ofSetFrameRate( 60 );
cwidth = 320;
cheight = 240;
threshold = 60;
mouseon=false;
bLearnBakground = true;
TUIOSocket.setup( HOST, PORT ); // Set in Header
vidGrabber.initGrabber( cwidth, cheight );
colorImg.allocate( cwidth, cheight );
grayImg.allocate( cwidth, cheight );
bgImg.allocate( cwidth, cheight );
blobTracker.setListener( this );
alivecounter=0;
}
void testApp::update() {
ofBackground( 100, 100, 100 );
vidGrabber.grabFrame();
if( vidGrabber.isFrameNew() ) {
colorImg = vidGrabber.getPixels();
colorImg.mirror( false, true );
grayImg = colorImg;
if( bLearnBakground ) {
bgImg = grayImg;
bLearnBakground = false;
}
grayImg.absDiff( bgImg );
grayImg.blur( 11 );
grayImg.threshold( threshold );
//findContures( img, minSize, maxSize, nMax, inner contours yes/no )
contourFinder.findContours( grayImg, 10,20000, 10, false );
blobTracker.trackBlobs( contourFinder.blobs );
}
}
void testApp::draw() {
ofSetColor( 0xffffff );
colorImg.draw( 20,20 );
// grayImg.draw( 360,200 );
blobTracker.draw( 20,20 );
string strhelp="[space] to learn background\n[+]/[-] to adjust threshold: "
+ ofToString(threshold, 2)
+" \n[m] to toggle system mouse events:"
+ofToString(mouseon);
ofDrawBitmapString( strhelp, 20,300 );
ofxOscMessage m2;
m2.setAddress( “/tuio/2Dcur” );
m2.addStringArg( “alive” );
for (int i = 0; i < blobTracker.blobs.size() ; i++){
// ofCvTrackedBlob blob = blobTracker.getById( id );
ofxOscMessage m1;
m1.setAddress( "/tuio/2Dcur" );
m1.addStringArg( "set" );
m1.addIntArg( blobTracker.blobs.id ); //id (id can’t be == 0)
m1.addFloatArg( blobTracker.blobs.center.x/360 ); // x/camWidth
m1.addFloatArg( blobTracker.blobs.center.y/240 ); // y/camHeight
m1.addFloatArg( blobTracker.blobs.deltaLoc.x ); //X
m1.addFloatArg( blobTracker.blobs.deltaLoc.y ); //Y
m1.addFloatArg( blobTracker.blobs.area ); //m
m1.addFloatArg(blobTracker.blobs.box.width ); // wd
m1.addFloatArg( blobTracker.blobs.box.height );// ht
TUIOSocket.sendMessage( m1 );
m2.addIntArg( blobTracker.blobs.id ); //Get list of ALL active IDs
}
TUIOSocket.sendMessage( m2 );//send them
alivecounter= blobTracker.blobs.size();
}
void testApp::keyPressed( int key ) {
if( key == ‘ ‘ ) {
bLearnBakground = true;
} else if( key == ‘-’ ) {
threshold = MAX( 0, threshold-1 );
} else if( key == ‘+’ || key == ‘=’ ) {
threshold = MIN( 255, threshold+1 );
}else if( key == ‘m’ && !mouseon ) {
mouseon = true;
}else{
mouseon=false;
}
}
void testApp::mouseMoved( int x, int y ) {}
void testApp::mouseDragged( int x, int y, int button ) {}
void testApp::mousePressed( int x, int y, int button ) {}
void testApp::mouseReleased() {}
//--------------------------------------------------------------
void testApp::setmouse(float x, float y,int event ){
CGPoint pt;
pt.x =x;
pt.y = y;
switch(event){
case 1://move
CGPostMouseEvent( pt, 1, 1, 0 );
break;
case 2://press
CGPostMouseEvent( pt, 1, 1, 1 );
break;
case 3://release
CGPostMouseEvent( pt, 1, 1, 0 );
break;
};
}
void testApp::blobOn( int x, int y, int id, int order ) {
if(mouseon && alivecounter==0 && order==0 ){
blobmouse=id;
setmouse(blobTracker.blobs[order].center.x, blobTracker.blobs[order].center.y,2 );
cout << "blobOn() - id:" << id << " order:" << order << endl;
}
}
void testApp::blobMoved( int x, int y, int id, int order) {
// cout << "blobMoved() - id:" << id << " order:" << order << endl;
}
void testApp::blobOff( int x, int y, int id, int order ) {
//
if( blobmouse==id){
setmouse(blobTracker.blobs[order].center.x, blobTracker.blobs[order].center.y,3 );
cout << "blobOff() - id:" << id << " order:" << order << endl;
}
}
void testApp::blobAlive( vector a ) {
}