void ofxOpticalFlowFarneback::draw(int width, int height,  float lineScale, int res) {
	bool rightSize = (sizeSml.width == width && sizeSml.height == height);

	ofPoint vel;
	for(int x=0; x<width; x+=res) {
		for(int y=0; y<height; y+=res) {
			if(rightSize) {
				vel = getVelAtPixel(x, y);
			}
			else {
				vel = getVelAtNorm(x / (float)width, y / (float)height);
			}
			if(vel.length() < 1) {  // smaller then 1 pixel, no point drawing.
				continue;
			}

            ofDrawLine(x, y, x + vel.x * lineScale, y + vel.y * lineScale);
		}
	}
}
void ofxOpticalFlowFarneback::drawColored(int width, int height,  float lineScale, int res) {
	bool rightSize = (sizeSml.width == width && sizeSml.height == height);

	ofPoint vel;
	ofMesh velMesh;

	velMesh.setMode(OF_PRIMITIVE_LINES);

	for(int x=0; x<width; x+=res) {
		for(int y=0; y<height; y+=res) {
			if(rightSize) {
				vel = getVelAtPixel(x, y);
			}
			else {
				vel = getVelAtNorm(x / (float)width, y / (float)height);
			}

			if(vel.length() < 1) {  // smaller then 1 pixel, no point drawing.
				continue;
			}
			ofVec3f p(x,y);
			ofVec3f vc = vel;
			vc.normalize();
			float hue = (atan2(vc.y, vc.x)+3.14159265)/(3.14159265*2.0);
			ofFloatColor c;
			c.setHsb(hue, 1.0, 1.0);
			c.a = 0.25;
			velMesh.addColor(c);
			velMesh.addVertex(p);
			c.a = 0.0;
			velMesh.addColor(c);
			velMesh.addVertex(p+vel*lineScale);
		}
	}

	ofPushStyle();
	ofEnableAlphaBlending();
	velMesh.draw();
	ofPopStyle();
}
void ofxOpticalFlowLK :: draw ( int width, int height,  float lineScale, int res )
{
	bool rightSize = ( sizeSml.width == width && sizeSml.height == height );
	
	ofPoint vel;
	
	for( int x=0; x<width; x+=res )
	{
		for( int y=0; y<height; y+=res )
		{
			if( rightSize )
				vel = getVelAtPixel( x, y );
			else
				vel = getVelAtNorm( x / (float)width, y / (float)height );
			
			if( vel.x == 0 && vel.y == 0 )
				continue;
			
			ofLine( x, y, x + vel.x * lineScale, y + vel.y * lineScale );
		}
	}
}