示例#1
0
    void setup() {
        ofSetDataPathRoot("../../../../../SharedData/");
        ofSetVerticalSync(true);
//        ofSetLogLevel(OF_LOG_VERBOSE);
        
#ifdef USE_VIDEO
        video.loadMovie("videos/melica.mp4");
        video.play();
#else
        video.setup();
        #ifdef USE_EDSDK
            video.setDeviceType(EDSDK_MKII);
        #endif
#endif
        
        ofFbo::Settings settings;
        settings.width = video.getWidth();
        settings.height = video.getHeight();
        settings.useDepth = false;
        buffer.allocate(settings);
        ofSetBackgroundAuto(false);
        contours.getTracker().setPersistence(100);
        contours.getTracker().setMaximumDistance(100);
        setupGui();
        
        osc.setup("klaus.local", 7400);
    }
vector< ofPolyline > utility::transform(ofxCv::ContourFinder input, int dx, int dy, float z, int r)
{
	vector< ofPolyline > output;		
	for (int i = 0; i < input.size(); ++i)
	{
		ofPolyline line = input.getPolyline(i);
		ofPolyline tLine;
		for (int j = 0; j < line.size(); ++j)
		{
			ofPoint pt = line[j];
			float tx = pt.x * z + dx;
			float ty = pt.y * z + dy;
			tLine.addVertex(tx, ty);
		}
		output.push_back(tLine);
	}
	return output;
}
示例#3
0
 void updateContours() {
     contours.setMinAreaRadius(minAreaRadius);
     contours.setSortBySize(true);
     contours.findContours(dilated);
     int n = contours.size();
     if(n > 0) {
         cv::Rect all = contours.getBoundingRect(0);
         for(int i = 1; i < n; i++) {
             all |= contours.getBoundingRect(i);
         }
         bodyCenter.interpolate(toOf(all).getCenter(), bodyCenterSmoothing);
     }
 }
void myBlobManager::update (ofxCv::ContourFinder contourFinder) {
    blobs.clear();
    for(int i = 0; i < contourFinder.size(); i++) {
        ofPoint center = toOf(contourFinder.getCenter(i));
        blobs.push_back(ofxCvBlob());
        
        blobs[i].area = contourFinder.getContourArea(i);
        blobs[i].length = contourFinder.getArcLength(i);
        blobs[i].boundingRect = toOf( contourFinder.getBoundingRect(i));
        blobs[i].centroid = center;
        
        vector<cv::Point> blobPoints = contourFinder.getContour(i);
        for(int j = 0; j < blobPoints.size(); j++) {
            blobs[i].pts.push_back( toOf(blobPoints[j]));
        }
        
        blobs[i].nPts = blobs[i].pts.size();
    }
    
    blobsManager.update(blobs);
}
示例#5
0
    void draw() {
        ofBackground(0);
        
        ofPushMatrix();
        ofPushStyle();
        
        float scaleFactor = ofGetHeight() / (float) MAX(1, video.getHeight());
        ofScale(scaleFactor, scaleFactor);
        ofTranslate(0, -verticalOffset);
        
        float totalStability = ofClamp(ofMap(smoothedMotionValue, motionMin, motionMax, 0, stability), 0, 1);
        
        int n = contours.size();
        
        for(int i = 0; i < n; i++) {
            cv::Rect cur = contours.getBoundingRect(i);
            float w = cur.width, h = cur.height;
            float sx = cur.x, sy = cur.y;
            
            buffer.begin();
            ofDisableBlendMode();
            
            // clear buffer area
            ofClear(0, 0);
            
            // draw filled shape (could blur here)
            ofPushMatrix();
            ofSetColor(255);
            ofFill();
            ofBeginShape();
            vector<cv::Point>& vertices = contours.getContour(i);
            for(int j = 0; j < vertices.size(); j++) {
                ofVertex(vertices[j].x, vertices[j].y);
            }
            ofEndShape();
            ofPopMatrix();
            
            // draw body image
            ofEnableBlendMode(OF_BLENDMODE_MULTIPLY);
            ofSetColor(255);
            video.getTexture().drawSubsection(sx, sy, w, h, sx, sy);
            buffer.end();
            
            ofEnableBlendMode(OF_BLENDMODE_ALPHA);
            ofPushMatrix();
            
            ofVec2f center = toOf(contours.getCenter(i));
            ofVec2f offset = center - bodyCenter;
            float orientation = atan2f(offset.y, offset.x);
            float spread = totalStability * spreadAmplitude;
            ofVec2f position = bodyCenter + offset + ofVec2f(offset.x, 0) * spread;
            
            float id = orientation; //contours.getLabel(i) % 3;
            
            float baseRotation = rotationRate * ofGetElapsedTimef() + id;
            float rotation = ofLerp(sin(baseRotation), ofSignedNoise(baseRotation), rotationNoise);
            rotation *= rotationAmplitude * totalStability;
            
            float baseScale = scaleRate * ofGetElapsedTimef() + id;
            float scale = 1 + scaleAmplitude * ofLerp(sin(baseScale), ofSignedNoise(baseScale), scaleNoise) * totalStability;
            
            ofPushStyle();
            ofSetColor(tintRed, tintGreen, tintBlue);
            ofTranslate(position);
            for(int j = 0; j < repetitionSteps; j++) {
                ofPushMatrix();
                float rotationAmount = ofMap(j, -1, repetitionSteps, 0, rotation);
                ofRotate(rotationAmount);
//                ofVec3f axis(0, 0, 1);
//                ofRotate(rotationAmount, axis.x, axis.y, axis.z);
                float curScale = ofMap(j, -1, repetitionSteps, 1, scale);
                ofScale(curScale, curScale, curScale);
                buffer.getTextureReference().drawSubsection(-w / 2, -h / 2, 0, w, h, sx, sy);
                ofPopMatrix();
            }
            ofPopStyle();
            
            if(debug) {
                ofDrawBitmapStringHighlight(ofToString(contours.getLabel(i)), 0, 0);
            }
            ofPopMatrix();
        }
            
        ofPopStyle();
        ofPopMatrix();
        
        ofEnableAlphaBlending();
        
        if(debug) {
            ofPushStyle();
            ofSetColor(255);
            ofNoFill();
            ofSetLineWidth(2);
            ofDrawRectangle(0, 0, video.getWidth(), video.getHeight());
            video.draw(0, 0);
            ofPopStyle();
            
            ofPushStyle();
            ofEnableBlendMode(OF_BLENDMODE_ADD);
            
            ofPushMatrix();
            ofScale(1 / rescale, 1 / rescale);
            drawMat(thresholdedRunning, 0, 0);
            ofPopMatrix();
            
            ofSetColor(magentaPrint, 10);
            drawMat(thresholded, 0, 0);
            
            ofSetLineWidth(3);
            for(int i = 0; i < n; i++) {
                ofSetColor(255);
                contours.getPolyline(i).draw();
            }
            ofNoFill();
            ofSetColor(cyanPrint);
            ofCircle(bodyCenter, 10);
            ofPopStyle();
            
#ifndef USE_VIDEO
            if(video.isLiveDataReady()) {
                stringstream status;
                status << video.getWidth() << "x" << video.getHeight() << " @ " <<
                (int) ofGetFrameRate() << " app-fps " << " / " <<
                (int) video.getFrameRate() << " cam-fps";
                ofDrawBitmapString(status.str(), 10, ofGetHeight() - 40);
            }
#endif
        }
    }