Esempio n. 1
0
 void setupedFbo()
 {
     if (!mFbo.isAllocated()) {
         mFbo.allocate(getWidth(), getHeight(), GL_RGBA);
         mGlitch.setup(&mFbo);
         mGlitch.setFx(OFXPOSTGLITCH_TWIST, true);
     }
 }
Esempio n. 2
0
//--------------------------------------------------------------
void testApp::update(){
    
    // Get infrarred image from kinect and transform to OpenCV image
    recordContext.update();
    recordImage.update();
    
    grayImage.setFromPixels(recordImage.ir_pixels, W, H);
    
    
    // Save background
    if(bBackground){
        saveBackground();
        bBackground = false;
    }
    
    
    // ROI mask selection
    drawRoiMask(grayImage);

 
    roi.x = MIN(roiMask[0].x, roiMask[3].x);
    roi.y = MIN(roiMask[0].y, roiMask[1].y);
    roiW = MAX(roiMask[1].x, roiMask[2].x) - roi.x;
    roiH = MAX(roiMask[3].y, roiMask[2].y) - roi.y;
    
    grayImage.setROI(roi.x, roi.y, roiW, roiH);
    backImg.setROI(roi.x, roi.y, roiW, roiH);
    grayAcc.setROI(roi.x, roi.y, roiW, roiH);
    
    
    // Opencv preprocessing
    
    t0 = ofGetElapsedTimeMillis();
    
    if(bProcess){
       // grayImage.absDiff(grayImage, backImg);
        grayImage.brightnessContrast(brightness, contrast);
        cvAdaptiveThreshold(grayImage.getCvImage(), grayImage.getCvImage(), 255);
        grayImage.blur();
        grayImage.erode();
        grayImage.dilate();
        
        grayImage.addWeighted(grayAcc, 0.1);
        grayAcc = grayImage;
        grayImage.canny(50, 150);
        
        Mat dst = grayImage.getCvImage();
        findContours(dst, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
        for (size_t i = 0; i < contours.size(); i++){
            CvPoint* pts = new CvPoint[contours[i].size()];
            for(int j = 0; j < contours[i].size(); j ++){
                pts[j].x = contours[i][j].x;
                pts[j].y = contours[i][j].y;
            }
            
            int nPts = contours[i].size();
            cvPolyLine( grayImage.getCvImage(), &pts, &nPts, 1, true, CV_RGB(255, 255, 255));
            delete[] pts;
        }
        grayImage.dilate();
        grayImage.erode();
    }
    t1 = ofGetElapsedTimeMillis() - t0;
     
    //---
    
    
	// Send image to MadMapper
    t0 = ofGetElapsedTimeMillis();
    tex.allocate(grayImage.getWidth(), grayImage.getHeight(), GL_LUMINANCE);
    tex.loadData(grayImage.getPixels(), grayImage.getWidth(), grayImage.getHeight(), GL_LUMINANCE);
    individualTextureSyphonServer.publishTexture(&tex);
    //---
    
	// Get image from MadMapper
    if(!fbo.isAllocated() || !(mClient.getWidth() == fbo.getWidth() && mClient.getHeight() == fbo.getHeight()))
        fbo.allocate(mClient.getWidth(), mClient.getHeight());
    
    fbo.begin();
    mClient.draw(0, 0);
    fbo.end();
    
    fbo.readToPixels(pix);
    
    t2 = ofGetElapsedTimeMillis() - t0;
    //---
    
    
	// Update my system
    
    L.update(mouseX, mouseY);
}