mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 14:13:15 +08:00
Added distance threshold argument into videostab sample
This commit is contained in:
parent
8fc84b7a41
commit
3323ee9d18
@ -137,6 +137,9 @@ public:
|
|||||||
void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
|
void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
|
||||||
float flowErrorThreshold() const { return flowErrorThreshold_; }
|
float flowErrorThreshold() const { return flowErrorThreshold_; }
|
||||||
|
|
||||||
|
void setDistThreshold(float val) { distThresh_ = val; }
|
||||||
|
float distThresh() const { return distThresh_; }
|
||||||
|
|
||||||
void setBorderMode(int val) { borderMode_ = val; }
|
void setBorderMode(int val) { borderMode_ = val; }
|
||||||
int borderMode() const { return borderMode_; }
|
int borderMode() const { return borderMode_; }
|
||||||
|
|
||||||
@ -146,6 +149,7 @@ private:
|
|||||||
FastMarchingMethod fmm_;
|
FastMarchingMethod fmm_;
|
||||||
Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
|
Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
|
||||||
float flowErrorThreshold_;
|
float flowErrorThreshold_;
|
||||||
|
float distThresh_;
|
||||||
int borderMode_;
|
int borderMode_;
|
||||||
|
|
||||||
Mat frame1_, transformedFrame1_;
|
Mat frame1_, transformedFrame1_;
|
||||||
@ -184,7 +188,7 @@ CV_EXPORTS void calcFlowMask(
|
|||||||
|
|
||||||
CV_EXPORTS void completeFrameAccordingToFlow(
|
CV_EXPORTS void completeFrameAccordingToFlow(
|
||||||
const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
|
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 videostab
|
||||||
} // namespace cv
|
} // namespace cv
|
||||||
|
@ -110,7 +110,7 @@ struct Pixel3
|
|||||||
|
|
||||||
ConsistentMosaicInpainter::ConsistentMosaicInpainter()
|
ConsistentMosaicInpainter::ConsistentMosaicInpainter()
|
||||||
{
|
{
|
||||||
setStdevThresh(20);
|
setStdevThresh(20.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -288,6 +288,7 @@ MotionInpainter::MotionInpainter()
|
|||||||
CV_Error(CV_StsNotImplemented, "Current implementation of MotionInpainter requires GPU");
|
CV_Error(CV_StsNotImplemented, "Current implementation of MotionInpainter requires GPU");
|
||||||
#endif
|
#endif
|
||||||
setFlowErrorThreshold(1e-4f);
|
setFlowErrorThreshold(1e-4f);
|
||||||
|
setDistThreshold(5.f);
|
||||||
setBorderMode(BORDER_REPLICATE);
|
setBorderMode(BORDER_REPLICATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +354,8 @@ void MotionInpainter::inpaint(int idx, Mat &frame, Mat &mask)
|
|||||||
fmm_.run(flowMask_, body);
|
fmm_.run(flowMask_, body);
|
||||||
|
|
||||||
completeFrameAccordingToFlow(
|
completeFrameAccordingToFlow(
|
||||||
flowMask_, flowX_, flowY_, transformedFrame1_, transformedMask1_, frame, mask);
|
flowMask_, flowX_, flowY_, transformedFrame1_, transformedMask1_, distThresh_,
|
||||||
|
frame, mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +448,7 @@ void calcFlowMask(
|
|||||||
|
|
||||||
void completeFrameAccordingToFlow(
|
void completeFrameAccordingToFlow(
|
||||||
const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
|
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(flowMask.type() == CV_8U);
|
||||||
CV_Assert(flowX.type() == CV_32F && flowX.size() == flowMask.size());
|
CV_Assert(flowX.type() == CV_32F && flowX.size() == flowMask.size());
|
||||||
@ -459,6 +461,7 @@ void completeFrameAccordingToFlow(
|
|||||||
Mat_<uchar> flowMask_(flowMask), mask1_(mask1), mask0_(mask0);
|
Mat_<uchar> flowMask_(flowMask), mask1_(mask1), mask0_(mask0);
|
||||||
Mat_<float> flowX_(flowX), flowY_(flowY);
|
Mat_<float> flowX_(flowX), flowY_(flowY);
|
||||||
|
|
||||||
|
//int count = 0;
|
||||||
for (int y0 = 0; y0 < frame0.rows; ++y0)
|
for (int y0 = 0; y0 < frame0.rows; ++y0)
|
||||||
{
|
{
|
||||||
for (int x0 = 0; x0 < frame0.cols; ++x0)
|
for (int x0 = 0; x0 < frame0.cols; ++x0)
|
||||||
@ -468,14 +471,17 @@ void completeFrameAccordingToFlow(
|
|||||||
int x1 = cvRound(x0 + flowX_(y0,x0));
|
int x1 = cvRound(x0 + flowX_(y0,x0));
|
||||||
int y1 = cvRound(y0 + flowY_(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);
|
frame0.at<Point3_<uchar> >(y0,x0) = frame1.at<Point3_<uchar> >(y1,x1);
|
||||||
mask0_(y0,x0) = 255;
|
mask0_(y0,x0) = 255;
|
||||||
|
//count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//cout << count << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace videostab
|
} // namespace videostab
|
||||||
|
@ -57,40 +57,42 @@ void printHelp()
|
|||||||
" Outliers ratio in motion estimation. The default is 0.5.\n"
|
" Outliers ratio in motion estimation. The default is 0.5.\n"
|
||||||
" --min-inlier-ratio=<float_number>\n"
|
" --min-inlier-ratio=<float_number>\n"
|
||||||
" Minimum inlier ratio to decide if estimated motion is OK. The default is 0.1,\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"
|
" -r, --radius=<int_number>\n"
|
||||||
" Set smoothing radius. The default is 15.\n"
|
" Set smoothing radius. The default is 15.\n"
|
||||||
" --stdev=<float_number>\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"
|
" --deblur=(yes|no)\n"
|
||||||
" Do deblurring.\n"
|
" Do deblurring.\n"
|
||||||
" --deblur-sens=<float_number>\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"
|
" -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"
|
" --est-trim=(yes|no)\n"
|
||||||
" Estimate trim ratio automatically. The default is yes (that leads to two passes,\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"
|
" you can turn it off if you want to use one pass only).\n"
|
||||||
" --incl-constr=(yes|no)\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"
|
" --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"
|
" --mosaic=(yes|no)\n"
|
||||||
" Do consistent mosaicing. The default is no.\n"
|
" Do consistent mosaicing. The default is no.\n"
|
||||||
" --mosaic-stdev=<float_number>\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"
|
" --motion-inpaint=(yes|no)\n"
|
||||||
" Do motion inpainting (requires GPU support). The default is 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"
|
" --color-inpaint=(no|average|ns|telea)\n"
|
||||||
" Do color inpainting. The defailt is no.\n"
|
" Do color inpainting. The defailt is no.\n"
|
||||||
" --color-inpaint-radius=<float_number>\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"
|
" -o, --output=<file_path>\n"
|
||||||
" Set output file path explicitely. The default is stabilized.avi.\n"
|
" Set output file path explicitely. The default is stabilized.avi.\n"
|
||||||
" --fps=<int_number>\n"
|
" --fps=<int_number>\n"
|
||||||
" Set output video FPS explicitely. By default the source FPS is used.\n"
|
" Set output video FPS explicitely. By default the source FPS is used.\n"
|
||||||
" -q, --quiet\n"
|
" -q, --quiet\n"
|
||||||
" Don't show output video frames.\n"
|
" Don't show output video frames.\n\n"
|
||||||
" -h, --help\n"
|
" -h, --help\n"
|
||||||
" Print help.\n"
|
" Print help.\n"
|
||||||
"\n";
|
"\n";
|
||||||
@ -117,6 +119,7 @@ int main(int argc, const char **argv)
|
|||||||
"{ | mosaic | | }"
|
"{ | mosaic | | }"
|
||||||
"{ | mosaic-stdev | | }"
|
"{ | mosaic-stdev | | }"
|
||||||
"{ | motion-inpaint | | }"
|
"{ | motion-inpaint | | }"
|
||||||
|
"{ | dist-thresh | | }"
|
||||||
"{ | color-inpaint | no | }"
|
"{ | color-inpaint | no | }"
|
||||||
"{ | color-inpaint-radius | | }"
|
"{ | color-inpaint-radius | | }"
|
||||||
"{ o | output | stabilized.avi | }"
|
"{ o | output | stabilized.avi | }"
|
||||||
@ -212,7 +215,12 @@ int main(int argc, const char **argv)
|
|||||||
inpainters->pushBack(inpainter);
|
inpainters->pushBack(inpainter);
|
||||||
}
|
}
|
||||||
if (cmd.get<string>("motion-inpaint") == "yes")
|
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").empty())
|
||||||
{
|
{
|
||||||
if (cmd.get<string>("color-inpaint") == "average")
|
if (cmd.get<string>("color-inpaint") == "average")
|
||||||
@ -254,7 +262,7 @@ int main(int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
catch (const exception &e)
|
catch (const exception &e)
|
||||||
{
|
{
|
||||||
cout << e.what() << endl;
|
cout << "error: " << e.what() << endl;
|
||||||
stabilizer.release();
|
stabilizer.release();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user