Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- //--------------------------------------------------------------
- void ofApp::setup(){
- ofSetVerticalSync(true);
- ofEnableAlphaBlending();
- kinect.setRegistration(true);
- video1.load("drive_water.mov");
- video1.play();
- video1.setVolume(0);
- kinect.init();
- kinect.open();
- ofSetFrameRate(30);
- grayscaleImage.allocate(ofGetWidth(),ofGetHeight());
- maskFbo.allocate(ofGetWidth(),ofGetHeight());
- videoFbo.allocate(ofGetWidth(),ofGetHeight());
- compFbo.allocate(ofGetWidth(),ofGetHeight());
- feedbackFbo.allocate(ofGetWidth(),ofGetHeight());
- maskShader.load("alphamask");
- lumaDrag.load("lumadrag");
- maskFbo.begin();
- ofClear(0,0,0,255);
- maskFbo.end();
- videoFbo.begin();
- ofClear(0,0,0,255);
- videoFbo.end();
- compFbo.begin();
- ofClear(0,0,0,255);
- compFbo.end();
- feedbackFbo.begin();
- ofClear(0,0,0,255);
- feedbackFbo.end();
- gui.setup("Thresholds","",10,620);
- gui.add(nearThresh.setup("Near",1000,0,1000));
- gui.add(farThresh.setup("Far",1000,0,1000));
- shaderGui.setup("Lumadrag","",310,620);
- shaderGui.add(dragThresh.setup("thresh",0.0,0.0,1.0));
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- kinect.update();
- video1.update();
- maskFbo.begin();
- ofClear(0,0,0,255);
- maskFbo.end();
- videoFbo.begin();
- ofClear(0,0,0,255);
- videoFbo.end();
- compFbo.begin();
- ofClear(0,0,0,255);
- compFbo.end();
- feedbackFbo.begin();
- compFbo.draw(0,0);
- feedbackFbo.end();
- if(kinect.isFrameNew()){
- grayscaleImage.setFromPixels(kinect.getDepthPixels());
- ofPixels & pix = grayscaleImage.getPixels();
- int numPixels = pix.size();
- for(int i=0; i < numPixels; i++){
- if(pix[i] < nearThresh && pix[i] > farThresh){
- pix[i] = 255;
- }else{
- pix[i] = 0;
- }
- }
- grayscaleImage.flagImageChanged();
- contourFinder.findContours(grayscaleImage, 10, (kinect.width*kinect.height)/2, 20, false);
- }
- maskFbo.begin();
- grayscaleImage.draw(0,0,ofGetWidth(),ofGetHeight());
- maskFbo.end();
- videoFbo.begin();
- video1.draw(0,0,ofGetWidth(),ofGetHeight());
- videoFbo.end();
- compFbo.begin();
- maskShader.begin();
- maskShader.setUniformTexture("maskTex", maskFbo.getTexture(), 1);
- videoFbo.draw(0,0,ofGetWidth(),ofGetHeight());
- maskShader.end();
- compFbo.end();
- //trying to fill a feedback buffer here:
- feedbackFbo.begin();
- lumaDrag.begin();
- lumaDrag.setUniformTexture("tex1", feedbackFbo.getTexture(), 1);
- lumaDrag.setUniform1f("thresh", dragThresh);
- compFbo.draw(0,0);
- lumaDrag.end();
- feedbackFbo.end();
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- lumaDrag.begin();
- lumaDrag.setUniformTexture("tex1", feedbackFbo.getTexture(), 1);
- lumaDrag.setUniform1f("thresh", dragThresh);
- compFbo.draw(0,0);
- lumaDrag.end();
- gui.draw();
- shaderGui.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