Skip to content

Instantly share code, notes, and snippets.

@tado
Created June 1, 2015 16:25
Show Gist options
  • Save tado/be55310de1fd98ed7945 to your computer and use it in GitHub Desktop.
Save tado/be55310de1fd98ed7945 to your computer and use it in GitHub Desktop.
ofxCv CounourFinder get center points
#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);
}
}
#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