@Tiago_Morais_Morgado wrote:
greetings
i have created the following piece of code, using openframeworks addons examples.
#include <iostream> #include <stdlib.h> #include "ofMain.h" #include "ofxPd.h" #include "ofxSuperCollider.h" #include "ofxSCexit.h" #include "ofxGui.h" #include "ofxOpenCv.h" #include "ofxOsc.h" #include "ofxOscParameterSync.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void exit(); 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 windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxSCSynth *synth; ofxSCexit sc; ofVideoGrabber vidGrabber; ofxCvColorImage colorImg; ofxCvGrayscaleImage grayImage; ofxCvGrayscaleImage grayBg; ofxCvGrayscaleImage grayDiff; ofxCvContourFinder contourFinder; int threshold; bool bLearnBakground; ofxOscParameterSync sync; ofParameter<float> size; ofParameter<int> number; ofParameter<bool> check; ofParameterGroup parameters; ofParameter<ofColor> color; ofxPanel gui; }; void ofApp::setup(){ system("/Applications/of_v0.9.8_osx_release/apps/myApps/appGiovaniDemo/bin/run.sh"); ofSetLogLevel(OF_LOG_VERBOSE); int num =1; float notes[] = {1.0, 5.0/4.0, 4.0/3.0, 3.0/2.0}; float base[] = {1.0, 2.0, 4.0, 6.0, 8.0, 16.0}; float radius; float soundSpeed; float lfo; float phase; float movedDim; soundSpeed = notes[num%4] * base[num%6] * pow(1.5, 1.0+int(num/16.0)); synth = new ofxSCSynth("simple_sine"); synth->set("freq", soundSpeed * 50); synth->set("lfoFreq", lfo); synth->set("amp", 0); synth->create(); vidGrabber.setVerbose(true); vidGrabber.setup(320,240); colorImg.allocate(320,240); grayImage.allocate(320,240); grayBg.allocate(320,240); grayDiff.allocate(320,240); bLearnBakground = true; threshold = 80; parameters.setName("parameters"); parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100)); parameters.add(number.set("FPS",ofGetFrameRate(),0,100)); gui.setup(parameters); ofSetVerticalSync(true); } //-------------------------------------------------------------- void ofApp::update(){ ofBackground(100,100,100); bool bNewFrame = false; vidGrabber.update(); bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels()); grayImage = colorImg; if (bLearnBakground == true){ grayBg = grayImage; bLearnBakground = false; } grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); // find holes } gui.getParameter(); parameters.add(size.set("number of blobs",contourFinder.nBlobs,0,100)); parameters.add(number.set("FPS",ofGetFrameRate(),0,100)); int mod, index; mod = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x + 360, 0, ofGetWidth(), 20, 8000); index = ofMap(contourFinder.blobs[1].boundingRect.getCenter().y + 540, 0, ofGetHeight(), 1000, 0); synth->set("mod", mod); synth->set("index", index); } //-------------------------------------------------------------- void ofApp::draw(){ ofSetHexColor(0xffffff); colorImg.draw(20,20); grayImage.draw(360,20); grayBg.draw(20,280); grayDiff.draw(360,280); ofFill(); ofSetHexColor(0x333333); ofDrawRectangle(360,540,320,240); ofSetHexColor(0xffffff); for (int i = 0; i < contourFinder.nBlobs; i++){ contourFinder.blobs[i].draw(360,540); ofSetColor(255); if(contourFinder.blobs[i].hole){ ofDrawBitmapString("hole", contourFinder.blobs[i].boundingRect.getCenter().x + 360, contourFinder.blobs[i].boundingRect.getCenter().y + 540); } } ofSetHexColor(0xffffff); stringstream reportStr; reportStr << "bg subtraction and blob detection" << endl << "press ' ' to capture bg" << endl << "threshold " << threshold << " (press: +/-)" << endl << "num blobs found " << contourFinder.nBlobs << ", fps: " << ofGetFrameRate(); ofDrawBitmapString(reportStr.str(), 20, 600); gui.draw(); } //-------------------------------------------------------------- void ofApp::exit(){ synth->free(); sc.SCexit(); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ switch (key){ case ' ': bLearnBakground = true; break; case '+': threshold ++; if (threshold > 255) threshold = 255; break; case '-': threshold --; if (threshold < 0) threshold = 0; break; } } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } //======================================================================== int main( ){ ofSetupOpenGL(320,720,OF_WINDOW); ofRunApp(new ofApp()); }
I need to know:
how can I map the following piece of code to the first blob, as the whole thing turns out to crash when I point to something like:
int mod, index; mod = ofMap(contourFinder.blobs[1].boundingRect.getCenter().x + 360, 0, ofGetWidth(), 20, 8000); int mod, index; mod = ofMap(, 0, ofGetWidth(), 20, 8000); index = ofMap(, 0, ofGetHeight(), 1000, 0); synth->set("mod", mod); synth->set("index", index);
also, what is wrong with the supercollider thing, as it doesn't turn out to generate any sound. shall I add a synthdef to the boot.scd file in the ofxsupercollider-boot example. also, the examples of supercollider synthdefs seem to have disappeared in the GitHub repositories. hope you guys can fix that (or maybe should I address this in each of them)
Posts: 9
Participants: 1