ofxUI and ofxOpenCv

HI! i’m making an app that count dots, using blob detection.
I want to trigger this event contourFinder.findContours(grayImage, 1, 150, 400, true); when i touch the button of the ofxUI. I try it a lot but no results! any help!?

What exact problem do you have?
Can you show us the code?

Please look at

first “if”-statement inside void ofApp::guiEvent(ofxUIEventArgs &e) is what you probably need

Hi! sure but how i declared to B1 im using two buttons. Thanks a lor for helping!
#include “testApp.h”

//--------------------------------------------------------------
void testApp::setup(){
// ofSetOrientation(OF_ORIENTATION_90_RIGHT);//Set iOS to Orientation Landscape Right

ofSetVerticalSync(true);
ofEnableSmoothing();
drawPadding = false;
gui = new ofxUICanvas();

capW = 320;
capH = 240;

#ifdef _USE_LIVE_VIDEO
	vidGrabber.initGrabber(capW, capH);
	capW = vidGrabber.getWidth();
		capH = vidGrabber.getHeight();
#else
  	  vidPlayer.loadMovie("fingers.m4v");
    	vidPlayer.setLoopState(OF_LOOP_NORMAL);
		vidPlayer.play();
#endif

	colorImg.allocate(capW,capH);
grayImage.allocate(capW,capH);
 grayBg.allocate(capW,capH);
	grayDiff.allocate(capW,capH);

	bLearnBakground = true;
threshold = 80;

ofSetFrameRate(20);

//User-Interface

gui->addButton("B1", false, 44, 44);
gui->addButton("B2", false, 44, 44);
gui->setGlobalButtonDimension(24);
gui->addSpacer();

}

//--------------------------------------------------------------
void testApp::update(){
ofBackground(100,100,100);

	bool bNewFrame = false;

	#ifdef _USE_LIVE_VIDEO
  	 vidGrabber.update();
    bNewFrame = vidGrabber.isFrameNew();
	#else
    	vidPlayer.update();
  	  bNewFrame = vidPlayer.isFrameNew();
	#endif



	if (bNewFrame){


		#ifdef _USE_LIVE_VIDEO
			if( vidGrabber.getPixels() != NULL ){
		#else
			if( vidPlayer.getPixels() != NULL && vidPlayer.getWidth() > 0 ){

#endif
#ifdef _USE_LIVE_VIDEO
colorImg.setFromPixels(vidGrabber.getPixels(), capW, capH);
#else
colorImg.setFromPixels(vidPlayer.getPixels(), capW, capH);
#endif

		grayImage = colorImg;
			if (bLearnBakground == true){
				grayBg = grayImage;		// the = sign copys the pixels from grayImage into grayBg (operator overloading)
				bLearnBakground = false;
			}

			// take the abs value of the difference between background and incoming and then threshold:
			grayDiff.absDiff(grayBg, grayImage);
			grayDiff.threshold(threshold);

		 //find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
		// also, find holes is set to true so we will get interior contours as well....
			// find holes
	
	}
	}

}
//--------------------------------------------------------------
void testApp::draw(){

ofSetColor(255);
ofDrawBitmapString(ofToString(ofGetFrameRate()), 20, 20);

ofPushMatrix();
ofScale(0.5, 0.5, 1);

// draw the incoming, the grayscale, the bg and the thresholded difference
ofSetHexColor(0xffffff);
grayImage.draw(0,0);
grayBg.draw(capW+4, 0);
grayDiff.draw(0, capH + 4);

// lets draw the contours. 
// this is how to get access to them:
for (int i = 0; i < contourFinder.nBlobs; i++){
    contourFinder.blobs[i].draw(0, capH + 4);
}

ofPopMatrix();
// finally, a report:

ofSetHexColor(0xfffff);
char reportStr[1024];
sprintf(reportStr, "MicroTracerIOS 1.0 ' ' threshold %i\nnum dots found %i", threshold, contourFinder.nBlobs );
ofDrawBitmapString(reportStr, 0, 30);

//user-interface

}

void testApp::guiEvent(ofxUIEventArgs &e)
{
    string name = e.widget->getName();
    int kind = e.widget->getKind();
    
    if(kind == OFX_UI_WIDGET_BUTTON)
    {
        ofxUIButton *button = (ofxUIButton *) e.widget;
        cout << name << "\t value: " << button->getValue() << endl;
        
    }
    else if(kind == OFX_UI_WIDGET_TOGGLE)
    {
        ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
        cout << name << "\t value: " << toggle->getValue() << endl;
    }
    else if(kind == OFX_UI_WIDGET_IMAGEBUTTON)
    {
        ofxUIImageButton *button = (ofxUIImageButton *) e.widget;
        cout << name << "\t value: " << button->getValue() << endl;
    }
    else if(kind == OFX_UI_WIDGET_IMAGETOGGLE)
    {
        ofxUIImageToggle *toggle = (ofxUIImageToggle *) e.widget;
        cout << name << "\t value: " << toggle->getValue() << endl;
    }
    else if(kind == OFX_UI_WIDGET_LABELBUTTON)
    {
        ofxUILabelButton *button = (ofxUILabelButton *) e.widget;
        cout << name << "\t value: " << button->getValue() << endl;
    }
    else if(kind == OFX_UI_WIDGET_LABELTOGGLE)
    {
        ofxUILabelToggle *toggle = (ofxUILabelToggle *) e.widget;
        cout << name << "\t value: " << toggle->getValue() << endl;
    }
    else if(name == "B1")
    {
       // ofxUIButton *button = (ofxUIButton *) e.widget;
        //cout << "value: " << button->getValue() << endl;
         contourFinder.findContours(grayImage, 1, 150, 400, true);
    }
    else if(name == "B2")
    {
        //ofxUIButton *button = (ofxUIButton *) e.widget;
       // cout << "value: " << button->getValue() << endl;
        	bLearnBakground = true;
    }
    else if(name == "T1")
    {
        ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
        cout << "value: " << toggle->getValue() << endl;
    }
    else if(name == "T2")
    {
        ofxUIToggle *toggle = (ofxUIToggle *) e.widget; 
        cout << "value: " << toggle->getValue() << endl;     
    }
}

//--------------------------------------------------------------
void testApp::exit(){

}

//--------------------------------------------------------------
void testApp::deviceOrientationChanged(int newOrientation){

}

So what doesn’t work?
Can you provide us with link to the code (github repository or zip archive)?

At first sight I see logic error here.

if(kind == OFX_UI_WIDGET_BUTTON) {
...
} else if(name == "B1") {
...
}

Here if(name == “B1”) won’t run because all buttons will be catched by “kind” branch. You need to remove else-keyword, so your code will be structured like this

if(kind == ...) { // debug code from example above
...
} else if (kind == ...) {
...
}

// second if-else here

if (name == ...) {
...
} else if (name == ...) {
...
}

Allright ! i will try that here is the link! https://github.com/jorgeavila/dotCountingIos.git
I have like 1 year programming! but i’m new at OF! thanks

dude! i’m getting this error [ error ] ofTrueTypeFont: drawString(): font not allocated: line 1077 in /Users/jorge/Documents/of_v0.8.0_ios_release/libs/openFrameworks/graphics/ofTrueTypeFont.cpp
i try to fixed but nothing!