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
7dca000b
Commit
7dca000b
authored
Aug 01, 2014
by
Alex Leontiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vadim 21
parent
2848831c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
18 deletions
+50
-18
tld_tracker.cpp
modules/tracking/src/tld_tracker.cpp
+12
-13
tld_tracker.hpp
modules/tracking/src/tld_tracker.hpp
+5
-0
tld_utils.cpp
modules/tracking/src/tld_utils.cpp
+33
-5
No files found.
modules/tracking/src/tld_tracker.cpp
View file @
7dca000b
...
...
@@ -88,14 +88,13 @@ using namespace tld;
*
* ?10. all in one class
*
* 21. precompute offset
* -->21. precompute offset
*
* 16. loops limits
* 17. inner scope loops
*/
/* design decisions:
* blur --> resize (vs. resize-->blur) in detect(), ensembleClassifier stage
* no random gauss noise, when making examples for ensembleClassifier
*/
namespace
cv
...
...
@@ -144,7 +143,6 @@ protected:
Ptr
<
TrackerModel
>
model
;
void
computeIntegralImages
(
const
Mat
&
img
,
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
){
integral
(
img
,
intImgP
,
intImgP2
,
CV_64F
);}
inline
bool
patchVariance
(
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
,
double
originalVariance
,
Point
pt
,
Size
size
);
inline
bool
ensembleClassifier
(
const
uchar
*
data
,
int
rowstep
);
TrackerTLD
::
Params
params_
;
};
...
...
@@ -200,13 +198,15 @@ class TrackerTLDModel : public TrackerModel{
Rect2d
getBoundingBox
(){
return
boundingBox_
;}
void
setBoudingBox
(
Rect2d
boundingBox
){
boundingBox_
=
boundingBox
;}
double
getOriginalVariance
(){
return
originalVariance_
;}
inline
double
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
);
inline
double
ensembleClassifierNum
(
const
uchar
*
data
);
inline
void
prepareClassifiers
(
int
rowstep
){
for
(
int
i
=
0
;
i
<
(
int
)
classifiers
.
size
();
i
++
)
classifiers
[
i
].
prepareClassifier
(
rowstep
);}
double
Sr
(
const
Mat_
<
uchar
>&
patch
);
double
Sc
(
const
Mat_
<
uchar
>&
patch
);
void
integrateRelabeled
(
Mat
&
img
,
Mat
&
imgBlurred
,
const
std
::
vector
<
TLDDetector
::
LabeledPatch
>&
patches
);
void
integrateAdditional
(
const
std
::
vector
<
Mat_
<
uchar
>
>&
eForModel
,
const
std
::
vector
<
Mat_
<
uchar
>
>&
eForEnsemble
,
bool
isPositive
);
Size
getMinSize
(){
return
minSize_
;}
void
printme
(
FILE
*
port
=
stdout
);
protected
:
Size
minSize_
;
unsigned
int
timeStampPositiveNext
,
timeStampNegativeNext
;
...
...
@@ -517,6 +517,7 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v
Mat_
<
double
>
intImgP
,
intImgP2
;
computeIntegralImages
(
resized_img
,
intImgP
,
intImgP2
);
tldModel
->
prepareClassifiers
((
int
)
blurred_img
.
step
[
0
]);
for
(
int
i
=
0
,
imax
=
cvFloor
((
0.0
+
resized_img
.
cols
-
initSize
.
width
)
/
dx
);
i
<
imax
;
i
++
){
for
(
int
j
=
0
,
jmax
=
cvFloor
((
0.0
+
resized_img
.
rows
-
initSize
.
height
)
/
dy
);
j
<
jmax
;
j
++
){
LabeledPatch
labPatch
;
...
...
@@ -524,7 +525,7 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v
if
(
!
patchVariance
(
intImgP
,
intImgP2
,
originalVariance
,
Point
(
dx
*
i
,
dy
*
j
),
initSize
)){
continue
;
}
if
(
!
ensembleClassifier
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
),(
int
)
blurred_img
.
step
[
0
]
)){
if
(
!
(
tldModel
->
ensembleClassifierNum
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
))
>
ENSEMBLE_THRESHOLD
)){
continue
;
}
pass
++
;
...
...
@@ -603,10 +604,10 @@ bool TLDDetector::patchVariance(Mat_<double>& intImgP,Mat_<double>& intImgP2,dou
return
((
p2
-
p
*
p
)
>
VARIANCE_THRESHOLD
*
originalVariance
);
}
double
TrackerTLDModel
::
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
){
double
TrackerTLDModel
::
ensembleClassifierNum
(
const
uchar
*
data
){
double
p
=
0
;
for
(
int
k
=
0
;
k
<
(
int
)
classifiers
.
size
();
k
++
){
p
+=
classifiers
[
k
].
posteriorProbability
(
data
,
rowstep
);
p
+=
classifiers
[
k
].
posteriorProbability
Fast
(
data
);
}
p
/=
classifiers
.
size
();
return
p
;
...
...
@@ -820,9 +821,10 @@ void MyMouseCallbackDEBUG::onMouse( int event, int x, int y){
i
=
(
int
)(
x
/
scale
/
dx
),
j
=
(
int
)(
y
/
scale
/
dy
);
dfprintf
((
stderr
,
"patchVariance=%s
\n
"
,(
detector_
->
patchVariance
(
intImgP
,
intImgP2
,
originalVariance
,
Point
(
dx
*
i
,
dy
*
j
),
initSize
))
?
"true"
:
"false"
));
dfprintf
((
stderr
,
"p=%f
\n
"
,(
tldModel
->
ensembleClassifierNum
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
),(
int
)
blurred_img
.
step
[
0
]))));
tldModel
->
prepareClassifiers
((
int
)
blurred_img
.
step
[
0
]);
dfprintf
((
stderr
,
"p=%f
\n
"
,(
tldModel
->
ensembleClassifierNum
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
)))));
fprintf
(
stderr
,
"ensembleClassifier=%s
\n
"
,
(
detector_
->
ensembleClassifier
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
),(
int
)
blurred_img
.
step
[
0
]
))
?
"true"
:
"false"
);
(
!
(
tldModel
->
ensembleClassifierNum
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
))
>
ENSEMBLE_THRESHOLD
))
?
"true"
:
"false"
);
resample
(
resized_img
,
Rect2d
(
Point
(
dx
*
i
,
dy
*
j
),
initSize
),
standardPatch
);
tmp
=
tldModel
->
Sr
(
standardPatch
);
...
...
@@ -859,8 +861,5 @@ void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example,bool positive){
}
(
*
proxyN
)
++
;
}
bool
TLDDetector
::
ensembleClassifier
(
const
uchar
*
data
,
int
rowstep
){
return
(((
TrackerTLDModel
*
)
static_cast
<
TrackerModel
*>
(
model
))
->
ensembleClassifierNum
(
data
,
rowstep
))
>
ENSEMBLE_THRESHOLD
;
}
}
/* namespace cv */
modules/tracking/src/tld_tracker.hpp
View file @
7dca000b
...
...
@@ -96,12 +96,17 @@ public:
static
int
makeClassifiers
(
Size
size
,
int
measurePerClassifier
,
int
gridSize
,
std
::
vector
<
TLDEnsembleClassifier
>&
classifiers
);
void
integrate
(
const
Mat_
<
uchar
>&
patch
,
bool
isPositive
);
double
posteriorProbability
(
const
uchar
*
data
,
int
rowstep
)
const
;
double
posteriorProbabilityFast
(
const
uchar
*
data
)
const
;
void
prepareClassifier
(
int
rowstep
);
private
:
TLDEnsembleClassifier
(
std
::
vector
<
Vec4b
>
meas
,
int
beg
,
int
end
);
static
void
stepPrefSuff
(
std
::
vector
<
Vec4b
>&
arr
,
int
pos
,
int
len
,
int
gridSize
);
int
code
(
const
uchar
*
data
,
int
rowstep
)
const
;
int
codeFast
(
const
uchar
*
data
)
const
;
std
::
vector
<
Point2i
>
posAndNeg
;
std
::
vector
<
Vec4b
>
measurements
;
std
::
vector
<
Point2i
>
offset
;
int
lastStep_
;
};
class
TrackerProxy
{
...
...
modules/tracking/src/tld_utils.cpp
View file @
7dca000b
...
...
@@ -268,11 +268,21 @@ void TLDEnsembleClassifier::stepPrefSuff(std::vector<Vec4b>& arr,int pos,int len
}
#endif
}
TLDEnsembleClassifier
::
TLDEnsembleClassifier
(
std
::
vector
<
Vec4b
>
meas
,
int
beg
,
int
end
){
int
posSize
=
1
;
for
(
int
i
=
0
,
mpc
=
end
-
beg
;
i
<
mpc
;
i
++
)
posSize
*=
2
;
void
TLDEnsembleClassifier
::
prepareClassifier
(
int
rowstep
){
if
(
lastStep_
!=
rowstep
){
lastStep_
=
rowstep
;
for
(
int
i
=
0
;
i
<
(
int
)
offset
.
size
();
i
++
){
offset
[
i
].
x
=
rowstep
*
measurements
[
i
].
val
[
0
]
+
measurements
[
i
].
val
[
1
];
offset
[
i
].
y
=
rowstep
*
measurements
[
i
].
val
[
2
]
+
measurements
[
i
].
val
[
3
];
}
}
}
TLDEnsembleClassifier
::
TLDEnsembleClassifier
(
std
::
vector
<
Vec4b
>
meas
,
int
beg
,
int
end
)
:
lastStep_
(
-
1
){
int
posSize
=
1
,
mpc
=
end
-
beg
;
for
(
int
i
=
0
;
i
<
mpc
;
i
++
)
posSize
*=
2
;
posAndNeg
.
assign
(
posSize
,
Point2i
(
0
,
0
));
measurements
.
assign
(
meas
.
begin
()
+
beg
,
meas
.
begin
()
+
end
);
offset
.
assign
(
mpc
,
Point2i
(
0
,
0
));
}
void
TLDEnsembleClassifier
::
integrate
(
const
Mat_
<
uchar
>&
patch
,
bool
isPositive
){
int
position
=
code
(
patch
.
data
,(
int
)
patch
.
step
[
0
]);
...
...
@@ -291,13 +301,31 @@ double TLDEnsembleClassifier::posteriorProbability(const uchar* data,int rowstep
return
posNum
/
(
posNum
+
negNum
);
}
}
double
TLDEnsembleClassifier
::
posteriorProbabilityFast
(
const
uchar
*
data
)
const
{
int
position
=
codeFast
(
data
);
double
posNum
=
(
double
)
posAndNeg
[
position
].
x
,
negNum
=
(
double
)
posAndNeg
[
position
].
y
;
if
(
posNum
==
0.0
&&
negNum
==
0.0
){
return
0.0
;
}
else
{
return
posNum
/
(
posNum
+
negNum
);
}
}
int
TLDEnsembleClassifier
::
codeFast
(
const
uchar
*
data
)
const
{
int
position
=
0
;
for
(
int
i
=
0
;
i
<
(
int
)
measurements
.
size
();
i
++
){
position
=
position
<<
1
;
if
(
data
[
offset
[
i
].
x
]
<
data
[
offset
[
i
].
y
]){
position
++
;
}
}
return
position
;
}
int
TLDEnsembleClassifier
::
code
(
const
uchar
*
data
,
int
rowstep
)
const
{
unsigned
short
int
position
=
0
;
int
position
=
0
;
for
(
int
i
=
0
;
i
<
(
int
)
measurements
.
size
();
i
++
){
position
=
position
<<
1
;
if
(
*
(
data
+
rowstep
*
measurements
[
i
].
val
[
0
]
+
measurements
[
i
].
val
[
1
])
<*
(
data
+
rowstep
*
measurements
[
i
].
val
[
2
]
+
measurements
[
i
].
val
[
3
])){
position
++
;
}
else
{
}
}
return
position
;
...
...
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