Created
June 1, 2015 16:25
-
-
Save tado/be55310de1fd98ed7945 to your computer and use it in GitHub Desktop.
ofxCv CounourFinder get center points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
using namespace ofxCv; | |
using namespace cv; | |
void ofApp::setup() { | |
cam.initGrabber(ofGetWidth(), ofGetHeight()); | |
contourFinder.setMinAreaRadius(10); | |
contourFinder.setMaxAreaRadius(200); | |
} | |
void ofApp::update() { | |
cam.update(); | |
if(cam.isFrameNew()) { | |
contourFinder.setThreshold(ofMap(mouseX, 0, ofGetWidth(), 0, 255)); | |
contourFinder.findContours(cam); | |
} | |
} | |
void ofApp::draw() { | |
ofSetColor(255); | |
cam.draw(0, 0); | |
contourFinder.draw(); | |
// 検出された輪郭線の数だけくりかえし | |
for (int i = 0; i < contourFinder.size(); i++) { | |
// 中心点抽出 | |
cv::Point2f pos = contourFinder.getCenter(i); | |
// 円を描画 | |
ofSetColor(255, 0, 0); | |
ofCircle(pos.x, pos.y, 5); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
#include "ofxCv.h" | |
class ofApp : public ofBaseApp { | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber cam; | |
ofxCv::ContourFinder contourFinder; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment