pull/2050/merge
Sebastian 1 month ago committed by GitHub
commit 6c3b4d394c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      modules/videostab/include/opencv2/videostab/global_motion.hpp
  2. 24
      modules/videostab/samples/videostab.cpp
  3. 21
      modules/videostab/src/global_motion.cpp

@ -188,8 +188,13 @@ public:
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) = 0;
void setFeatureVisualizationCallback(std::function<void(Mat)> featureVisualizationCallback) {
featureVisualizationCallback_ = std::bind(featureVisualizationCallback, std::placeholders::_1);
};
protected:
ImageMotionEstimatorBase(MotionModel model) { setMotionModel(model); }
std::function<void(Mat)> featureVisualizationCallback_;
private:
MotionModel motionModel_;

@ -168,6 +168,8 @@ void printHelp()
" Set output file path explicitly. The default is stabilized.avi.\n"
" --fps=(<float_number>|auto)\n"
" Set output video FPS explicitly. By default the source FPS is used (auto).\n"
" --vo=, --vis-output=(no|<file_path>)\n"
" Set visualization output file path. The default is no.\n"
" -q, --quiet\n"
" Don't show output video frames.\n\n"
" -h, --help\n"
@ -338,6 +340,7 @@ int main(int argc, const char **argv)
"{ gpu | no | }"
"{ o output | stabilized.avi | }"
"{ fps | auto | }"
"{ vo vis-output | no | }"
"{ q quiet | | }"
"{ h help | | }";
CommandLineParser cmd(argc, argv, keys);
@ -480,6 +483,27 @@ int main(int argc, const char **argv)
// cast stabilizer to simple frame source interface to read stabilized frames
stabilizedFrames.reset(dynamic_cast<IFrameSource*>(stabilizer));
// visWriter and visOutputPath must not be defined inside the if statement
VideoWriter visWriter;
string visOutputPath;
if (arg("vis-output") != "no")
{
visOutputPath = arg("vis-output");
std::function<void(Mat)> featureVisualizationCallback = [&visWriter, &visOutputPath](Mat featureVisualization){
// init visWriter (once) and save visualization frame
if (!featureVisualization.empty())
{
if (!visWriter.isOpened())
visWriter.open(visOutputPath, VideoWriter::fourcc('X','V','I','D'),
outputFps, featureVisualization.size());
visWriter << featureVisualization;
}
};
// must be called before
// "stabilizer->setMotionEstimator(makePtr<ToFileMotionWriter>(arg("save-motions"), stabilizer->motionEstimator()));"
stabilizer->motionEstimator()->setFeatureVisualizationCallback(featureVisualizationCallback);
}
MotionModel model = stabilizer->motionEstimator()->motionModel();
if (arg("load-motions") != "no")
{

@ -728,7 +728,11 @@ Mat KeypointBasedMotionEstimator::estimate(InputArray frame0, InputArray frame1,
// find keypoints
detector_->detect(frame0, keypointsPrev_, mask_);
if (keypointsPrev_.empty())
{
if (featureVisualizationCallback_)
featureVisualizationCallback_(Mat());
return Mat::eye(3, 3, CV_32F);
}
// extract points from keypoints
pointsPrev_.resize(keypointsPrev_.size());
@ -778,6 +782,23 @@ Mat KeypointBasedMotionEstimator::estimate(InputArray frame0, InputArray frame1,
}
}
if (featureVisualizationCallback_) {
Mat featureVisualizationPrev;
drawKeypoints(frame0, keypointsPrev_, featureVisualizationPrev,
Scalar(0, 0, 255), DrawMatchesFlags::DEFAULT);
std::vector<KeyPoint> keypointsPrevGood;
keypointsPrevGood.reserve(pointsPrevGood_.size());
for( size_t i = 0; i < pointsPrevGood_.size(); ++i) {
keypointsPrevGood.push_back(KeyPoint(pointsPrevGood_[i], 1.f));
}
drawKeypoints(frame0, keypointsPrevGood, featureVisualizationPrev,
Scalar(0, 255, 0), DrawMatchesFlags::DRAW_OVER_OUTIMG);
featureVisualizationCallback_(featureVisualizationPrev);
}
// estimate motion
return motionEstimator_->estimate(pointsPrevGood_, pointsGood_, ok);
}

Loading…
Cancel
Save