Advertisement
Guest User

ofApp.cpp

a guest
Sep 19th, 2016
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void ofApp::setup(){
  5.     ofSetVerticalSync(true);
  6.     ofEnableAlphaBlending();
  7.     kinect.setRegistration(true);
  8.    
  9.     video1.load("drive_water.mov");
  10.     video1.play();
  11.     video1.setVolume(0);
  12.    
  13.     kinect.init();
  14.     kinect.open();
  15.    
  16.     ofSetFrameRate(30);
  17.  
  18.     grayscaleImage.allocate(ofGetWidth(),ofGetHeight());
  19.     maskFbo.allocate(ofGetWidth(),ofGetHeight());
  20.     videoFbo.allocate(ofGetWidth(),ofGetHeight());
  21.     compFbo.allocate(ofGetWidth(),ofGetHeight());
  22.     feedbackFbo.allocate(ofGetWidth(),ofGetHeight());
  23.  
  24.     maskShader.load("alphamask");
  25.     lumaDrag.load("lumadrag");
  26.  
  27.     maskFbo.begin();
  28.     ofClear(0,0,0,255);
  29.     maskFbo.end();
  30.    
  31.     videoFbo.begin();
  32.     ofClear(0,0,0,255);
  33.     videoFbo.end();
  34.    
  35.     compFbo.begin();
  36.     ofClear(0,0,0,255);
  37.     compFbo.end();
  38.    
  39.     feedbackFbo.begin();
  40.     ofClear(0,0,0,255);
  41.     feedbackFbo.end();
  42.    
  43.     gui.setup("Thresholds","",10,620);
  44.     gui.add(nearThresh.setup("Near",1000,0,1000));
  45.     gui.add(farThresh.setup("Far",1000,0,1000));
  46.    
  47.     shaderGui.setup("Lumadrag","",310,620);
  48.     shaderGui.add(dragThresh.setup("thresh",0.0,0.0,1.0));
  49. }
  50.  
  51. //--------------------------------------------------------------
  52. void ofApp::update(){
  53.     kinect.update();
  54.     video1.update();
  55.    
  56.     maskFbo.begin();
  57.     ofClear(0,0,0,255);
  58.     maskFbo.end();
  59.    
  60.     videoFbo.begin();
  61.     ofClear(0,0,0,255);
  62.     videoFbo.end();
  63.    
  64.     compFbo.begin();
  65.     ofClear(0,0,0,255);
  66.     compFbo.end();
  67.    
  68.     feedbackFbo.begin();
  69.     compFbo.draw(0,0);
  70.     feedbackFbo.end();
  71.    
  72.     if(kinect.isFrameNew()){
  73.         grayscaleImage.setFromPixels(kinect.getDepthPixels());
  74.        
  75.         ofPixels & pix = grayscaleImage.getPixels();
  76.         int numPixels = pix.size();
  77.         for(int i=0; i < numPixels; i++){
  78.             if(pix[i] < nearThresh && pix[i] > farThresh){
  79.                 pix[i] = 255;
  80.             }else{
  81.                 pix[i] = 0;
  82.             }
  83.         }
  84.        
  85.         grayscaleImage.flagImageChanged();
  86.         contourFinder.findContours(grayscaleImage, 10, (kinect.width*kinect.height)/2, 20, false);
  87.     }
  88.  
  89.     maskFbo.begin();
  90.         grayscaleImage.draw(0,0,ofGetWidth(),ofGetHeight());
  91.     maskFbo.end();
  92.    
  93.     videoFbo.begin();
  94.         video1.draw(0,0,ofGetWidth(),ofGetHeight());
  95.     videoFbo.end();
  96.    
  97.     compFbo.begin();
  98.         maskShader.begin();
  99.             maskShader.setUniformTexture("maskTex", maskFbo.getTexture(), 1);
  100.             videoFbo.draw(0,0,ofGetWidth(),ofGetHeight());
  101.         maskShader.end();
  102.     compFbo.end();
  103.    
  104.     //trying to fill a feedback buffer here:
  105.     feedbackFbo.begin();
  106.         lumaDrag.begin();
  107.         lumaDrag.setUniformTexture("tex1", feedbackFbo.getTexture(), 1);
  108.         lumaDrag.setUniform1f("thresh", dragThresh);
  109.         compFbo.draw(0,0);
  110.         lumaDrag.end();
  111.     feedbackFbo.end();
  112. }
  113.  
  114. //--------------------------------------------------------------
  115. void ofApp::draw(){
  116.  
  117.     lumaDrag.begin();
  118.         lumaDrag.setUniformTexture("tex1", feedbackFbo.getTexture(), 1);
  119.         lumaDrag.setUniform1f("thresh", dragThresh);
  120.         compFbo.draw(0,0);
  121.     lumaDrag.end();
  122.    
  123.     gui.draw();
  124.     shaderGui.draw();
  125. }
  126.  
  127. //--------------------------------------------------------------
  128. void ofApp::keyPressed(int key){
  129.  
  130. }
  131.  
  132. //--------------------------------------------------------------
  133. void ofApp::keyReleased(int key){
  134.  
  135. }
  136.  
  137. //--------------------------------------------------------------
  138. void ofApp::mouseMoved(int x, int y ){
  139.  
  140. }
  141.  
  142. //--------------------------------------------------------------
  143. void ofApp::mouseDragged(int x, int y, int button){
  144.  
  145. }
  146.  
  147. //--------------------------------------------------------------
  148. void ofApp::mousePressed(int x, int y, int button){
  149.  
  150. }
  151.  
  152. //--------------------------------------------------------------
  153. void ofApp::mouseReleased(int x, int y, int button){
  154.  
  155. }
  156.  
  157. //--------------------------------------------------------------
  158. void ofApp::mouseEntered(int x, int y){
  159.  
  160. }
  161.  
  162. //--------------------------------------------------------------
  163. void ofApp::mouseExited(int x, int y){
  164.  
  165. }
  166.  
  167. //--------------------------------------------------------------
  168. void ofApp::windowResized(int w, int h){
  169.  
  170. }
  171.  
  172. //--------------------------------------------------------------
  173. void ofApp::gotMessage(ofMessage msg){
  174.  
  175. }
  176.  
  177. //--------------------------------------------------------------
  178. void ofApp::dragEvent(ofDragInfo dragInfo){
  179.  
  180. }
Advertisement
RAW Paste Data Copied
Advertisement