Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
afb9b954
Commit
afb9b954
authored
Jul 02, 2014
by
Ernest Galbrun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
performance issue when gamma=0
parent
f2e09d04
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
36 deletions
+37
-36
tvl1flow.cpp
modules/video/src/tvl1flow.cpp
+37
-36
No files found.
modules/video/src/tvl1flow.cpp
View file @
afb9b954
...
...
@@ -373,7 +373,7 @@ void OpticalFlowDual_TVL1::calc(InputArray _I0, InputArray _I1, InputOutputArray
CV_Assert
(
I0
.
type
()
==
I1
.
type
()
);
CV_Assert
(
!
useInitialFlow
||
(
_flow
.
size
()
==
I0
.
size
()
&&
_flow
.
type
()
==
CV_32FC2
)
);
CV_Assert
(
nscales
>
0
);
bool
use_gamma
=
gamma
!=
0
;
// allocate memory for the pyramid structure
dm
.
I0s
.
resize
(
nscales
);
dm
.
I1s
.
resize
(
nscales
);
...
...
@@ -386,7 +386,7 @@ void OpticalFlowDual_TVL1::calc(InputArray _I0, InputArray _I1, InputOutputArray
dm
.
u1s
[
0
].
create
(
I0
.
size
());
dm
.
u2s
[
0
].
create
(
I0
.
size
());
dm
.
u3s
[
0
].
create
(
I0
.
size
());
if
(
use_gamma
)
dm
.
u3s
[
0
].
create
(
I0
.
size
());
if
(
useInitialFlow
)
{
...
...
@@ -454,14 +454,14 @@ void OpticalFlowDual_TVL1::calc(InputArray _I0, InputArray _I1, InputOutputArray
dm
.
u1s
[
s
].
create
(
dm
.
I0s
[
s
].
size
());
dm
.
u2s
[
s
].
create
(
dm
.
I0s
[
s
].
size
());
}
dm
.
u3s
[
s
].
create
(
dm
.
I0s
[
s
].
size
());
if
(
use_gamma
)
dm
.
u3s
[
s
].
create
(
dm
.
I0s
[
s
].
size
());
}
if
(
!
useInitialFlow
)
{
dm
.
u1s
[
nscales
-
1
].
setTo
(
Scalar
::
all
(
0
));
dm
.
u2s
[
nscales
-
1
].
setTo
(
Scalar
::
all
(
0
));
}
dm
.
u3s
[
nscales
-
1
].
setTo
(
Scalar
::
all
(
0
));
if
(
use_gamma
)
dm
.
u3s
[
nscales
-
1
].
setTo
(
Scalar
::
all
(
0
));
// pyramidal structure for computing the optical flow
for
(
int
s
=
nscales
-
1
;
s
>=
0
;
--
s
)
{
...
...
@@ -477,7 +477,7 @@ void OpticalFlowDual_TVL1::calc(InputArray _I0, InputArray _I1, InputOutputArray
// zoom the optical flow for the next finer scale
resize
(
dm
.
u1s
[
s
],
dm
.
u1s
[
s
-
1
],
dm
.
I0s
[
s
-
1
].
size
());
resize
(
dm
.
u2s
[
s
],
dm
.
u2s
[
s
-
1
],
dm
.
I0s
[
s
-
1
].
size
());
resize
(
dm
.
u3s
[
s
],
dm
.
u3s
[
s
-
1
],
dm
.
I0s
[
s
-
1
].
size
());
if
(
use_gamma
)
resize
(
dm
.
u3s
[
s
],
dm
.
u3s
[
s
-
1
],
dm
.
I0s
[
s
-
1
].
size
());
// scale the optical flow with the appropriate zoom factor (don't scale u3!)
multiply
(
dm
.
u1s
[
s
-
1
],
Scalar
::
all
(
1
/
scaleStep
),
dm
.
u1s
[
s
-
1
]);
...
...
@@ -948,24 +948,25 @@ struct EstimateVBody : ParallelLoopBody
void
EstimateVBody
::
operator
()
(
const
Range
&
range
)
const
{
bool
use_gamma
=
gamma
!=
0
;
for
(
int
y
=
range
.
start
;
y
<
range
.
end
;
++
y
)
{
const
float
*
I1wxRow
=
I1wx
[
y
];
const
float
*
I1wyRow
=
I1wy
[
y
];
const
float
*
u1Row
=
u1
[
y
];
const
float
*
u2Row
=
u2
[
y
];
const
float
*
u3Row
=
u3
[
y
]
;
const
float
*
u3Row
=
use_gamma
?
u3
[
y
]
:
nullptr
;
const
float
*
gradRow
=
grad
[
y
];
const
float
*
rhoRow
=
rho_c
[
y
];
float
*
v1Row
=
v1
[
y
];
float
*
v2Row
=
v2
[
y
];
float
*
v3Row
=
v3
[
y
]
;
float
*
v3Row
=
use_gamma
?
v3
[
y
]
:
nullptr
;
for
(
int
x
=
0
;
x
<
I1wx
.
cols
;
++
x
)
{
const
float
rho
=
rhoRow
[
x
]
+
(
I1wxRow
[
x
]
*
u1Row
[
x
]
+
I1wyRow
[
x
]
*
u2Row
[
x
])
+
gamma
*
u3Row
[
x
];
const
float
rho
=
use_gamma
?
rhoRow
[
x
]
+
(
I1wxRow
[
x
]
*
u1Row
[
x
]
+
I1wyRow
[
x
]
*
u2Row
[
x
])
+
gamma
*
u3Row
[
x
]
:
rhoRow
[
x
]
+
(
I1wxRow
[
x
]
*
u1Row
[
x
]
+
I1wyRow
[
x
]
*
u2Row
[
x
]);
float
d1
=
0.0
f
;
float
d2
=
0.0
f
;
float
d3
=
0.0
f
;
...
...
@@ -974,25 +975,25 @@ void EstimateVBody::operator() (const Range& range) const
{
d1
=
l_t
*
I1wxRow
[
x
];
d2
=
l_t
*
I1wyRow
[
x
];
d3
=
l_t
*
gamma
;
if
(
use_gamma
)
d3
=
l_t
*
gamma
;
}
else
if
(
rho
>
l_t
*
gradRow
[
x
])
{
d1
=
-
l_t
*
I1wxRow
[
x
];
d2
=
-
l_t
*
I1wyRow
[
x
];
d3
=
-
l_t
*
gamma
;
if
(
use_gamma
)
d3
=
-
l_t
*
gamma
;
}
else
if
(
gradRow
[
x
]
>
std
::
numeric_limits
<
float
>::
epsilon
())
{
float
fi
=
-
rho
/
gradRow
[
x
];
d1
=
fi
*
I1wxRow
[
x
];
d2
=
fi
*
I1wyRow
[
x
];
d3
=
fi
*
gamma
;
if
(
use_gamma
)
d3
=
fi
*
gamma
;
}
v1Row
[
x
]
=
u1Row
[
x
]
+
d1
;
v2Row
[
x
]
=
u2Row
[
x
]
+
d2
;
v3Row
[
x
]
=
u3Row
[
x
]
+
d3
;
if
(
use_gamma
)
v3Row
[
x
]
=
u3Row
[
x
]
+
d3
;
}
}
}
...
...
@@ -1003,28 +1004,25 @@ void estimateV(const Mat_<float>& I1wx, const Mat_<float>& I1wy, const Mat_<floa
CV_DbgAssert
(
I1wy
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
u1
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
u2
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
u3
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
grad
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
rho_c
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
v1
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
v2
.
size
()
==
I1wx
.
size
()
);
CV_DbgAssert
(
v3
.
size
()
==
I1wx
.
size
()
);
EstimateVBody
body
;
bool
use_gamma
=
gamma
!=
0
;
body
.
I1wx
=
I1wx
;
body
.
I1wy
=
I1wy
;
body
.
u1
=
u1
;
body
.
u2
=
u2
;
body
.
u3
=
u3
;
if
(
use_gamma
)
body
.
u3
=
u3
;
body
.
grad
=
grad
;
body
.
rho_c
=
rho_c
;
body
.
v1
=
v1
;
body
.
v2
=
v2
;
body
.
v3
=
v3
;
if
(
use_gamma
)
body
.
v3
=
v3
;
body
.
l_t
=
l_t
;
body
.
gamma
=
gamma
;
parallel_for_
(
Range
(
0
,
I1wx
.
rows
),
body
);
}
...
...
@@ -1037,39 +1035,39 @@ float estimateU(const Mat_<float>& v1, const Mat_<float>& v2, const Mat_<float>&
float
theta
,
float
gamma
)
{
CV_DbgAssert
(
v2
.
size
()
==
v1
.
size
()
);
CV_DbgAssert
(
v3
.
size
()
==
v1
.
size
()
);
CV_DbgAssert
(
div_p1
.
size
()
==
v1
.
size
()
);
CV_DbgAssert
(
div_p2
.
size
()
==
v1
.
size
()
);
CV_DbgAssert
(
div_p3
.
size
()
==
v1
.
size
()
);
CV_DbgAssert
(
u1
.
size
()
==
v1
.
size
()
);
CV_DbgAssert
(
u2
.
size
()
==
v1
.
size
()
);
CV_DbgAssert
(
u3
.
size
()
==
v1
.
size
()
);
float
error
=
0.0
f
;
bool
use_gamma
=
gamma
!=
0
;
for
(
int
y
=
0
;
y
<
v1
.
rows
;
++
y
)
{
const
float
*
v1Row
=
v1
[
y
];
const
float
*
v2Row
=
v2
[
y
];
const
float
*
v3Row
=
v3
[
y
]
;
const
float
*
v3Row
=
use_gamma
?
v3
[
y
]
:
nullptr
;
const
float
*
divP1Row
=
div_p1
[
y
];
const
float
*
divP2Row
=
div_p2
[
y
];
const
float
*
divP3Row
=
div_p3
[
y
]
;
const
float
*
divP3Row
=
use_gamma
?
div_p3
[
y
]
:
nullptr
;
float
*
u1Row
=
u1
[
y
];
float
*
u2Row
=
u2
[
y
];
float
*
u3Row
=
u3
[
y
];
float
*
u3Row
=
use_gamma
?
u3
[
y
]
:
nullptr
;
for
(
int
x
=
0
;
x
<
v1
.
cols
;
++
x
)
{
const
float
u1k
=
u1Row
[
x
];
const
float
u2k
=
u2Row
[
x
];
const
float
u3k
=
u3Row
[
x
]
;
const
float
u3k
=
use_gamma
?
u3Row
[
x
]
:
0
;
u1Row
[
x
]
=
v1Row
[
x
]
+
theta
*
divP1Row
[
x
];
u2Row
[
x
]
=
v2Row
[
x
]
+
theta
*
divP2Row
[
x
];
u3Row
[
x
]
=
v3Row
[
x
]
+
theta
*
divP3Row
[
x
];
if
(
use_gamma
)
u3Row
[
x
]
=
v3Row
[
x
]
+
theta
*
divP3Row
[
x
];
error
+=
(
u1Row
[
x
]
-
u1k
)
*
(
u1Row
[
x
]
-
u1k
)
+
(
u2Row
[
x
]
-
u2k
)
*
(
u2Row
[
x
]
-
u2k
)
+
(
u3Row
[
x
]
-
u3k
)
*
(
u3Row
[
x
]
-
u3k
);
error
+=
use_gamma
?
(
u1Row
[
x
]
-
u1k
)
*
(
u1Row
[
x
]
-
u1k
)
+
(
u2Row
[
x
]
-
u2k
)
*
(
u2Row
[
x
]
-
u2k
)
+
(
u3Row
[
x
]
-
u3k
)
*
(
u3Row
[
x
]
-
u3k
)
:
(
u1Row
[
x
]
-
u1k
)
*
(
u1Row
[
x
]
-
u1k
)
+
(
u2Row
[
x
]
-
u2k
)
*
(
u2Row
[
x
]
-
u2k
);
}
}
...
...
@@ -1096,6 +1094,7 @@ struct EstimateDualVariablesBody : ParallelLoopBody
mutable
Mat_
<
float
>
p31
;
mutable
Mat_
<
float
>
p32
;
float
taut
;
bool
use_gamma
;
};
void
EstimateDualVariablesBody
::
operator
()
(
const
Range
&
range
)
const
...
...
@@ -1130,8 +1129,8 @@ void EstimateDualVariablesBody::operator() (const Range& range) const
p12Row
[
x
]
=
(
p12Row
[
x
]
+
taut
*
u1yRow
[
x
])
/
ng1
;
p21Row
[
x
]
=
(
p21Row
[
x
]
+
taut
*
u2xRow
[
x
])
/
ng2
;
p22Row
[
x
]
=
(
p22Row
[
x
]
+
taut
*
u2yRow
[
x
])
/
ng2
;
p31Row
[
x
]
=
(
p31Row
[
x
]
+
taut
*
u3xRow
[
x
])
/
ng3
;
p32Row
[
x
]
=
(
p32Row
[
x
]
+
taut
*
u3yRow
[
x
])
/
ng3
;
if
(
use_gamma
)
p31Row
[
x
]
=
(
p31Row
[
x
]
+
taut
*
u3xRow
[
x
])
/
ng3
;
if
(
use_gamma
)
p32Row
[
x
]
=
(
p32Row
[
x
]
+
taut
*
u3yRow
[
x
])
/
ng3
;
}
}
}
...
...
@@ -1142,7 +1141,7 @@ void estimateDualVariables(const Mat_<float>& u1x, const Mat_<float>& u1y,
Mat_
<
float
>&
p11
,
Mat_
<
float
>&
p12
,
Mat_
<
float
>&
p21
,
Mat_
<
float
>&
p22
,
Mat_
<
float
>&
p31
,
Mat_
<
float
>&
p32
,
float
taut
)
float
taut
,
bool
use_gamma
)
{
CV_DbgAssert
(
u1y
.
size
()
==
u1x
.
size
()
);
CV_DbgAssert
(
u2x
.
size
()
==
u1x
.
size
()
);
...
...
@@ -1171,6 +1170,7 @@ void estimateDualVariables(const Mat_<float>& u1x, const Mat_<float>& u1y,
body
.
p31
=
p31
;
body
.
p32
=
p32
;
body
.
taut
=
taut
;
body
.
use_gamma
=
use_gamma
;
parallel_for_
(
Range
(
0
,
u1x
.
rows
),
body
);
}
...
...
@@ -1300,8 +1300,9 @@ void OpticalFlowDual_TVL1::procOneScale(const Mat_<float>& I0, const Mat_<float>
p12
.
setTo
(
Scalar
::
all
(
0
));
p21
.
setTo
(
Scalar
::
all
(
0
));
p22
.
setTo
(
Scalar
::
all
(
0
));
p31
.
setTo
(
Scalar
::
all
(
0
));
p32
.
setTo
(
Scalar
::
all
(
0
));
bool
use_gamma
=
gamma
!=
0.
;
if
(
use_gamma
)
p31
.
setTo
(
Scalar
::
all
(
0
));
if
(
use_gamma
)
p32
.
setTo
(
Scalar
::
all
(
0
));
Mat_
<
float
>
div_p1
=
dm
.
div_p1_buf
(
Rect
(
0
,
0
,
I0
.
cols
,
I0
.
rows
));
Mat_
<
float
>
div_p2
=
dm
.
div_p2_buf
(
Rect
(
0
,
0
,
I0
.
cols
,
I0
.
rows
));
...
...
@@ -1342,7 +1343,7 @@ void OpticalFlowDual_TVL1::procOneScale(const Mat_<float>& I0, const Mat_<float>
// compute the divergence of the dual variable (p1, p2, p3)
divergence
(
p11
,
p12
,
div_p1
);
divergence
(
p21
,
p22
,
div_p2
);
divergence
(
p31
,
p32
,
div_p3
);
if
(
use_gamma
)
divergence
(
p31
,
p32
,
div_p3
);
// estimate the values of the optical flow (u1, u2)
error
=
estimateU
(
v1
,
v2
,
v3
,
div_p1
,
div_p2
,
div_p3
,
u1
,
u2
,
u3
,
static_cast
<
float
>
(
theta
),
gamma
);
...
...
@@ -1350,10 +1351,10 @@ void OpticalFlowDual_TVL1::procOneScale(const Mat_<float>& I0, const Mat_<float>
// compute the gradient of the optical flow (Du1, Du2)
forwardGradient
(
u1
,
u1x
,
u1y
);
forwardGradient
(
u2
,
u2x
,
u2y
);
forwardGradient
(
u3
,
u3x
,
u3y
);
if
(
use_gamma
)
forwardGradient
(
u3
,
u3x
,
u3y
);
// estimate the values of the dual variable (p1, p2, p3)
estimateDualVariables
(
u1x
,
u1y
,
u2x
,
u2y
,
u3x
,
u3y
,
p11
,
p12
,
p21
,
p22
,
p31
,
p32
,
taut
);
estimateDualVariables
(
u1x
,
u1y
,
u2x
,
u2y
,
u3x
,
u3y
,
p11
,
p12
,
p21
,
p22
,
p31
,
p32
,
taut
,
use_gamma
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment