4 of 6
4
OS X Multitouch? 
Posted: 27 May 2008 09:25 AM   [ Ignore ]   [ # 46 ]
New Member
Rank
Total Posts:  59
Joined  2007-07-09

I don’t mean to sound grouchy, or bossy or anything, I’m just suggesting that this thread is for objective-c discussions and it would be a real benefit to people looking for openframeworks stuff if all of this was on the appropriate thread.  Also I get overly excited when someone posts here showing interest in objective-c but it turns out to be c++.
Again I don’t want to offend or anything but for openframeworks/c++ stuff it would be for everyones benifit if it where posted here:

http://nuigroup.com/forums/viewforum/27/

Just a suggestion, don’t get upset. Os x is a must lets keep this alive.

ding

Profile
 
 
Posted: 27 May 2008 09:50 AM   [ Ignore ]   [ # 47 ]
New Member
Avatar
Rank
Total Posts:  38
Joined  2008-01-31

Iseba:
Can you post the header file as well? Also can you post both files as attachments so the tabbing and spacing is preserved. From the error message it sounds like some object is not getting handled properly, which is borking the memory when the object’s desctructor is getting called. As far as your event generation goes, you are on the right track. The Quartz Events Services API is what you want to be using to accomplish your goals.

Ding:
I agree. However I have hardly seen much Obj-C talk in any of these threads. Maybe a rename of this section is in order? Considering OS X does not have a solidified solution, maybe the admins should rename this section to something fitting OS X development as a whole. While Obj-C and Obj-C++ are the primary languages for OS X, a small percentage of the frameworks are still in C, and Obj-C is still not the most friendly language. It is understandable for people to get into the shallow end of the pool, C/C++, instead of jumping into the deep end.

To All OS X Developers Using OpenFramework:

I highly suggest using OpenFramework as a wrapper around Apple’s Sequence Grabber framework with extreme caution. The approach for managing the “frame grabbing” leaves open a vulnerability for a loss of frame data. If I am understanding OF’s code properly they are using a source other than the Sequence Grabber to handle the checking for updating of frames and handling of the new frames. This works, but it assumes that this “outside source” can process frames faster than the SG can dish out frames. In certain applications this approach would be fine, but considering our applications rely on the images for accuracy of input, one should be extremely cautious when using this framework. The SG framework has built in call back functions that developers can implement that will be called whenever a frame is brought in from the capture source.

Profile
 
 
Posted: 27 May 2008 12:05 PM   [ Ignore ]   [ # 48 ]
New Member
Rank
Total Posts:  11
Joined  2008-05-06

here goes my cpp and h files. ive changed a bit both of them. using CGEventCreateMouseEvent instead of CGPostMouseEvent but still having hangs

cpp:

#include "testApp.h"

#define SCROLL_AMT 10
void testApp::setup() {
    ofSetFrameRate
60 );
    
cwidth 320;
    
cheight 240;
    
threshold 60;
    
lowRange 0;
    
highRange 255;
    
mouseon=false;
    
screenw=ofGetScreenWidth();
    
screenh=ofGetScreenHeight();
    
bLearnBakground true;  
    
    
TUIOSocket.setupHOSTPORT ); // Set in Header  

    
vidGrabber.initGrabbercwidthcheight );
    
colorImg.allocatecwidthcheight );
    
grayImg.allocatecwidthcheight );
    
bgImg.allocatecwidthcheight );
    
    
blobTracker.setListenerthis );
    
alivecounter=0;
}



void testApp
::update() {
    ofBackground
100100100 );
    
vidGrabber.grabFrame();
    
    if( 
vidGrabber.isFrameNew() ) {
        colorImg 
vidGrabber.getPixels();
        
colorImg.mirrorfalsetrue );
        
grayImg colorImg;
     
        if( 
bLearnBakground {
            bgImg 
grayImg;
            
bLearnBakground false;
        
}    
        
//Create Image Level Range 0 - 255        
        
grayImg.convertToRange(lowRangehighRange);
        
grayImg.absDiffbgImg );
        
grayImg.blur11 );
        
grayImg.thresholdthreshold );

        
//findContures( img, minSize, maxSize, nMax, inner contours yes/no )
        
contourFinder.findContoursgrayImg50,180010false );
        
blobTracker.trackBlobscontourFinder.blobs );
    
}
    
}



void testApp
::draw() {
    ofSetColor
0xffffff );
    
     
colorImg.draw20,20 );
   
// grayImg.draw(340,20 );
    
    
blobTracker.draw20,20 );
    
string strhelp="[space] to learn background\n[1]/[2] to adjust threshold: "+ofToString(threshold2)+"\n[m] to toggle system mouse events:"+ofToString(mouseon)+"\n[9]/[0] to adj low level pass:"+ofToString(lowRange)+"\n[-]/[=] to adj high level pass:"+ofToString(highRange);
    
ofDrawBitmapStringstrhelp20,300 );   
       
    
ofxOscMessage m2;
    
m2.setAddress"/tuio/2Dcur" );        
    
m2.addStringArg"alive" );
    for (
int i 0blobTracker.blobs.size() ; i++){
  
//  ofCvTrackedBlob blob = blobTracker.getById( id );
        
ofxOscMessage m1;
        
m1.setAddress"/tuio/2Dcur" );
        
m1.addStringArg"set" );
        
m1.addIntArgblobTracker.blobs[i].id ); //id (id can't be == 0)
        
m1.addFloatArgblobTracker.blobs[i].center.x/360 ); //  x/camWidth
        
m1.addFloatArg(  blobTracker.blobs[i].center.y/240 ); // y/camHeight 
        
m1.addFloatArg(   blobTracker.blobs[i].deltaLoc.); //X
        
m1.addFloatArg(  blobTracker.blobs[i].deltaLoc.y  ); //Y
        
m1.addFloatArg(  blobTracker.blobs[i].area ); //m    
        
m1.addFloatArg(blobTracker.blobs[i].box.width ); //  wd
        
m1.addFloatArgblobTracker.blobs[i].box.height );// ht
        
TUIOSocket.sendMessagem1 );
        
        
m2.addIntArgblobTracker.blobs[i].id  ); //Get list of ALL active IDs        
        
    
}
    TUIOSocket
.sendMessagem2 );//send them
    
alivecounterblobTracker.blobs.size();
}


void testApp
::keyPressedint key {
   
    
switch (key){
        
case 'm':
            if( !
mouseon {
                mouseon 
true;
            
}else{
                mouseon
=false;
            
}
        
break;
        case 
'2':
            
threshold ++;
            if (
threshold 255threshold 255;
            break;        
        case 
'1':
            
threshold --;
            if (
threshold 10threshold 10;
            
//if (threshold < 0) threshold = 0;
            
break;
        case 
' ':
            
bLearnBakground true;
            break;    
        case 
'0':
            
lowRange ++;
            if (
lowRange 255lowRange 255;
            break;    
        case 
'9':
            
lowRange --;
            if (
lowRange 0lowRange 0;
            break;
        case 
'=':
            
highRange ++;
            if (
highRange 255highRange 255;
            break;    
        case 
'-':
            
highRange --;
            if (
highRange 0highRange 0;
            break;    
    
}
}
void testApp
::mouseMovedint xint y {}    
void testApp
::mouseDraggedint xint yint button {}
void testApp
::mousePressedint xint yint button {}
void testApp
::mouseReleased() {}

//--------------------------------------------------------------
void testApp::setmouse(float xfloat y,float dx,float dy,eventtype event ){
CGSize mainScreenSize 
CGDisplayScreenSize (CGMainDisplayID ());
//Boolean debug=1;
    
CGPoint pt;
    
CGPoint newloc;
    
CGEventRef eventRef=NULL;
    
pt.=x/360*screenw;
    
pt.y/240*screenh;
    
int xDelta=0yDelta=0;


                
                        switch(
event){
        
case EVENT_TYPE_MOUSE_MOVE://move
 
        //CGPostMouseEvent( pt, 1, 1, 0 );
        
break;
        
        case 
EVENT_TYPE_MOUSE_DOWN://press
        
eventRef=CGEventCreateMouseEvent (NULL,kCGEventLeftMouseDown,pt,0);
        
CGEventPost (kCGHIDEventTap,eventRef);
        
CFRelease(eventRef); 
        break;
        
        case 
EVENT_TYPE_MOUSE_UP://release
        
eventRef=CGEventCreateMouseEvent (NULL,kCGEventLeftMouseUp,pt,0);
        
CGEventPost (kCGHIDEventTap,eventRef);
        
CFRelease(eventRef); 
        break;
    
};
}

void testApp
::blobOn( const ofCvTrackedBlob{
int order
blobTracker.findOrder(b.id);
    if(
mouseon && alivecounter==&& order==){
    blobmouse
=b.id;
    
setmouse(blobTracker.getById(blobmouse).center.x,blobTracker.getById(blobmouse).center.y,blobTracker.getById(blobmouse).deltaLoc.x,blobTracker.getById(blobmouse).deltaLoc.y,EVENT_TYPE_MOUSE_DOWN );
     
cout << "blobOn() - id:" << b.id << " order:" << order << endl;

    
}

}    
void testApp
::blobMoved( const ofCvTrackedBlobb{
int order
blobTracker.findOrder(b.id);
  
   if( 
order==0){
      cout 
<< "blobMoved() - id:" << b.id << " order:" << order << endl;
    
//setmouse(blobTracker.getById(blobmouse).center.x,blobTracker.getById(blobmouse).center.y,blobTracker.getById(blobmouse).deltaLoc.x,blobTracker.getById(blobmouse).deltaLoc.y,EVENT_TYPE_MOUSE_MOVE );
    //cout << "blobMoved() - id:" << b.id << " order:" << order << endl;

    

   
}
void testApp
::blobOff( const ofCvTrackedBlob{
int order
blobTracker.findOrder(b.id);
  
//  
  
if(order==&& blobmouse== b.id){
    
    setmouse
(blobTracker.getById(blobmouse).center.x,blobTracker.getById(blobmouse).center.y,blobTracker.getById(blobmouse).deltaLoc.x,blobTracker.getById(blobmouse).deltaLoc.y,EVENT_TYPE_MOUSE_UP );
    
cout << "blobOff() - id:" << b.id << " order:" << order << endl;

    
}

}


void testApp
::blobAlivevector <int{

}

and h:

#include "ofMain.h"
#include "ofCvMain.h"
#include "ofxOsc.h"


#define HOST "localhost"
#define PORT 3333


class testApp : public ofSimpleApp, public ofCvBlobListener {

  
public:
  

    
int alivecounter;
    
int cwidth;
    
int cheight;
    
int screenw;
    
int screenh;
    
ofVideoGrabber  vidGrabber;
    
ofCvColorImage  colorImg;
    
ofCvGrayscaleImage  grayImg;
    
ofCvGrayscaleImage  bgImg;

    
ofCvContourFinder  contourFinder;
    
ofCvBlobTracker  blobTracker;
    
    
int threshold;
    
bool bLearnBakground;
    
bool mouseon;
    
int blobmouse;
    
int    lowRange;
    
int    highRange;
        
    
    
void setup();
    
void update();
    
void draw();

    
void keyPressedint key );
    
void mouseMovedint xint y );
    
void mouseDraggedint xint yint button );
    
void mousePressedint xint yint button );
    
void mouseReleased();
    
    
void blobOn(const ofCvTrackedBlobb);
    
void blobMoved( const ofCvTrackedBlobb);    
    
void blobOff( const ofCvTrackedBlob);  
    
void blobAlivevector <int);  
    
typedef enum
    {
        EVENT_TYPE_MOUSE_DOWN
,
        
EVENT_TYPE_MOUSE_UP,
        
EVENT_TYPE_MOUSE_MOVE,
        
EVENT_TYPE_MOUSE_SCROLL_MOVE,
        
EVENT_TYPE_KEY_DOWN,
        
EVENT_TYPE_KEY_UP
    } eventtype
;
    
void setmouse(float x,float y,float dx,float dy,eventtype event);
    
    
    
private:

        
ofxOscSender            TUIOSocket
        
};

Profile
 
 
Posted: 27 May 2008 12:55 PM   [ Ignore ]   [ # 49 ]
New Member
Rank
Total Posts:  11
Joined  2008-05-06

forgot to tell you that in the debugger console in xcode when blobOn func is called it works , but when blobOff, it hangs.

Profile
 
 
Posted: 27 May 2008 01:29 PM   [ Ignore ]   [ # 50 ]
New Member
Avatar
Rank
Total Posts:  38
Joined  2008-01-31

Here is a question, what is calling these functions?

Profile
 
 
Posted: 27 May 2008 01:55 PM   [ Ignore ]   [ # 51 ]
New Member
Rank
Total Posts:  11
Joined  2008-05-06

the functions are called by the blobTracker object every time a blob appears, moves or dissappear.  these fucns are collbacks from blobTraker events

// Delegate to Callbacks
//
//
void ofCvBlobTracker::doBlobOn( const ofCvTrackedBlob{
    
if( listener != NULL {
        listener
->blobOn);
    
else {
        cout 
<< "doBlobOn() event for blob: " << b.id << endl;
    
}
}    
void ofCvBlobTracker
::doBlobMoved( const ofCvTrackedBlob{
    
if( listener != NULL {
        listener
->blobMoved);
    
else {
        cout 
<< "doBlobMoved() event for blob: " << b.id << endl;
    
}
}
void ofCvBlobTracker
::doBlobOff( const ofCvTrackedBlob{
    
if( listener != NULL {
        listener
->blobOff();
    
else {
        cout 
<< "doBlobOff() event for blob: " << b.id << endl;
    
}
}
void ofCvBlobTracker
::doBlobAlive(  const vector<int>& {
    
if( listener != NULL {
        listener
->blobAlive();
    
else {
        cout 
<< "doBlobActive() event for blob: " << a.size() << endl;
    
}
}

Profile
 
 
Posted: 27 May 2008 01:57 PM   [ Ignore ]   [ # 52 ]
New Member
Rank
Total Posts:  11
Joined  2008-05-06

just wandering. could be that the point at wich the event is called is diferent betwen mouse down and mouse up?

Profile
 
 
Posted: 27 May 2008 02:03 PM   [ Ignore ]   [ # 53 ]
New Member
Avatar
Rank
Total Posts:  38
Joined  2008-01-31

My guess is that something somewhere is getting freed when it is not suppose to. All of your code seems fine to me. My guess is that object is getting freed and that function is accessing garbage memory space. I am sorry that is not much help. Try using Xcode’s debugger to back track where the crash is coming from. Even though you only see a bunch of assembly it should still display function names and other help information to help your narrow down the problem. If I get a chance I will slap this into an xcode project and try playing with it in the debugger. Once again I am not to fond of this framework and how it was put together. I am also not familiar with the inner workings of this framework. I am just looking at it as a general C++ programmer.

Profile
 
 
Posted: 27 May 2008 02:05 PM   [ Ignore ]   [ # 54 ]
New Member
Avatar
Rank
Total Posts:  38
Joined  2008-01-31

Let me clarify that a little more. I am guessing that this blobtracker has some sort of list of the blobs it found. My guess is that one of the blobs is being free and yet is still in the list or in other words the call back function is getting passed a bogus blob, so it freaks because it is accessing garbage memory.

Profile
 
 
Posted: 27 May 2008 02:06 PM   [ Ignore ]   [ # 55 ]
New Member
Rank
Total Posts:  11
Joined  2008-05-06

ok, ill try with the debbuger. thanks

Profile
 
 
Posted: 27 May 2008 02:20 PM   [ Ignore ]   [ # 56 ]
New Member
Rank
Total Posts:  11
Joined  2008-05-06

ive solveit. you were right. i was passing a reference of the blob beeing destroyed to a callback, but when passing parameters to the setmouse func, i was tring to get the values from the active blobs, and not from the reference. fixed that and now it works.
thank a lot

Profile
 
 
Posted: 27 May 2008 02:24 PM   [ Ignore ]   [ # 57 ]
New Member
Avatar