提交 36ef5998 编写于 作者: A Alexey Spizhevoy

Fixed trim ratio estimation for the case of homographies motion model (videostab)

上级 ae8d3775
...@@ -616,11 +616,15 @@ static inline bool isGoodMotion(const float M[], float w, float h, float dx, flo ...@@ -616,11 +616,15 @@ static inline bool isGoodMotion(const float M[], float w, float h, float dx, flo
{ {
Point2f pt[4] = {Point2f(0,0), Point2f(w,0), Point2f(w,h), Point2f(0,h)}; Point2f pt[4] = {Point2f(0,0), Point2f(w,0), Point2f(w,h), Point2f(0,h)};
Point2f Mpt[4]; Point2f Mpt[4];
float z;
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
Mpt[i].x = M[0]*pt[i].x + M[1]*pt[i].y + M[2]; Mpt[i].x = M[0]*pt[i].x + M[1]*pt[i].y + M[2];
Mpt[i].y = M[3]*pt[i].x + M[4]*pt[i].y + M[5]; Mpt[i].y = M[3]*pt[i].x + M[4]*pt[i].y + M[5];
z = M[6]*pt[i].x + M[7]*pt[i].y + M[8];
Mpt[i].x /= z;
Mpt[i].y /= z;
} }
pt[0] = Point2f(dx, dy); pt[0] = Point2f(dx, dy);
...@@ -640,6 +644,9 @@ static inline void relaxMotion(const float M[], float t, float res[]) ...@@ -640,6 +644,9 @@ static inline void relaxMotion(const float M[], float t, float res[])
res[3] = M[3]*(1.f-t); res[3] = M[3]*(1.f-t);
res[4] = M[4]*(1.f-t) + t; res[4] = M[4]*(1.f-t) + t;
res[5] = M[5]*(1.f-t); res[5] = M[5]*(1.f-t);
res[6] = M[6]*(1.f-t);
res[7] = M[7]*(1.f-t);
res[8] = M[8]*(1.f-t) + t;
} }
...@@ -651,11 +658,12 @@ Mat ensureInclusionConstraint(const Mat &M, Size size, float trimRatio) ...@@ -651,11 +658,12 @@ Mat ensureInclusionConstraint(const Mat &M, Size size, float trimRatio)
const float h = static_cast<float>(size.height); const float h = static_cast<float>(size.height);
const float dx = floor(w * trimRatio); const float dx = floor(w * trimRatio);
const float dy = floor(h * trimRatio); const float dy = floor(h * trimRatio);
const float srcM[6] = const float srcM[] =
{M.at<float>(0,0), M.at<float>(0,1), M.at<float>(0,2), {M.at<float>(0,0), M.at<float>(0,1), M.at<float>(0,2),
M.at<float>(1,0), M.at<float>(1,1), M.at<float>(1,2)}; M.at<float>(1,0), M.at<float>(1,1), M.at<float>(1,2),
M.at<float>(2,0), M.at<float>(2,1), M.at<float>(2,2)};
float curM[6]; float curM[9];
float t = 0; float t = 0;
relaxMotion(srcM, t, curM); relaxMotion(srcM, t, curM);
if (isGoodMotion(curM, w, h, dx, dy)) if (isGoodMotion(curM, w, h, dx, dy))
...@@ -687,11 +695,15 @@ float estimateOptimalTrimRatio(const Mat &M, Size size) ...@@ -687,11 +695,15 @@ float estimateOptimalTrimRatio(const Mat &M, Size size)
Point2f pt[4] = {Point2f(0,0), Point2f(w,0), Point2f(w,h), Point2f(0,h)}; Point2f pt[4] = {Point2f(0,0), Point2f(w,0), Point2f(w,h), Point2f(0,h)};
Point2f Mpt[4]; Point2f Mpt[4];
float z;
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
Mpt[i].x = M_(0,0)*pt[i].x + M_(0,1)*pt[i].y + M_(0,2); Mpt[i].x = M_(0,0)*pt[i].x + M_(0,1)*pt[i].y + M_(0,2);
Mpt[i].y = M_(1,0)*pt[i].x + M_(1,1)*pt[i].y + M_(1,2); Mpt[i].y = M_(1,0)*pt[i].x + M_(1,1)*pt[i].y + M_(1,2);
z = M_(2,0)*pt[i].x + M_(2,1)*pt[i].y + M_(2,2);
Mpt[i].x /= z;
Mpt[i].y /= z;
} }
float l = 0, r = 0.5f; float l = 0, r = 0.5f;
......
...@@ -95,15 +95,15 @@ void printHelp() ...@@ -95,15 +95,15 @@ void printHelp()
" (i.e. sqrt(radius)).\n" " (i.e. sqrt(radius)).\n"
" -lps, --lin-prog-stab=(yes|no)\n" " -lps, --lin-prog-stab=(yes|no)\n"
" Turn on/off linear programming based stabilization method.\n" " Turn on/off linear programming based stabilization method.\n"
" --lp-trim-ratio=(<float_number>|auto)\n" " --lps-trim-ratio=(<float_number>|auto)\n"
" Trimming ratio used in linear programming based method.\n" " Trimming ratio used in linear programming based method.\n"
" --lp-w1=(<float_number>|1)\n" " --lps-w1=(<float_number>|1)\n"
" 1st derivative weight. The default is 1.\n" " 1st derivative weight. The default is 1.\n"
" --lp-w2=(<float_number>|10)\n" " --lps-w2=(<float_number>|10)\n"
" 2nd derivative weight. The default is 10.\n" " 2nd derivative weight. The default is 10.\n"
" --lp-w3=(<float_number>|100)\n" " --lps-w3=(<float_number>|100)\n"
" 3rd derivative weight. The default is 100.\n" " 3rd derivative weight. The default is 100.\n"
" --lp-w4=(<float_number>|100)\n" " --lps-w4=(<float_number>|100)\n"
" Non-translation motion components weight. The default is 100.\n\n" " Non-translation motion components weight. The default is 100.\n\n"
" --deblur=(yes|no)\n" " --deblur=(yes|no)\n"
" Do deblurring.\n" " Do deblurring.\n"
...@@ -185,11 +185,11 @@ int main(int argc, const char **argv) ...@@ -185,11 +185,11 @@ int main(int argc, const char **argv)
"{ r | radius | 15 | }" "{ r | radius | 15 | }"
"{ | stdev | auto | }" "{ | stdev | auto | }"
"{ lps | lin-prog-stab | no | }" "{ lps | lin-prog-stab | no | }"
"{ | lp-trim-ratio | auto | }" "{ | lps-trim-ratio | auto | }"
"{ | lp-w1 | 1 | }" "{ | lps-w1 | 1 | }"
"{ | lp-w2 | 10 | }" "{ | lps-w2 | 10 | }"
"{ | lp-w3 | 100 | }" "{ | lps-w3 | 100 | }"
"{ | lp-w4 | 100 | }" "{ | lps-w4 | 100 | }"
"{ | deblur | no | }" "{ | deblur | no | }"
"{ | deblur-sens | 0.1 | }" "{ | deblur-sens | 0.1 | }"
"{ et | est-trim | yes | }" "{ et | est-trim | yes | }"
...@@ -260,11 +260,11 @@ int main(int argc, const char **argv) ...@@ -260,11 +260,11 @@ int main(int argc, const char **argv)
{ {
LpMotionStabilizer *stab = new LpMotionStabilizer(); LpMotionStabilizer *stab = new LpMotionStabilizer();
stab->setFrameSize(Size(source->width(), source->height())); stab->setFrameSize(Size(source->width(), source->height()));
stab->setTrimRatio(arg("lp-trim-ratio") == "auto" ? argf("trim-ratio") : argf("lp-trim-ratio")); stab->setTrimRatio(arg("lps-trim-ratio") == "auto" ? argf("trim-ratio") : argf("lps-trim-ratio"));
stab->setWeight1(argf("lp-w1")); stab->setWeight1(argf("lps-w1"));
stab->setWeight2(argf("lp-w2")); stab->setWeight2(argf("lps-w2"));
stab->setWeight3(argf("lp-w3")); stab->setWeight3(argf("lps-w3"));
stab->setWeight4(argf("lp-w4")); stab->setWeight4(argf("lps-w4"));
twoPassStabilizer->setMotionStabilizer(stab); twoPassStabilizer->setMotionStabilizer(stab);
} }
else if (arg("stdev") == "auto") else if (arg("stdev") == "auto")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册