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
449eb346
Commit
449eb346
authored
Jul 31, 2014
by
Alex Leontiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vadim 18, 19
parent
b564f1b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
48 deletions
+46
-48
tld_tracker.cpp
modules/tracking/src/tld_tracker.cpp
+46
-24
tld_tracker.hpp
modules/tracking/src/tld_tracker.hpp
+0
-3
tld_utils.cpp
modules/tracking/src/tld_utils.cpp
+0
-21
No files found.
modules/tracking/src/tld_tracker.cpp
View file @
449eb346
...
...
@@ -80,19 +80,21 @@ using namespace tld;
* ||video(0.5<->0.6) --> debug if box size is less than 20
* perfect PN
*
* vadim:
* ?3. comment each function/method
* 5. empty lines to separate logical...
* 6. comment logical sections
* ?10. all in one class
* 11. group decls logically, order of statements
* 12. not v=vector(n), but assign(n,0)
* 16. loops limits
* 17. inner scope loops
* 19. var checker
* 20. NCC using plain loops
* 21. precompute offset
* 22. vec of structs (detect and beyond)
* vadim:
* ?3. comment each function/method
* 5. empty lines to separate logical...
* 6. comment logical sections
* 11. group decls logically, order of statements
*
* ?10. all in one class
*
* 16. loops limits
* 17. inner scope loops
*
* 12. not v=vector(n), but assign(n,0)
* 20. NCC using plain loops
* 21. precompute offset
* 22. vec of structs (detect and beyond)
*
*/
...
...
@@ -146,8 +148,7 @@ 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
);
bool
ensembleClassifier
(
const
uchar
*
data
,
int
rowstep
){
return
ensembleClassifierNum
(
data
,
rowstep
)
>
ENSEMBLE_THRESHOLD
;}
double
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
);
inline
bool
ensembleClassifier
(
const
uchar
*
data
,
int
rowstep
);
TrackerTLD
::
Params
params_
;
};
...
...
@@ -203,7 +204,7 @@ class TrackerTLDModel : public TrackerModel{
Rect2d
getBoundingBox
(){
return
boundingBox_
;}
void
setBoudingBox
(
Rect2d
boundingBox
){
boundingBox_
=
boundingBox
;}
double
getOriginalVariance
(){
return
originalVariance_
;}
std
::
vector
<
TLDEnsembleClassifier
>*
getClassifiers
(){
return
&
classifiers
;}
inline
double
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
);
double
Sr
(
const
Mat_
<
uchar
>&
patch
);
double
Sc
(
const
Mat_
<
uchar
>&
patch
);
void
integrateRelabeled
(
Mat
&
img
,
Mat
&
imgBlurred
,
const
std
::
vector
<
Rect2d
>&
box
,
const
std
::
vector
<
bool
>&
isPositive
,
...
...
@@ -584,18 +585,36 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v
return
true
;
}
/** Computes the variance of subimage given by box, with the help of two integral
* images intImgP and intImgP2 (sum of squares), which should be also provided.*/
bool
TLDDetector
::
patchVariance
(
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
,
double
originalVariance
,
Point
pt
,
Size
size
){
return
variance
(
intImgP
,
intImgP2
,
Rect
(
pt
.
x
,
pt
.
y
,
size
.
width
,
size
.
height
))
>=
VARIANCE_THRESHOLD
*
originalVariance
;
int
x
=
(
pt
.
x
),
y
=
(
pt
.
y
),
width
=
(
size
.
width
),
height
=
(
size
.
height
);
CV_Assert
(
0
<=
x
&&
(
x
+
width
)
<
intImgP
.
cols
&&
(
x
+
width
)
<
intImgP2
.
cols
);
CV_Assert
(
0
<=
y
&&
(
y
+
height
)
<
intImgP
.
rows
&&
(
y
+
height
)
<
intImgP2
.
rows
);
double
p
=
0
,
p2
=
0
;
double
A
,
B
,
C
,
D
;
A
=
intImgP
(
y
,
x
);
B
=
intImgP
(
y
,
x
+
width
);
C
=
intImgP
(
y
+
height
,
x
);
D
=
intImgP
(
y
+
height
,
x
+
width
);
p
=
(
0.0
+
A
+
D
-
B
-
C
)
/
(
width
*
height
);
A
=
intImgP2
(
y
,
x
);
B
=
intImgP2
(
y
,
x
+
width
);
C
=
intImgP2
(
y
+
height
,
x
);
D
=
intImgP2
(
y
+
height
,
x
+
width
);
p2
=
(
0.0
+
(
D
-
B
)
-
(
C
-
A
))
/
(
width
*
height
);
return
p2
-
p
*
p
;
}
double
TLDDetector
::
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
){
TrackerTLDModel
*
tldModel
=
((
TrackerTLDModel
*
)
static_cast
<
TrackerModel
*>
(
model
));
std
::
vector
<
TLDEnsembleClassifier
>*
classifiers
=
tldModel
->
getClassifiers
();
double
TrackerTLDModel
::
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
){
double
p
=
0
;
for
(
int
k
=
0
;
k
<
(
int
)
classifiers
->
size
();
k
++
){
p
+=
(
*
classifiers
)
[
k
].
posteriorProbability
(
data
,
rowstep
);
for
(
int
k
=
0
;
k
<
(
int
)
classifiers
.
size
();
k
++
){
p
+=
classifiers
[
k
].
posteriorProbability
(
data
,
rowstep
);
}
p
/=
classifiers
->
size
();
p
/=
classifiers
.
size
();
return
p
;
}
...
...
@@ -808,7 +827,7 @@ 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
"
,(
detector_
->
ensembleClassifierNum
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
),(
int
)
blurred_img
.
step
[
0
]))));
dfprintf
((
stderr
,
"p=%f
\n
"
,(
tldModel
->
ensembleClassifierNum
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
),(
int
)
blurred_img
.
step
[
0
]))));
fprintf
(
stderr
,
"ensembleClassifier=%s
\n
"
,
(
detector_
->
ensembleClassifier
(
&
blurred_img
.
at
<
uchar
>
(
dy
*
j
,
dx
*
i
),(
int
)
blurred_img
.
step
[
0
]))
?
"true"
:
"false"
);
...
...
@@ -847,5 +866,8 @@ 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 @
449eb346
...
...
@@ -84,9 +84,6 @@ void resample(const Mat& img,const RotatedRect& r2,Mat_<uchar>& samples);
void
resample
(
const
Mat
&
img
,
const
Rect2d
&
r2
,
Mat_
<
uchar
>&
samples
);
/** Computes the variance of single given image.*/
double
variance
(
const
Mat
&
img
);
/** Computes the variance of subimage given by box, with the help of two integral
* images intImgP and intImgP2 (sum of squares), which should be also provided.*/
double
variance
(
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
,
Rect
box
);
/** Computes normalized corellation coefficient between the two patches (they should be
* of the same size).*/
double
NCC
(
const
Mat_
<
uchar
>&
patch1
,
const
Mat_
<
uchar
>&
patch2
);
...
...
modules/tracking/src/tld_utils.cpp
View file @
449eb346
...
...
@@ -177,27 +177,6 @@ double variance(const Mat& img){
p2
/=
(
img
.
cols
*
img
.
rows
);
return
p2
-
p
*
p
;
}
double
variance
(
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
,
Rect
box
){
int
x
=
(
box
.
x
),
y
=
(
box
.
y
),
width
=
(
box
.
width
),
height
=
(
box
.
height
);
CV_Assert
(
0
<=
x
&&
(
x
+
width
)
<
intImgP
.
cols
&&
(
x
+
width
)
<
intImgP2
.
cols
);
CV_Assert
(
0
<=
y
&&
(
y
+
height
)
<
intImgP
.
rows
&&
(
y
+
height
)
<
intImgP2
.
rows
);
double
p
=
0
,
p2
=
0
;
double
A
,
B
,
C
,
D
;
A
=
intImgP
(
y
,
x
);
B
=
intImgP
(
y
,
x
+
width
);
C
=
intImgP
(
y
+
height
,
x
);
D
=
intImgP
(
y
+
height
,
x
+
width
);
p
=
(
0.0
+
A
+
D
-
B
-
C
)
/
(
width
*
height
);
A
=
intImgP2
(
y
,
x
);
B
=
intImgP2
(
y
,
x
+
width
);
C
=
intImgP2
(
y
+
height
,
x
);
D
=
intImgP2
(
y
+
height
,
x
+
width
);
p2
=
(
0.0
+
(
D
-
B
)
-
(
C
-
A
))
/
(
width
*
height
);
return
p2
-
p
*
p
;
}
double
NCC
(
const
Mat_
<
uchar
>&
patch1
,
const
Mat_
<
uchar
>&
patch2
){
CV_Assert
(
patch1
.
rows
==
patch2
.
rows
);
...
...
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