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
70803dff
Commit
70803dff
authored
Jul 02, 2014
by
Alex Leontiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vadim
parent
c019f0a8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
56 deletions
+42
-56
TLD.cpp
modules/tracking/src/TLD.cpp
+27
-22
TLD.hpp
modules/tracking/src/TLD.hpp
+5
-5
trackerTLD.cpp
modules/tracking/src/trackerTLD.cpp
+10
-29
No files found.
modules/tracking/src/TLD.cpp
View file @
70803dff
...
...
@@ -181,23 +181,23 @@ double variance(const Mat& img){
p2
/=
(
img
.
cols
*
img
.
rows
);
return
p2
-
p
*
p
;
}
double
variance
(
Mat_
<
unsigned
int
>&
intImgP
,
Mat_
<
unsigned
int
>&
intImgP2
,
Rect
box
){
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
);
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
;
unsigned
int
A
,
B
,
C
,
D
;
double
A
,
B
,
C
,
D
;
A
=
((
y
>
0
&&
x
>
0
)
?
intImgP
(
y
-
1
,
x
-
1
)
:
0
);
B
=
((
y
>
0
)
?
intImgP
(
y
-
1
,
x
+
width
-
1
)
:
0
);
C
=
((
x
>
0
)
?
intImgP
(
y
+
height
-
1
,
x
-
1
)
:
0
);
D
=
intImgP
(
y
+
height
-
1
,
x
+
width
-
1
);
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
=
((
y
>
0
&&
x
>
0
)
?
intImgP2
(
y
-
1
,
x
-
1
)
:
0
);
B
=
((
y
>
0
)
?
intImgP2
(
y
-
1
,
x
+
width
-
1
)
:
0
);
C
=
((
x
>
0
)
?
intImgP2
(
y
+
height
-
1
,
x
-
1
)
:
0
);
D
=
intImgP2
(
y
+
height
-
1
,
x
+
width
-
1
);
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
;
...
...
@@ -253,11 +253,10 @@ void resample(const Mat& img,const Rect2d& r2,Mat_<uchar>& samples){
M
(
0
,
0
)
=
(
float
)(
samples
.
cols
/
r2
.
width
);
M
(
0
,
1
)
=
0.0
f
;
M
(
0
,
2
)
=
(
float
)(
-
r2
.
x
*
samples
.
cols
/
r2
.
width
);
M
(
1
,
0
)
=
0.0
f
;
M
(
1
,
1
)
=
(
float
)(
samples
.
rows
/
r2
.
height
);
M
(
1
,
2
)
=
(
float
)(
-
r2
.
y
*
samples
.
rows
/
r2
.
height
);
warpAffine
(
img
,
samples
,
M
,
samples
.
size
());
}
//other stuff
void
TLDEnsembleClassifier
::
stepPrefSuff
(
uchar
*
arr
,
int
len
){
void
TLDEnsembleClassifier
::
stepPrefSuff
(
std
::
vector
<
uchar
>&
arr
,
int
len
){
int
gridSize
=
getGridSize
();
#if 0
int step=len/(gridSize-1), pref=(len-step*(gridSize-1))/2;
...
...
@@ -270,7 +269,7 @@ void TLDEnsembleClassifier::stepPrefSuff(uchar* arr,int len){
int
smallStep
=
quo
,
bigStep
=
quo
+
1
;
int
bigOnes
=
rem
,
smallOnes
=
gridSize
-
bigOnes
-
1
;
int
bigOnes_front
=
bigOnes
/
2
,
bigOnes_back
=
bigOnes
-
bigOnes_front
;
for
(
int
i
=
0
;
i
<
(
int
)
(
sizeof
(
x1
)
/
sizeof
(
x1
[
0
])
);
i
++
){
for
(
int
i
=
0
;
i
<
(
int
)
arr
.
size
(
);
i
++
){
if
(
arr
[
i
]
<
bigOnes_back
){
arr
[
i
]
=
(
uchar
)(
arr
[
i
]
*
bigStep
+
arr
[
i
]);
continue
;
...
...
@@ -287,12 +286,23 @@ void TLDEnsembleClassifier::stepPrefSuff(uchar* arr,int len){
}
#endif
}
TLDEnsembleClassifier
::
TLDEnsembleClassifier
(
int
ordinal
,
Size
size
){
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
);
int
posSize
=
1
;
for
(
int
i
=
0
;
i
<
measurePerClassifier
;
i
++
)
posSize
*=
2
;
pos
=
std
::
vector
<
unsigned
int
>
(
posSize
,
0
);
neg
=
std
::
vector
<
unsigned
int
>
(
posSize
,
0
);
}
void
TLDEnsembleClassifier
::
integrate
(
Mat_
<
uchar
>
patch
,
bool
isPositive
){
unsigned
short
int
position
=
code
(
patch
.
data
,(
int
)
patch
.
step
[
0
]);
...
...
@@ -313,18 +323,13 @@ double TLDEnsembleClassifier::posteriorProbability(const uchar* data,int rowstep
}
unsigned
short
int
TLDEnsembleClassifier
::
code
(
const
uchar
*
data
,
int
rowstep
)
const
{
unsigned
short
int
position
=
0
;
//char codeS[20];
for
(
int
i
=
0
;
i
<
(
int
)(
sizeof
(
x1
)
/
sizeof
(
x1
[
0
]));
i
++
){
for
(
int
i
=
0
;
i
<
(
int
)
x1
.
size
();
i
++
){
position
=
position
<<
1
;
if
(
*
(
data
+
rowstep
*
y1
[
i
]
+
x1
[
i
])
<*
(
data
+
rowstep
*
y2
[
i
]
+
x2
[
i
])){
position
++
;
//codeS[i]='o';
}
else
{
//codeS[i]='x';
}
}
//codeS[13]='\0';
//dprintf(("integrate with code %s\n",codeS));
return
position
;
}
...
...
modules/tracking/src/TLD.hpp
View file @
70803dff
...
...
@@ -79,7 +79,7 @@ double overlap(const Rect2d& r1,const Rect2d& r2);
void
resample
(
const
Mat
&
img
,
const
RotatedRect
&
r2
,
Mat_
<
uchar
>&
samples
);
void
resample
(
const
Mat
&
img
,
const
Rect2d
&
r2
,
Mat_
<
uchar
>&
samples
);
double
variance
(
const
Mat
&
img
);
double
variance
(
Mat_
<
unsigned
int
>&
intImgP
,
Mat_
<
unsigned
int
>&
intImgP2
,
Rect
box
);
double
variance
(
Mat_
<
double
>&
intImgP
,
Mat_
<
double
>&
intImgP2
,
Rect
box
);
double
NCC
(
Mat_
<
uchar
>
patch1
,
Mat_
<
uchar
>
patch2
);
void
getClosestN
(
std
::
vector
<
Rect2d
>&
scanGrid
,
Rect2d
bBox
,
int
n
,
std
::
vector
<
Rect2d
>&
res
);
double
scaleAndBlur
(
const
Mat
&
originalImg
,
int
scale
,
Mat
&
scaledImg
,
Mat
&
blurredImg
,
Size
GaussBlurKernelSize
);
...
...
@@ -87,17 +87,17 @@ unsigned int getMedian(const std::vector<unsigned int>& values, int size=-1);
class
TLDEnsembleClassifier
{
public
:
TLDEnsembleClassifier
(
int
ordinal
,
Size
size
);
TLDEnsembleClassifier
(
int
ordinal
,
Size
size
,
int
measurePerClassifier
);
void
integrate
(
Mat_
<
uchar
>
patch
,
bool
isPositive
);
double
posteriorProbability
(
const
uchar
*
data
,
int
rowstep
)
const
;
static
int
getMaxOrdinal
();
private
:
static
int
getGridSize
();
inline
void
stepPrefSuff
(
uchar
*
arr
,
int
len
);
inline
void
stepPrefSuff
(
std
::
vector
<
uchar
>&
arr
,
int
len
);
void
preinit
(
int
ordinal
);
unsigned
short
int
code
(
const
uchar
*
data
,
int
rowstep
)
const
;
unsigned
int
pos
[
8192
],
neg
[
8192
];
//8192=2^13
uchar
x1
[
13
],
y1
[
13
],
x2
[
13
],
y2
[
13
]
;
std
::
vector
<
unsigned
int
>
pos
,
neg
;
std
::
vector
<
uchar
>
x1
,
y1
,
x2
,
y2
;
};
class
TrackerProxy
:
public
TrackerTLD
::
Private
{
...
...
modules/tracking/src/trackerTLD.cpp
View file @
70803dff
...
...
@@ -52,6 +52,7 @@
#define CORE_THRESHOLD 0.5
#define NEG_EXAMPLES_IN_INIT_MODEL 300
#define MAX_EXAMPLES_IN_MODEL 500
#define MEASURES_PER_CLASSIFIER 13
static
const
cv
::
Size
GaussBlurKernelSize
(
3
,
3
);
using
namespace
cv
;
...
...
@@ -65,19 +66,14 @@ using namespace tld;
* THETA_NN 0.5<->0.6 dramatic change vs video 6 !!
* TODO:
* schoolPC: codec, libopencv-dev
* fix pushbot ->pick commits -> compare_branches->all in 1
* ||video(0.5<->0.6) --> debug if box size is less than 20 --> (remove ensemble self-loop) --> (try inter_area)
* fix pushbot ->pick commits -> compare_branches->all in 1
->resubmit
* ||video(0.5<->0.6) --> debug if box size is less than 20 --> (remove ensemble self-loop) --> (try inter_area
for resize
)
* perfect PN
*
* vadim:
*
* private members
*
* cv::integral
*
* 13 as enum
*
* blurred in TrackerTLDModel()
* private members
*
* warpAffine -- ?
*/
...
...
@@ -129,8 +125,8 @@ public:
protected
:
friend
class
MyMouseCallbackDEBUG
;
Ptr
<
TrackerModel
>
model
;
void
computeIntegralImages
(
const
Mat
&
img
,
Mat_
<
unsigned
int
>&
intImgP
,
Mat_
<
unsigned
int
>&
intImgP2
);
bool
patchVariance
(
Mat_
<
unsigned
int
>&
intImgP
,
Mat_
<
unsigned
int
>&
intImgP2
,
double
originalVariance
,
Point
pt
,
Size
size
);
inline
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
;}
double
ensembleClassifierNum
(
const
uchar
*
data
,
int
rowstep
);
TrackerTLD
::
Params
params_
;
...
...
@@ -406,7 +402,7 @@ timeStampPositiveNext(0),timeStampNegativeNext(0),params_(params){
Mat_
<
uchar
>
blurredPatch
(
minSize
);
for
(
int
i
=
0
,
howMany
=
TLDEnsembleClassifier
::
getMaxOrdinal
();
i
<
howMany
;
i
++
){
classifiers
.
push_back
(
TLDEnsembleClassifier
(
i
+
1
,
minSize
));
classifiers
.
push_back
(
TLDEnsembleClassifier
(
i
+
1
,
minSize
,
MEASURES_PER_CLASSIFIER
));
}
positiveExamples
.
reserve
(
200
);
...
...
@@ -507,7 +503,7 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v
Rect2d
maxScRect
;
START_TICK
(
"detector"
);
do
{
Mat_
<
unsigned
int
>
intImgP
(
resized_img
.
rows
,
resized_img
.
cols
),
intImgP2
(
resized_img
.
rows
,
resized_img
.
cols
)
;
Mat_
<
double
>
intImgP
,
intImgP2
;
computeIntegralImages
(
resized_img
,
intImgP
,
intImgP2
);
for
(
int
i
=
0
,
imax
=
cvFloor
((
0.0
+
resized_img
.
cols
-
initSize
.
width
)
/
dx
);
i
<
imax
;
i
++
){
...
...
@@ -595,22 +591,7 @@ bool TLDDetector::detect(const Mat& img,const Mat& imgBlurred,Rect2d& res,std::v
return
true
;
}
void
TLDDetector
::
computeIntegralImages
(
const
Mat
&
img
,
Mat_
<
unsigned
int
>&
intImgP
,
Mat_
<
unsigned
int
>&
intImgP2
){
intImgP
(
0
,
0
)
=
img
.
at
<
uchar
>
(
0
,
0
);
for
(
int
j
=
1
;
j
<
intImgP
.
cols
;
j
++
){
intImgP
(
0
,
j
)
=
intImgP
(
0
,
j
-
1
)
+
img
.
at
<
uchar
>
(
0
,
j
);}
for
(
int
i
=
1
;
i
<
intImgP
.
rows
;
i
++
){
intImgP
(
i
,
0
)
=
intImgP
(
i
-
1
,
0
)
+
img
.
at
<
uchar
>
(
i
,
0
);}
for
(
int
i
=
1
;
i
<
intImgP
.
rows
;
i
++
){
for
(
int
j
=
1
;
j
<
intImgP
.
cols
;
j
++
){
intImgP
(
i
,
j
)
=
intImgP
(
i
,
j
-
1
)
-
intImgP
(
i
-
1
,
j
-
1
)
+
intImgP
(
i
-
1
,
j
)
+
img
.
at
<
uchar
>
(
i
,
j
);}}
unsigned
int
p
;
p
=
img
.
at
<
uchar
>
(
0
,
0
);
intImgP2
(
0
,
0
)
=
p
*
p
;
for
(
int
j
=
1
;
j
<
intImgP2
.
cols
;
j
++
){
p
=
img
.
at
<
uchar
>
(
0
,
j
);
intImgP2
(
0
,
j
)
=
intImgP2
(
0
,
j
-
1
)
+
p
*
p
;}
for
(
int
i
=
1
;
i
<
intImgP2
.
rows
;
i
++
){
p
=
img
.
at
<
uchar
>
(
i
,
0
);
intImgP2
(
i
,
0
)
=
intImgP2
(
i
-
1
,
0
)
+
p
*
p
;}
for
(
int
i
=
1
;
i
<
intImgP2
.
rows
;
i
++
){
for
(
int
j
=
1
;
j
<
intImgP2
.
cols
;
j
++
){
p
=
img
.
at
<
uchar
>
(
i
,
j
);
intImgP2
(
i
,
j
)
=
intImgP2
(
i
,
j
-
1
)
-
intImgP2
(
i
-
1
,
j
-
1
)
+
intImgP2
(
i
-
1
,
j
)
+
p
*
p
;}}
}
bool
TLDDetector
::
patchVariance
(
Mat_
<
unsigned
int
>&
intImgP
,
Mat_
<
unsigned
int
>&
intImgP2
,
double
originalVariance
,
Point
pt
,
Size
size
){
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
;
}
...
...
@@ -818,7 +799,7 @@ void MyMouseCallbackDEBUG::onMouse( int event, int x, int y){
resize
(
img_
,
resized_img
,
size
);
resize
(
imgBlurred_
,
blurred_img
,
size
);
Mat_
<
unsigned
int
>
intImgP
(
resized_img
.
rows
,
resized_img
.
cols
),
intImgP2
(
resized_img
.
rows
,
resized_img
.
cols
)
;
Mat_
<
double
>
intImgP
,
intImgP2
;
detector_
->
computeIntegralImages
(
resized_img
,
intImgP
,
intImgP2
);
int
dx
=
initSize
.
width
/
10
,
dy
=
initSize
.
height
/
10
,
...
...
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