Browse files

moved flow comments

  • Loading branch information...
1 parent 2acff54 commit e2e24c7ff0d2050b19289182fff17eca3d53d407 @kylemcdonald committed Jun 2, 2012
Showing with 50 additions and 72 deletions.
  1. +8 −15 libs/ofxCv/include/ofxCv/Flow.h
  2. +0 −7 libs/ofxCv/include/ofxCv/Wrappers.h
  3. +41 −49 libs/ofxCv/src/Flow.cpp
  4. +1 −1 src/ofxCv.h
View
23 libs/ofxCv/include/ofxCv/Flow.h
@@ -1,10 +1,3 @@
-/*
- * Flow.h
- * FlowExample
- *
- * Created by James George on 12/20/11.
- */
-
#pragma once
#include "ofxCv.h"
@@ -18,15 +11,15 @@ namespace ofxCv {
public:
Flow();
~Flow();
-
+
//call these functions to calculate flow on sequential images.
//After this call the flow field will be populated and
//subsequent calls to getFlow() will be updated
//call with two contiguous images
void calcOpticalFlow(ofBaseHasPixels& lastImage, ofBaseHasPixels& currentImage);
void calcOpticalFlow(ofPixelsRef lastImage, ofPixelsRef currentImage);
-
+
//call with subsequent images to do running optical flow.
//the Flow class internally stores the last image for convenience
void calcOpticalFlow(ofBaseHasPixels& nextImage);
@@ -36,7 +29,7 @@ namespace ofxCv {
void draw(float x, float y);
void draw(float x, float y, float width, float height);
void draw(ofRectangle rect);
-
+
protected:
ofImage last, curr;
bool hasFlow;
@@ -46,7 +39,7 @@ namespace ofxCv {
//specific drawing implementation
virtual void drawFlow(ofRectangle r) = 0;
};
-
+
//there are two implementations of Flow
//use Farneback for a dense flow field,
//use PyrLK for specific features
@@ -68,12 +61,12 @@ namespace ofxCv {
void setMaxLevel(int maxLevel);
void setMaxFeatures(int maxFeatures);
void setQualityLevel(float qualityLevel);
-
+
//returns tracking features for this image
vector<ofPoint> getFeatures();
protected:
-
+
void drawFlow(ofRectangle r);
void calcFlow();
@@ -96,7 +89,7 @@ namespace ofxCv {
FlowFarneback();
~FlowFarneback();
-
+
//see http://opencv.willowgarage.com/documentation/cpp/motion_analysis_and_object_tracking.html
//for a description of these parameters
@@ -129,5 +122,5 @@ namespace ofxCv {
float polySigma;
bool farnebackGaussian;
};
-
+
}
View
7 libs/ofxCv/include/ofxCv/Wrappers.h
@@ -18,13 +18,6 @@
point set/ofPolyline functions:
- convexHull, minAreaRect, fitEllipse, unwarpPerspective, warpPerspective
- in ofxOpenCv, these were methods of ofxCvImage. for completeness, we need:
- ROI methods (set, get, reset)
- pixel manipulation (set, +, -, *, /)
- filtering (erode, dilate, blur, gaussian, invert, stretch contrast, range)
- transform (resize, mirror, translate, rotate, scale, abritrary combo)
- undistort, remap
- count nonzero pixels
*/
#pragma once
View
90 libs/ofxCv/src/Flow.cpp
@@ -1,17 +1,9 @@
-/*
- * Flow.cpp
- * FlowExample
- *
- * Created by James George on 12/20/11.
- *
- */
-
#include "Flow.h"
namespace ofxCv {
using namespace cv;
-
+
#pragma mark FLOW IMPLEMENTATION
Flow::Flow(){
hasFlow = false;
@@ -21,12 +13,12 @@ namespace ofxCv {
Flow::~Flow(){
}
-
+
//call with two images
void Flow::calcOpticalFlow(ofBaseHasPixels& lastImage, ofBaseHasPixels& currentImage){
calcOpticalFlow(lastImage.getPixelsRef(), currentImage.getPixelsRef());
}
-
+
void Flow::calcOpticalFlow(ofPixelsRef lastImage, ofPixelsRef currentImage){
last.setFromPixels(lastImage);
last.setImageType(OF_IMAGE_GRAYSCALE); //force to gray
@@ -43,7 +35,7 @@ namespace ofxCv {
void Flow::calcOpticalFlow(ofBaseHasPixels& nextImage){
calcOpticalFlow(nextImage.getPixelsRef());
}
-
+
void Flow::calcOpticalFlow(ofPixelsRef nextImage){
curr.setFromPixels(nextImage);
curr.setImageType(OF_IMAGE_GRAYSCALE);
@@ -52,7 +44,7 @@ namespace ofxCv {
calcFlow(); //will call concrete implementation
hasFlow = true;
}
-
+
last.setFromPixels(curr.getPixelsRef());
}
@@ -83,7 +75,7 @@ namespace ofxCv {
FlowPyrLK::~FlowPyrLK(){
}
-
+
void FlowPyrLK::setWindowSize(int winsize){
this->windowSize = winsize;
}
@@ -99,32 +91,32 @@ namespace ofxCv {
void FlowPyrLK::setMinDistance(int minDistance){
this->minDistance = minDistance;
}
-
+
void FlowPyrLK::calcFlow(){
prevPts.clear();
goodFeaturesToTrack(
- toCv(last),
- prevPts,
- maxFeatures,
- qualityLevel,
- minDistance
- );
+ toCv(last),
+ prevPts,
+ maxFeatures,
+ qualityLevel,
+ minDistance
+ );
vector<uchar> status;
vector<float> err;
calcOpticalFlowPyrLK(
- toCv(last),
- toCv(curr),
- prevPts,
- nextPts,
- status,
- err,
-
- cv::Size(windowSize, windowSize),
- maxLevel
- );
+ toCv(last),
+ toCv(curr),
+ prevPts,
+ nextPts,
+ status,
+ err,
+
+ cv::Size(windowSize, windowSize),
+ maxLevel
+ );
}
-
+
vector<ofPoint> FlowPyrLK::getFeatures(){
return toOf(prevPts).getVertices();
}
@@ -143,7 +135,7 @@ namespace ofxCv {
FlowFarneback::~FlowFarneback(){
}
-
+
void FlowFarneback::setPyramidScale(float scale){
if(scale < 0.0 || scale > 1.0){
ofLogWarning("ofxCvFlowFarneback -- Warning setting scale to a number outside of 0 - 1");
@@ -169,26 +161,26 @@ namespace ofxCv {
void FlowFarneback::setUseGaussian(bool gaussian){
this->farnebackGaussian = gaussian;
}
-
+
void FlowFarneback::calcFlow(){
int flags = OPTFLOW_USE_INITIAL_FLOW;
flags |= farnebackGaussian ? OPTFLOW_FARNEBACK_GAUSSIAN : 0;
calcOpticalFlowFarneback(
- toCv(last),
- toCv(curr),
- flow,
-
- pyramidScale,
- numLevels,
- windowSize,
- numIterations,
- polyN,
- polySigma,
- flags
- );
+ toCv(last),
+ toCv(curr),
+ flow,
+
+ pyramidScale,
+ numLevels,
+ windowSize,
+ numIterations,
+ polyN,
+ polySigma,
+ flags
+ );
}
-
+
ofVec2f FlowFarneback::getFlowOffset(int x, int y){
const Vec2f& vec = flow.at<Vec2f>(y, x);
return ofVec2f(vec[0], vec[1]);
@@ -203,7 +195,7 @@ namespace ofxCv {
ofVec2f FlowFarneback::getAverageFlow(){
return getAverageFlowInRegion(ofRectangle(0,0,flow.cols,flow.rows));
}
-
+
ofVec2f FlowFarneback::getAverageFlowInRegion(ofRectangle rect){
return getTotalFlowInRegion(rect)/(rect.width*rect.height);
}
@@ -212,7 +204,7 @@ namespace ofxCv {
const Scalar& sc = sum(flow(toCv(region)));
return ofVec2f(sc[1], sc[0]);
}
-
+
void FlowFarneback::drawFlow(ofRectangle rect){
ofVec2f offset(rect.x,rect.y);
ofVec2f scale(rect.width/flow.cols, rect.height/flow.rows);
View
2 src/ofxCv.h
@@ -23,6 +23,6 @@
#include "ofxCv/Tracker.h" // object tracking
#include "ofxCv/ContourFinder.h" // contour finding and tracking
#include "ofxCv/RunningBackground.h" // background subtraction
-#include "ofxCv/Flow.h" // optical flow
+#include "ofxCv/Flow.h" // optical flow, from james george
// <3 kyle

0 comments on commit e2e24c7

Please sign in to comment.