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
b564f1b6
Commit
b564f1b6
authored
Jul 31, 2014
by
Alex Leontiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vadim 14
parent
8c38fa76
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
41 deletions
+57
-41
tld_classifier.cpp
modules/tracking/src/tld_classifier.cpp
+0
-0
tld_tracker.cpp
modules/tracking/src/tld_tracker.cpp
+7
-8
tld_tracker.hpp
modules/tracking/src/tld_tracker.hpp
+5
-7
tld_utils.cpp
modules/tracking/src/tld_utils.cpp
+45
-26
No files found.
modules/tracking/src/tld_classifier.cpp
deleted
100644 → 0
View file @
8c38fa76
This source diff could not be displayed because it is too large. You can
view the blob
instead.
modules/tracking/src/tld_tracker.cpp
View file @
b564f1b6
...
...
@@ -55,6 +55,9 @@
#define MAX_EXAMPLES_IN_MODEL 500
#define MEASURES_PER_CLASSIFIER 13
#define SCALE_STEP 1.2
#define ENSEMBLE_THRESHOLD 0.5
#define VARIANCE_THRESHOLD 0.5
#define GRIDSIZE 15
#define DOWNSCALE_MODE INTER_LINEAR
#define BLUR_AS_VADIM
#undef CLOSED_LOOP
...
...
@@ -84,10 +87,8 @@ using namespace tld;
* ?10. all in one class
* 11. group decls logically, order of statements
* 12. not v=vector(n), but assign(n,0)
* -->14. TLDEnsembleClassifier
* 16. loops limits
* 17. inner scope loops
* 18. classify in TLDEnsembleClassifier
* 19. var checker
* 20. NCC using plain loops
* 21. precompute offset
...
...
@@ -145,7 +146,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
)
>
0.5
;}
bool
ensembleClassifier
(
const
uchar
*
data
,
int
rowstep
){
return
ensembleClassifierNum
(
data
,
rowstep
)
>
ENSEMBLE_THRESHOLD
;}
double
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
);
TrackerTLD
::
Params
params_
;
};
...
...
@@ -417,9 +418,7 @@ timeStampPositiveNext(0),timeStampNegativeNext(0),params_(params){
getClosestN
(
scanGrid
,
Rect2d
(
boundingBox
.
x
/
scale
,
boundingBox
.
y
/
scale
,
boundingBox
.
width
/
scale
,
boundingBox
.
height
/
scale
),
10
,
closest
);
Mat_
<
uchar
>
blurredPatch
(
minSize
);
for
(
int
i
=
0
,
howMany
=
TLDEnsembleClassifier
::
getMaxOrdinal
();
i
<
howMany
;
i
++
){
classifiers
.
push_back
(
TLDEnsembleClassifier
(
i
+
1
,
minSize
,
MEASURES_PER_CLASSIFIER
));
}
TLDEnsembleClassifier
::
makeClassifiers
(
minSize
,
MEASURES_PER_CLASSIFIER
,
GRIDSIZE
,
classifiers
);
positiveExamples
.
reserve
(
200
);
Point2f
center
;
...
...
@@ -586,7 +585,7 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v
}
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
))
>=
0.5
*
originalVariance
;
return
variance
(
intImgP
,
intImgP2
,
Rect
(
pt
.
x
,
pt
.
y
,
size
.
width
,
size
.
height
))
>=
VARIANCE_THRESHOLD
*
originalVariance
;
}
double
TLDDetector
::
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
){
...
...
@@ -694,7 +693,7 @@ void TrackerTLDModel::integrateAdditional(const std::vector<Mat_<uchar> >& eForM
p
+=
classifiers
[
i
].
posteriorProbability
(
eForEnsemble
[
k
].
data
,(
int
)
eForEnsemble
[
k
].
step
[
0
]);
}
p
/=
classifiers
.
size
();
if
((
p
>
0.5
)
!=
isPositive
){
if
((
p
>
ENSEMBLE_THRESHOLD
)
!=
isPositive
){
if
(
isPositive
){
positiveIntoEnsemble
++
;
}
else
{
...
...
modules/tracking/src/tld_tracker.hpp
View file @
b564f1b6
...
...
@@ -61,7 +61,7 @@ namespace cv {namespace tld
clock_t start;float milisec=0.0;\
start=clock();{a} milisec=1000.0*(clock()-start)/CLOCKS_PER_SEC;\
dprintf(("%-90s took %f milis\n",#a,milisec)); }
#define HERE dprintf(("%d\n",__LINE__));fflush(stderr);
#define HERE dprintf(("
line
%d\n",__LINE__));fflush(stderr);
#define START_TICK(name) { clock_t start;double milisec=0.0; start=clock();
#define END_TICK(name) milisec=1000.0*(clock()-start)/CLOCKS_PER_SEC;\
dprintf(("%s took %f milis\n",name,milisec)); }
...
...
@@ -96,17 +96,15 @@ unsigned int getMedian(const std::vector<unsigned int>& values, int size=-1);
class
TLDEnsembleClassifier
{
public
:
TLDEnsembleClassifier
(
int
ordinal
,
Size
size
,
int
measurePerClassifier
);
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
;
static
int
getMaxOrdinal
();
private
:
static
int
getGridSize
();
inline
void
stepPrefSuff
(
std
::
vector
<
uchar
>&
arr
,
int
len
);
void
preinit
(
int
ordinal
);
TLDEnsembleClassifier
(
std
::
vector
<
Vec4b
>
meas
,
int
beg
,
int
end
);
static
void
stepPrefSuff
(
std
::
vector
<
Vec4b
>&
arr
,
int
pos
,
int
len
,
int
gridSize
);
unsigned
short
int
code
(
const
uchar
*
data
,
int
rowstep
)
const
;
std
::
vector
<
unsigned
int
>
pos
,
neg
;
std
::
vector
<
uchar
>
x1
,
y1
,
x2
,
y2
;
std
::
vector
<
Vec4b
>
measurements
;
};
class
TrackerProxy
{
...
...
modules/tracking/src/tld_utils.cpp
View file @
b564f1b6
...
...
@@ -252,8 +252,7 @@ void resample(const Mat& img,const Rect2d& r2,Mat_<uchar>& samples){
}
//other stuff
void
TLDEnsembleClassifier
::
stepPrefSuff
(
std
::
vector
<
uchar
>&
arr
,
int
len
){
int
gridSize
=
getGridSize
();
void
TLDEnsembleClassifier
::
stepPrefSuff
(
std
::
vector
<
Vec4b
>&
arr
,
int
pos
,
int
len
,
int
gridSize
){
#if 0
int step=len/(gridSize-1), pref=(len-step*(gridSize-1))/2;
for(int i=0;i<(int)(sizeof(x1)/sizeof(x1[0]));i++){
...
...
@@ -266,39 +265,29 @@ void TLDEnsembleClassifier::stepPrefSuff(std::vector<uchar>& arr,int len){
int
bigOnes
=
rem
,
smallOnes
=
gridSize
-
bigOnes
-
1
;
int
bigOnes_front
=
bigOnes
/
2
,
bigOnes_back
=
bigOnes
-
bigOnes_front
;
for
(
int
i
=
0
;
i
<
(
int
)
arr
.
size
();
i
++
){
if
(
arr
[
i
]
<
bigOnes_back
){
arr
[
i
]
=
(
uchar
)(
arr
[
i
]
*
bigStep
+
arr
[
i
]);
if
(
arr
[
i
]
.
val
[
pos
]
<
bigOnes_back
){
arr
[
i
]
.
val
[
pos
]
=
(
uchar
)(
arr
[
i
].
val
[
pos
]
*
bigStep
+
arr
[
i
].
val
[
pos
]);
continue
;
}
if
(
arr
[
i
]
<
(
bigOnes_front
+
smallOnes
)){
arr
[
i
]
=
(
uchar
)(
bigOnes_front
*
bigStep
+
(
arr
[
i
]
-
bigOnes_front
)
*
smallStep
+
arr
[
i
]);
if
(
arr
[
i
]
.
val
[
pos
]
<
(
bigOnes_front
+
smallOnes
)){
arr
[
i
]
.
val
[
pos
]
=
(
uchar
)(
bigOnes_front
*
bigStep
+
(
arr
[
i
].
val
[
pos
]
-
bigOnes_front
)
*
smallStep
+
arr
[
i
].
val
[
pos
]);
continue
;
}
if
(
arr
[
i
]
<
(
bigOnes_front
+
smallOnes
+
bigOnes_back
)){
arr
[
i
]
=
(
uchar
)(
bigOnes_front
*
bigStep
+
smallOnes
*
smallStep
+
(
arr
[
i
]
-
(
bigOnes_front
+
smallOnes
))
*
bigStep
+
arr
[
i
]);
if
(
arr
[
i
].
val
[
pos
]
<
(
bigOnes_front
+
smallOnes
+
bigOnes_back
)){
arr
[
i
].
val
[
pos
]
=
(
uchar
)(
bigOnes_front
*
bigStep
+
smallOnes
*
smallStep
+
(
arr
[
i
].
val
[
pos
]
-
(
bigOnes_front
+
smallOnes
))
*
bigStep
+
arr
[
i
].
val
[
pos
]);
continue
;
}
arr
[
i
]
=
(
uchar
)(
len
-
1
);
arr
[
i
]
.
val
[
pos
]
=
(
uchar
)(
len
-
1
);
}
#endif
}
TLDEnsembleClassifier
::
TLDEnsembleClassifier
(
int
ordinal
,
Size
size
,
int
measurePerClassifier
){
x1
=
std
::
vector
<
uchar
>
(
measurePerClassifier
,
0
);
x2
=
std
::
vector
<
uchar
>
(
measurePerClassifier
,
0
);
y1
=
std
::
vector
<
uchar
>
(
measurePerClassifier
,
0
);
y2
=
std
::
vector
<
uchar
>
(
measurePerClassifier
,
0
);
preinit
(
ordinal
);
stepPrefSuff
(
x1
,
size
.
width
);
stepPrefSuff
(
x2
,
size
.
width
);
stepPrefSuff
(
y1
,
size
.
height
);
stepPrefSuff
(
y2
,
size
.
height
);
TLDEnsembleClassifier
::
TLDEnsembleClassifier
(
std
::
vector
<
Vec4b
>
meas
,
int
beg
,
int
end
){
int
posSize
=
1
;
for
(
int
i
=
0
;
i
<
measurePerClassifier
;
i
++
)
posSize
*=
2
;
for
(
int
i
=
0
,
mpc
=
end
-
beg
;
i
<
mpc
;
i
++
)
posSize
*=
2
;
pos
=
std
::
vector
<
unsigned
int
>
(
posSize
,
0
);
neg
=
std
::
vector
<
unsigned
int
>
(
posSize
,
0
);
measurements
.
assign
(
meas
.
begin
()
+
beg
,
meas
.
begin
()
+
end
);
}
void
TLDEnsembleClassifier
::
integrate
(
const
Mat_
<
uchar
>&
patch
,
bool
isPositive
){
unsigned
short
int
position
=
code
(
patch
.
data
,(
int
)
patch
.
step
[
0
]);
...
...
@@ -318,15 +307,45 @@ double TLDEnsembleClassifier::posteriorProbability(const uchar* data,int rowstep
}
}
unsigned
short
int
TLDEnsembleClassifier
::
code
(
const
uchar
*
data
,
int
rowstep
)
const
{
unsigned
short
int
position
=
0
;
for
(
int
i
=
0
;
i
<
(
int
)
x1
.
size
();
i
++
){
unsigned
short
int
position
=
0
;
//TODO: this --> encapsule
for
(
int
i
=
0
;
i
<
(
int
)
measurements
.
size
();
i
++
){
position
=
position
<<
1
;
if
(
*
(
data
+
rowstep
*
y1
[
i
]
+
x1
[
i
])
<*
(
data
+
rowstep
*
y2
[
i
]
+
x2
[
i
])){
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
;
}
int
TLDEnsembleClassifier
::
makeClassifiers
(
Size
size
,
int
measurePerClassifier
,
int
gridSize
,
std
::
vector
<
TLDEnsembleClassifier
>&
classifiers
){
std
::
vector
<
Vec4b
>
measurements
;
for
(
int
i
=
0
;
i
<
gridSize
;
i
++
){
for
(
int
j
=
0
;
j
<
gridSize
;
j
++
){
for
(
int
k
=
0
;
k
<
j
;
k
++
){
Vec4b
m
;
m
.
val
[
0
]
=
m
.
val
[
2
]
=
i
;
m
.
val
[
1
]
=
j
;
m
.
val
[
3
]
=
k
;
measurements
.
push_back
(
m
);
m
.
val
[
1
]
=
m
.
val
[
3
]
=
i
;
m
.
val
[
0
]
=
j
;
m
.
val
[
2
]
=
k
;
measurements
.
push_back
(
m
);
}
}
}
random_shuffle
(
measurements
.
begin
(),
measurements
.
end
());
stepPrefSuff
(
measurements
,
0
,
size
.
width
,
gridSize
);
stepPrefSuff
(
measurements
,
1
,
size
.
width
,
gridSize
);
stepPrefSuff
(
measurements
,
2
,
size
.
height
,
gridSize
);
stepPrefSuff
(
measurements
,
3
,
size
.
height
,
gridSize
);
for
(
int
i
=
0
,
howMany
=
measurements
.
size
()
/
measurePerClassifier
;
i
<
howMany
;
i
++
){
classifiers
.
push_back
(
TLDEnsembleClassifier
(
measurements
,
i
*
measurePerClassifier
,(
i
+
1
)
*
measurePerClassifier
));
}
return
(
int
)
classifiers
.
size
();
}
}}
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