Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.26 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. using namespace cv;
  4. using namespace ofxCv;
  5.  
  6. //--------------------------------------------------------------
  7. void ofApp::setup(){
  8.     kinect.setRegistration(true);
  9.     kinect.init();
  10.     kinect.open();
  11.    
  12.     gui_depthThresh.setup("Kinect Depth","",0,kinect.height-100);
  13.     gui_depthThresh.add(gui_nearThresh.setup("Near Thresh",335,0,1000));
  14.     gui_depthThresh.add(gui_farThresh.setup("Far Thresh",185,0,1000));
  15.    
  16.     gui_threshold.setup("CV Threshold","",0,kinect.height);
  17.     gui_threshold.add(gui_thresh.setup("thresh",40,0,500));
  18.     gui_threshold.add(gui_max_area.setup("max_area",255,0,255));
  19.    
  20.     gui_distanceTransform.setup("CV Dist Trans","",kinect.width,kinect.height);
  21.     gui_distanceTransform.add(gui_distance_type.setup("distance_type",3,0,10));
  22. }
  23.  
  24. //--------------------------------------------------------------
  25. void ofApp::update(){
  26.     kinect.update();
  27.  
  28.     if(kinect.isFrameNew()){
  29.         ofPixels & pix = kinect.getDepthPixels();
  30.         int numPixels = pix.size();
  31.        
  32.         for(int i=0; i < numPixels; i++){
  33.             if(pix[i] < gui_nearThresh && pix[i] > gui_farThresh){
  34.                 pix[i] = 255;
  35.             }else{
  36.                 pix[i] = 0;
  37.             }
  38.         }
  39.     }
  40. }
  41.  
  42. //--------------------------------------------------------------
  43. void ofApp::draw(){
  44.    
  45.     Mat dist, bw;
  46.     Mat src = toCv(kinect.getDepthPixels());
  47.  
  48.     //Can't seem to properly convert colors, which makes me think that the src mat is actually
  49.     //already grayscale. Which makes sense, but I could definitely be wrong, I don't exactly know how to check.
  50.     //cv::cvtColor(src, bw, CV_RGBA2GRAY);
  51.     //threshold(src, bw, gui_thresh, gui_max_area, CV_THRESH_BINARY | CV_THRESH_OTSU);
  52.     distanceTransform(src, dist, CV_DIST_L2, 3);
  53.     normalize(dist, dist, 0, 1., NORM_MINMAX);
  54.    
  55.     drawMat(dist,0,0,400,300);
  56.     drawMat(src,400,0,400,300);
  57.    
  58.     gui_threshold.draw();
  59.     gui_distanceTransform.draw();
  60.     gui_depthThresh.draw();
  61. }
  62.  
  63. //--------------------------------------------------------------
  64. void ofApp::keyPressed(int key){
  65.  
  66. }
  67.  
  68. //--------------------------------------------------------------
  69. void ofApp::keyReleased(int key){
  70.  
  71. }
  72.  
  73. //--------------------------------------------------------------
  74. void ofApp::mouseMoved(int x, int y ){
  75.  
  76. }
  77.  
  78. //--------------------------------------------------------------
  79. void ofApp::mouseDragged(int x, int y, int button){
  80.  
  81. }
  82.  
  83. //--------------------------------------------------------------
  84. void ofApp::mousePressed(int x, int y, int button){
  85.  
  86. }
  87.  
  88. //--------------------------------------------------------------
  89. void ofApp::mouseReleased(int x, int y, int button){
  90.  
  91. }
  92.  
  93. //--------------------------------------------------------------
  94. void ofApp::mouseEntered(int x, int y){
  95.  
  96. }
  97.  
  98. //--------------------------------------------------------------
  99. void ofApp::mouseExited(int x, int y){
  100.  
  101. }
  102.  
  103. //--------------------------------------------------------------
  104. void ofApp::windowResized(int w, int h){
  105.  
  106. }
  107.  
  108. //--------------------------------------------------------------
  109. void ofApp::gotMessage(ofMessage msg){
  110.  
  111. }
  112.  
  113. //--------------------------------------------------------------
  114. void ofApp::dragEvent(ofDragInfo dragInfo){
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement