Created
May 24, 2015 09:56
-
-
Save tado/da1e555b4c8c79d6d32d to your computer and use it in GitHub Desktop.
ofxCv Contour Finder with ofxKinect
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" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
//画面設定 | |
ofSetFrameRate(60); | |
ofBackground(0); | |
// Kinect初期化 | |
kinect.init(); | |
kinect.open(); | |
// GUI初期設定 | |
gui.setup(); | |
gui.add(thresh.setup("Threshhold", 127, 0, 255)); | |
gui.add(minRadius.setup("Min Radius", 10, 0, 400)); | |
gui.add(maxRadius.setup("Max Radius", 200, 0, 400)); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
// CV設定 | |
contourFinder.setMinAreaRadius(minRadius); | |
contourFinder.setMaxAreaRadius(maxRadius); | |
// Kinect状態更新 | |
kinect.update(); | |
if (kinect.isFrameNew()) { | |
// Kinectの深度画像を、cv::Mat形式に変換 | |
cv::Mat mat = cv::Mat(kinect.height, kinect.width, CV_8UC1, kinect.getDepthPixels(), 0); | |
// ofxCvで輪郭抽出 | |
contourFinder.setThreshold(thresh); | |
contourFinder.findContours(mat); | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
// 深度画像描画 | |
ofSetColor(255); | |
kinect.drawDepth(0, 0, ofGetWidth(), ofGetHeight()); | |
// 輪郭抽出結果描画 | |
ofSetColor(255, 255, 0); | |
ofPushMatrix(); | |
ofScale(ofGetWidth() / float(kinect.width), ofGetHeight() / float(kinect.height)); | |
contourFinder.draw(); | |
ofPopMatrix(); | |
// GUI描画 | |
gui.draw(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
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){ | |
} |
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 "ofxKinect.h" | |
#include "ofxGui.h" | |
#include "ofxCv.h" | |
class ofApp : public ofBaseApp{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
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); | |
ofxKinect kinect; //Kinectインスタンス | |
ofImage kinectImage; // Kinectカメラ映像 | |
ofImage depthImage; // Kinect深度映像 | |
ofxCv::ContourFinder contourFinder; //CV輪郭抽出 | |
// GUI | |
ofxPanel gui; | |
ofxFloatSlider thresh; | |
ofxFloatSlider minRadius; | |
ofxFloatSlider maxRadius; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment