Added more flags for motion estimation in videostab sample

This commit is contained in:
Alexey Spizhevoy
2012-04-11 10:17:35 +00:00
parent b549900fe1
commit b5a1bad7a4
4 changed files with 40 additions and 3 deletions

View File

@@ -148,6 +148,9 @@ public:
void setMinInlierRatio(float val) { minInlierRatio_ = val; }
float minInlierRatio() const { return minInlierRatio_; }
void setGridSize(Size val) { gridSize_ = val; }
Size gridSize() const { return gridSize_; }
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
private:
@@ -160,6 +163,7 @@ private:
std::vector<Point2f> pointsPrevGood_, pointsGood_;
float maxRmse_;
float minInlierRatio_;
Size gridSize_;
};
CV_EXPORTS Mat getMotion(int from, int to, const std::vector<Mat> &motions);

View File

@@ -344,6 +344,7 @@ PyrLkRobustMotionEstimator::PyrLkRobustMotionEstimator(MotionModel model)
setRansacParams(RansacParams::homography2dMotionStd());
setMaxRmse(0.5f);
setMinInlierRatio(0.1f);
setGridSize(Size(0,0));
}
@@ -351,6 +352,21 @@ Mat PyrLkRobustMotionEstimator::estimate(const Mat &frame0, const Mat &frame1, b
{
detector_->detect(frame0, keypointsPrev_);
// add extra keypoints
if (gridSize_.width > 0 && gridSize_.height > 0)
{
float dx = (float)frame0.cols / (gridSize_.width + 1);
float dy = (float)frame0.rows / (gridSize_.height + 1);
for (int x = 0; x < gridSize_.width; ++x)
for (int y = 0; y < gridSize_.height; ++y)
keypointsPrev_.push_back(KeyPoint((x+1)*dx, (y+1)*dy, 0.f));
}
/*Mat img;
drawKeypoints(frame0, keypointsPrev_, img);
imshow("frame0_keypoints", img);
waitKey(3);*/
pointsPrev_.resize(keypointsPrev_.size());
for (size_t i = 0; i < keypointsPrev_.size(); ++i)
pointsPrev_[i] = keypointsPrev_[i].pt;

View File

@@ -375,6 +375,7 @@ void TwoPassStabilizer::runPrePassIfNecessary()
motionStabilizer_->stabilize(
frameCount_, motions_, make_pair(0, frameCount_ - 1), &stabilizationMotions_[0]);
// save motions
/*ofstream fm("log_motions.csv");
for (int i = 0; i < frameCount_ - 1; ++i)
{