void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
float flowErrorThreshold() const { return flowErrorThreshold_; }
+ void setDistThreshold(float val) { distThresh_ = val; }
+ float distThresh() const { return distThresh_; }
+
void setBorderMode(int val) { borderMode_ = val; }
int borderMode() const { return borderMode_; }
FastMarchingMethod fmm_;
Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
float flowErrorThreshold_;
+ float distThresh_;
int borderMode_;
Mat frame1_, transformedFrame1_;
CV_EXPORTS void completeFrameAccordingToFlow(
const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
- Mat& frame0, Mat &mask0);
+ float distThresh, Mat& frame0, Mat &mask0);
} // namespace videostab
} // namespace cv
ConsistentMosaicInpainter::ConsistentMosaicInpainter()
{
- setStdevThresh(20);
+ setStdevThresh(20.f);
}
CV_Error(CV_StsNotImplemented, "Current implementation of MotionInpainter requires GPU");
#endif
setFlowErrorThreshold(1e-4f);
+ setDistThreshold(5.f);
setBorderMode(BORDER_REPLICATE);
}
fmm_.run(flowMask_, body);
completeFrameAccordingToFlow(
- flowMask_, flowX_, flowY_, transformedFrame1_, transformedMask1_, frame, mask);
+ flowMask_, flowX_, flowY_, transformedFrame1_, transformedMask1_, distThresh_,
+ frame, mask);
}
}
void completeFrameAccordingToFlow(
const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
- Mat &frame0, Mat &mask0)
+ float distThresh, Mat &frame0, Mat &mask0)
{
CV_Assert(flowMask.type() == CV_8U);
CV_Assert(flowX.type() == CV_32F && flowX.size() == flowMask.size());
Mat_<uchar> flowMask_(flowMask), mask1_(mask1), mask0_(mask0);
Mat_<float> flowX_(flowX), flowY_(flowY);
+ //int count = 0;
for (int y0 = 0; y0 < frame0.rows; ++y0)
{
for (int x0 = 0; x0 < frame0.cols; ++x0)
int x1 = cvRound(x0 + flowX_(y0,x0));
int y1 = cvRound(y0 + flowY_(y0,x0));
- if (x1 >= 0 && x1 < frame1.cols && y1 >= 0 && y1 < frame1.rows && mask1_(y1,x1))
- {
+ if (x1 >= 0 && x1 < frame1.cols && y1 >= 0 && y1 < frame1.rows && mask1_(y1,x1)
+ && sqr(flowX_(y0,x0)) + sqr(flowY_(y0,x0)) < sqr(distThresh))
+ {
frame0.at<Point3_<uchar> >(y0,x0) = frame1.at<Point3_<uchar> >(y1,x1);
mask0_(y0,x0) = 255;
+ //count++;
}
}
}
}
+ //cout << count << endl;
}
} // namespace videostab
" Outliers ratio in motion estimation. The default is 0.5.\n"
" --min-inlier-ratio=<float_number>\n"
" Minimum inlier ratio to decide if estimated motion is OK. The default is 0.1,\n"
- " but you may want to increase it.\n"
+ " but you may want to increase it.\n\n"
" -r, --radius=<int_number>\n"
" Set smoothing radius. The default is 15.\n"
" --stdev=<float_number>\n"
- " Set smoothing weights standard deviation. The default is sqrt(radius).\n"
+ " Set smoothing weights standard deviation. The default is sqrt(radius).\n\n"
" --deblur=(yes|no)\n"
" Do deblurring.\n"
" --deblur-sens=<float_number>\n"
- " Set deblurring sensitivity (from 0 to +inf). The default is 0.1.\n"
+ " Set deblurring sensitivity (from 0 to +inf). The default is 0.1.\n\n"
" -t, --trim-ratio=<float_number>\n"
- " Set trimming ratio (from 0 to 0.5). The default is 0.\n"
+ " Set trimming ratio (from 0 to 0.5). The default is 0.0.\n"
" --est-trim=(yes|no)\n"
" Estimate trim ratio automatically. The default is yes (that leads to two passes,\n"
" you can turn it off if you want to use one pass only).\n"
" --incl-constr=(yes|no)\n"
- " Ensure the inclusion constraint is always satisfied. The default is no.\n"
+ " Ensure the inclusion constraint is always satisfied. The default is no.\n\n"
" --border-mode=(replicate|reflect|const)\n"
- " Set border extrapolation mode. The default is replicate.\n"
+ " Set border extrapolation mode. The default is replicate.\n\n"
" --mosaic=(yes|no)\n"
" Do consistent mosaicing. The default is no.\n"
" --mosaic-stdev=<float_number>\n"
- " Consistent mosaicing stdev threshold. The default is 10.\n"
+ " Consistent mosaicing stdev threshold. The default is 10.0.\n\n"
" --motion-inpaint=(yes|no)\n"
" Do motion inpainting (requires GPU support). The default is no.\n"
+ " --dist-thresh=<float_number>\n"
+ " Estimated flow distance threshold for motion inpainting. The default is 5.0.\n\n"
" --color-inpaint=(no|average|ns|telea)\n"
" Do color inpainting. The defailt is no.\n"
" --color-inpaint-radius=<float_number>\n"
- " Set color inpainting radius (for ns and telea options only).\n"
+ " Set color inpainting radius (for ns and telea options only).\n\n"
" -o, --output=<file_path>\n"
" Set output file path explicitely. The default is stabilized.avi.\n"
" --fps=<int_number>\n"
" Set output video FPS explicitely. By default the source FPS is used.\n"
" -q, --quiet\n"
- " Don't show output video frames.\n"
+ " Don't show output video frames.\n\n"
" -h, --help\n"
" Print help.\n"
"\n";
"{ | mosaic | | }"
"{ | mosaic-stdev | | }"
"{ | motion-inpaint | | }"
+ "{ | dist-thresh | | }"
"{ | color-inpaint | no | }"
"{ | color-inpaint-radius | | }"
"{ o | output | stabilized.avi | }"
inpainters->pushBack(inpainter);
}
if (cmd.get<string>("motion-inpaint") == "yes")
- inpainters->pushBack(new MotionInpainter());
+ {
+ MotionInpainter *inpainter = new MotionInpainter();
+ if (!cmd.get<string>("dist-thresh").empty())
+ inpainter->setDistThreshold(cmd.get<float>("dist-thresh"));
+ inpainters->pushBack(inpainter);
+ }
if (!cmd.get<string>("color-inpaint").empty())
{
if (cmd.get<string>("color-inpaint") == "average")
}
catch (const exception &e)
{
- cout << e.what() << endl;
+ cout << "error: " << e.what() << endl;
stabilizer.release();
return -1;
}