Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
941865c9
Commit
941865c9
authored
Sep 07, 2017
by
Vladislav Sovrasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tracking: reduce useless computations in TLD
parent
62939e29
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
13 deletions
+47
-13
tldDetector.cpp
modules/tracking/src/tldDetector.cpp
+42
-13
tldDetector.hpp
modules/tracking/src/tldDetector.hpp
+5
-0
No files found.
modules/tracking/src/tldDetector.cpp
View file @
941865c9
...
...
@@ -65,6 +65,18 @@ namespace cv
return
p
;
}
double
TLDDetector
::
computeSminus
(
const
Mat_
<
uchar
>&
patch
)
const
{
double
sminus
=
0.0
;
Mat_
<
uchar
>
modelSample
(
STANDARD_PATCH_SIZE
,
STANDARD_PATCH_SIZE
);
for
(
int
i
=
0
;
i
<
*
negNum
;
i
++
)
{
modelSample
.
data
=
&
(
negExp
->
data
[
i
*
225
]);
sminus
=
std
::
max
(
sminus
,
0.5
*
(
tracking_internal
::
computeNCC
(
modelSample
,
patch
)
+
1.0
));
}
return
sminus
;
}
// Calculate Relative similarity of the patch (NN-Model)
double
TLDDetector
::
Sr
(
const
Mat_
<
uchar
>&
patch
)
const
{
...
...
@@ -75,17 +87,36 @@ namespace cv
modelSample
.
data
=
&
(
posExp
->
data
[
i
*
225
]);
splus
=
std
::
max
(
splus
,
0.5
*
(
tracking_internal
::
computeNCC
(
modelSample
,
patch
)
+
1.0
));
}
for
(
int
i
=
0
;
i
<
*
negNum
;
i
++
)
{
modelSample
.
data
=
&
(
negExp
->
data
[
i
*
225
]);
sminus
=
std
::
max
(
sminus
,
0.5
*
(
tracking_internal
::
computeNCC
(
modelSample
,
patch
)
+
1.0
));
}
sminus
=
computeSminus
(
patch
);
if
(
splus
+
sminus
==
0.0
)
return
0.0
;
return
splus
/
(
sminus
+
splus
);
}
std
::
pair
<
double
,
double
>
TLDDetector
::
SrAndSc
(
const
Mat_
<
uchar
>&
patch
)
const
{
double
splusC
=
0.0
,
sminus
=
0.0
,
splus
=
0.0
;
Mat_
<
uchar
>
modelSample
(
STANDARD_PATCH_SIZE
,
STANDARD_PATCH_SIZE
);
int
med
=
tracking_internal
::
getMedian
((
*
timeStampsPositive
));
for
(
int
i
=
0
;
i
<
*
posNum
;
i
++
)
{
modelSample
.
data
=
&
(
posExp
->
data
[
i
*
225
]);
double
s
=
0.5
*
(
tracking_internal
::
computeNCC
(
modelSample
,
patch
)
+
1.0
);
if
((
int
)(
*
timeStampsPositive
)[
i
]
<=
med
)
splusC
=
std
::
max
(
splusC
,
s
);
splus
=
std
::
max
(
splus
,
s
);
}
sminus
=
computeSminus
(
patch
);
double
sr
=
(
splus
+
sminus
==
0.0
)
?
0.
:
splus
/
(
sminus
+
splus
);
double
sc
=
(
splusC
+
sminus
==
0.0
)
?
0.
:
splusC
/
(
sminus
+
splusC
);
return
std
::
pair
<
double
,
double
>
(
sr
,
sc
);
}
#ifdef HAVE_OPENCL
double
TLDDetector
::
ocl_Sr
(
const
Mat_
<
uchar
>&
patch
)
{
...
...
@@ -205,11 +236,7 @@ namespace cv
splus
=
std
::
max
(
splus
,
0.5
*
(
tracking_internal
::
computeNCC
(
modelSample
,
patch
)
+
1.0
));
}
}
for
(
int
i
=
0
;
i
<
*
negNum
;
i
++
)
{
modelSample
.
data
=
&
(
negExp
->
data
[
i
*
225
]);
sminus
=
std
::
max
(
sminus
,
0.5
*
(
tracking_internal
::
computeNCC
(
modelSample
,
patch
)
+
1.0
));
}
sminus
=
computeSminus
(
patch
);
if
(
splus
+
sminus
==
0.0
)
return
0.0
;
...
...
@@ -317,9 +344,9 @@ namespace cv
resample
(
detectorF
->
resized_imgs
[
detectorF
->
ensScaleIDs
[
ind
]],
Rect2d
(
detectorF
->
ensBuffer
[
ind
],
initSizeF
),
detectorF
->
standardPatches
[
ind
]);
detectorF
->
scValues
[
ind
]
=
detectorF
->
Sc
(
detectorF
->
standardPatches
[
ind
])
;
detectorF
->
srValues
[
ind
]
=
detectorF
->
Sr
(
detectorF
->
standardPatches
[
ind
])
;
std
::
pair
<
double
,
double
>
values
=
detectorF
->
SrAndSc
(
detectorF
->
standardPatches
[
ind
]);
detectorF
->
scValues
[
ind
]
=
values
.
second
;
detectorF
->
srValues
[
ind
]
=
values
.
first
;
}
}
...
...
@@ -413,6 +440,8 @@ namespace cv
LabeledPatch
labPatch
;
double
curScale
=
pow
(
SCALE_STEP
,
ensScaleIDs
[
i
]);
labPatch
.
rect
=
Rect2d
(
ensBuffer
[
i
].
x
*
curScale
,
ensBuffer
[
i
].
y
*
curScale
,
initSize
.
width
*
curScale
,
initSize
.
height
*
curScale
);
labPatch
.
Sc
=
scValues
[
i
];
//printf("max sc %f\n", labPatch.Sc);
const
double
srValue
=
srValues
[
i
];
const
double
scValue
=
scValues
[
i
];
...
...
modules/tracking/src/tldDetector.hpp
View file @
941865c9
...
...
@@ -78,6 +78,7 @@ namespace cv
void
prepareClassifiers
(
int
rowstep
);
double
Sr
(
const
Mat_
<
uchar
>&
patch
)
const
;
double
Sc
(
const
Mat_
<
uchar
>&
patch
)
const
;
std
::
pair
<
double
,
double
>
SrAndSc
(
const
Mat_
<
uchar
>&
patch
)
const
;
#ifdef HAVE_OPENCL
double
ocl_Sr
(
const
Mat_
<
uchar
>&
patch
);
double
ocl_Sc
(
const
Mat_
<
uchar
>&
patch
);
...
...
@@ -102,6 +103,7 @@ namespace cv
{
Rect2d
rect
;
bool
isObject
,
shouldBeIntegrated
;
double
Sc
;
};
bool
detect
(
const
Mat
&
img
,
const
Mat
&
imgBlurred
,
Rect2d
&
res
,
std
::
vector
<
LabeledPatch
>&
patches
,
Size
initSize
);
bool
ocl_detect
(
const
Mat
&
img
,
const
Mat
&
imgBlurred
,
Rect2d
&
res
,
std
::
vector
<
LabeledPatch
>&
patches
,
Size
initSize
);
...
...
@@ -109,6 +111,9 @@ namespace cv
friend
class
MyMouseCallbackDEBUG
;
static
void
computeIntegralImages
(
const
Mat
&
img
,
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
){
integral
(
img
,
intImgP
,
intImgP2
,
CV_64F
);
}
static
inline
bool
patchVariance
(
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
,
double
*
originalVariance
,
Point
pt
,
Size
size
);
protected
:
double
computeSminus
(
const
Mat_
<
uchar
>&
patch
)
const
;
};
...
...
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