ofVec2f ofxCvOpticalFlowLK::flowInRegion(float x, float y, float w, float h){
	ofVec2f topLeft, bottomRight, total(0,0);
	boundsForRect(x, y, w, h, &topLeft, &bottomRight);
	for (int j = topLeft.y; j < bottomRight.y; j++) {
		for(int i = topLeft.x; i < bottomRight.x; i++){
			total += flowAtPoint(i, j);
		}
	}
	return total; 
}
ofVec2f ofxCvOpticalFlowLK::averageFlowInRegion(float x, float y, float w, float h)
{
	ofVec2f topLeft, bottomRight, total(0,0);
	boundsForRect(x, y, w, h, &topLeft, &bottomRight);
	for (int j = topLeft.y; j < bottomRight.y; j += captureRowsStep) {
		for(int i = topLeft.x; i < bottomRight.x; i += captureColsStep) {
			total += flowAtPoint(i, j);
		}
	}

	return total / ( (bottomRight.x - topLeft.x) * (bottomRight.y - topLeft.y));
}
Ejemplo n.º 3
0
ofPoint ofxCvOpticalFlowLK::flowInRegion(int x, int y, int w, int h){
	w = fmin(x+w, x - captureWidth);
	h = fmin(y+h, y - captureHeight);
	x = fmax(0,x);
	y = fmax(0,y);
	ofPoint total(0,0);
	for(int i = 0; i < x; i++){
		for (int j = 0; j < y; j++) {
			total += flowAtPoint(x, y);
		}
	}
	return total / (w*h);
}
void ofxCvOpticalFlowLK::draw(int width, int height){

	ofPushStyle();
	
//	float scalex = (float) width / captureWidth;
//	float scaley = (float) height / captureHeight;
	
	int x, y, dx, dy;
	for ( y = 0; y < captureHeight; y+=captureRowsStep ){
		for ( x = 0; x < captureWidth; x+=captureColsStep ){
			
//			dx = (int)cvGetReal2D( vel_x, y, x );
//			dy = (int)cvGetReal2D( vel_y, y, x );
//			
			ofVec2f vec = flowAtPoint(x, y);

			ofLine(x,y,(x+vec.x),(y+vec.y));
			
		}
	}
	
	ofPopStyle();
	
}