Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- using namespace cv;
- using namespace ofxCv;
- //--------------------------------------------------------------
- void ofApp::setup(){
- kinect.setRegistration(true);
- kinect.init();
- kinect.open();
- gui_depthThresh.setup("Kinect Depth","",0,kinect.height-100);
- gui_depthThresh.add(gui_nearThresh.setup("Near Thresh",335,0,1000));
- gui_depthThresh.add(gui_farThresh.setup("Far Thresh",185,0,1000));
- gui_threshold.setup("CV Threshold","",0,kinect.height);
- gui_threshold.add(gui_thresh.setup("thresh",40,0,500));
- gui_threshold.add(gui_max_area.setup("max_area",255,0,255));
- gui_distanceTransform.setup("CV Dist Trans","",kinect.width,kinect.height);
- gui_distanceTransform.add(gui_distance_type.setup("distance_type",3,0,10));
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- kinect.update();
- if(kinect.isFrameNew()){
- ofPixels & pix = kinect.getDepthPixels();
- int numPixels = pix.size();
- for(int i=0; i < numPixels; i++){
- if(pix[i] < gui_nearThresh && pix[i] > gui_farThresh){
- pix[i] = 255;
- }else{
- pix[i] = 0;
- }
- }
- }
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- Mat dist, bw;
- Mat src = toCv(kinect.getDepthPixels());
- //Can't seem to properly convert colors, which makes me think that the src mat is actually
- //already grayscale. Which makes sense, but I could definitely be wrong, I don't exactly know how to check.
- //cv::cvtColor(src, bw, CV_RGBA2GRAY);
- //threshold(src, bw, gui_thresh, gui_max_area, CV_THRESH_BINARY | CV_THRESH_OTSU);
- distanceTransform(src, dist, CV_DIST_L2, 3);
- normalize(dist, dist, 0, 1., NORM_MINMAX);
- drawMat(dist,0,0,400,300);
- drawMat(src,400,0,400,300);
- gui_threshold.draw();
- gui_distanceTransform.draw();
- gui_depthThresh.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::mouseEntered(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::mouseExited(int x, int y){
- }
- //--------------------------------------------------------------
- void ofApp::windowResized(int w, int h){
- }
- //--------------------------------------------------------------
- void ofApp::gotMessage(ofMessage msg){
- }
- //--------------------------------------------------------------
- void ofApp::dragEvent(ofDragInfo dragInfo){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement