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
c06bb0dc
Commit
c06bb0dc
authored
Jul 09, 2014
by
Alex Leontiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vadim
parent
296a864a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
59 deletions
+53
-59
tracker.hpp
modules/tracking/include/opencv2/tracking/tracker.hpp
+2
-22
TLD.hpp
modules/tracking/src/TLD.hpp
+1
-1
tracker.cpp
modules/tracking/src/tracker.cpp
+2
-0
trackerMedianFlow.cpp
modules/tracking/src/trackerMedianFlow.cpp
+18
-26
trackerTLD.cpp
modules/tracking/src/trackerTLD.cpp
+30
-10
No files found.
modules/tracking/include/opencv2/tracking/tracker.hpp
View file @
c06bb0dc
...
...
@@ -1022,16 +1022,7 @@ class CV_EXPORTS_W TrackerMedianFlow : public Tracker
void
write
(
FileStorage
&
/*fs*/
)
const
;
};
TrackerMedianFlow
(
const
TrackerMedianFlow
::
Params
&
parameters
=
TrackerMedianFlow
::
Params
()
);
virtual
~
TrackerMedianFlow
();
void
read
(
const
FileNode
&
fn
);
void
write
(
FileStorage
&
fs
)
const
;
protected
:
bool
initImpl
(
const
Mat
&
image
,
const
Rect2d
&
boundingBox
);
bool
updateImpl
(
const
Mat
&
image
,
Rect2d
&
boundingBox
);
Params
params
;
AlgorithmInfo
*
info
()
const
;
BOILERPLATE_CODE
(
"MEDIANFLOW"
,
TrackerMedianFlow
);
};
class
CV_EXPORTS_W
TrackerTLD
:
public
Tracker
...
...
@@ -1044,18 +1035,7 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
void
write
(
FileStorage
&
/*fs*/
)
const
;
};
TrackerTLD
(
const
TrackerTLD
::
Params
&
parameters
=
TrackerTLD
::
Params
()
);
virtual
~
TrackerTLD
();
void
read
(
const
FileNode
&
fn
);
void
write
(
FileStorage
&
fs
)
const
;
class
Private
{
public
:
virtual
~
Private
(){}};
protected
:
bool
initImpl
(
const
Mat
&
image
,
const
Rect2d
&
boundingBox
);
bool
updateImpl
(
const
Mat
&
image
,
Rect2d
&
boundingBox
);
Params
params
;
std
::
vector
<
Ptr
<
Private
>
>
privateInfo
;
AlgorithmInfo
*
info
()
const
;
BOILERPLATE_CODE
(
"TLD"
,
TrackerTLD
);
};
}
/* namespace cv */
...
...
modules/tracking/src/TLD.hpp
View file @
c06bb0dc
...
...
@@ -100,7 +100,7 @@ private:
std
::
vector
<
uchar
>
x1
,
y1
,
x2
,
y2
;
};
class
TrackerProxy
:
public
TrackerTLD
::
Private
{
class
TrackerProxy
{
public
:
virtual
bool
init
(
const
Mat
&
image
,
const
Rect2d
&
boundingBox
)
=
0
;
virtual
bool
update
(
const
Mat
&
image
,
Rect2d
&
boundingBox
)
=
0
;
...
...
modules/tracking/src/tracker.cpp
View file @
c06bb0dc
...
...
@@ -112,6 +112,8 @@ Ptr<Tracker> Tracker::create( const String& trackerType )
{
BOILERPLATE_CODE
(
"MIL"
,
TrackerMIL
);
BOILERPLATE_CODE
(
"BOOSTING"
,
TrackerBoosting
);
BOILERPLATE_CODE
(
"MEDIANFLOW"
,
TrackerMedianFlow
);
BOILERPLATE_CODE
(
"TLD"
,
TrackerTLD
);
return
Ptr
<
Tracker
>
();
}
...
...
modules/tracking/src/trackerMedianFlow.cpp
View file @
c06bb0dc
...
...
@@ -74,9 +74,9 @@ namespace cv
* bring "out" all the parameters to TrackerMedianFlow::Param
*/
class
MedianFlowCore
{
class
TrackerMedianFlowImpl
:
public
TrackerMedianFlow
{
public
:
MedianFlowCore
(
TrackerMedianFlow
::
Params
paramsIn
)
:
termcrit
(
TermCriteria
::
COUNT
|
TermCriteria
::
EPS
,
20
,
0.3
){
params
=
paramsIn
;}
TrackerMedianFlowImpl
(
TrackerMedianFlow
::
Params
paramsIn
)
:
termcrit
(
TermCriteria
::
COUNT
|
TermCriteria
::
EPS
,
20
,
0.3
){
params
=
paramsIn
;
isInit
=
false
;}
bool
medianFlowImpl
(
Mat
oldImage
,
Mat
newImage
,
Rect2d
&
oldBox
);
private
:
Rect2d
vote
(
const
std
::
vector
<
Point2f
>&
oldPoints
,
const
std
::
vector
<
Point2f
>&
newPoints
,
const
Rect2d
&
oldRect
,
Point2f
&
mD
);
...
...
@@ -99,14 +99,12 @@ class MedianFlowCore{
class
TrackerMedianFlowModel
:
public
TrackerModel
{
public
:
TrackerMedianFlowModel
(
TrackerMedianFlow
::
Params
params
)
:
medianFlow
(
params
){}
MedianFlowCore
*
getMedianFlowCore
(){
return
&
medianFlow
;}
TrackerMedianFlowModel
(
TrackerMedianFlow
::
Params
/*params*/
){}
Rect2d
getBoundingBox
(){
return
boundingBox_
;}
void
setBoudingBox
(
Rect2d
boundingBox
){
boundingBox_
=
boundingBox
;}
Mat
getImage
(){
return
image_
;}
void
setImage
(
const
Mat
&
image
){
image
.
copyTo
(
image_
);}
protected
:
MedianFlowCore
medianFlow
;
Rect2d
boundingBox_
;
Mat
image_
;
void
modelEstimationImpl
(
const
std
::
vector
<
Mat
>&
/*responses*/
){}
...
...
@@ -128,38 +126,32 @@ void TrackerMedianFlow::Params::write( cv::FileStorage& fs ) const{
fs
<<
"pointsInGrid"
<<
pointsInGrid
;
}
TrackerMedianFlow
::~
TrackerMedianFlow
()
{
}
void
TrackerMedianFlow
::
read
(
const
cv
::
FileNode
&
fn
)
void
TrackerMedianFlowImpl
::
read
(
const
cv
::
FileNode
&
fn
)
{
params
.
read
(
fn
);
}
void
TrackerMedianFlow
::
write
(
cv
::
FileStorage
&
fs
)
const
void
TrackerMedianFlow
Impl
::
write
(
cv
::
FileStorage
&
fs
)
const
{
params
.
write
(
fs
);
}
TrackerMedianFlow
::
TrackerMedianFlow
(
const
TrackerMedianFlow
::
Params
&
parameters
)
:
params
(
parameters
){
isInit
=
false
;
Ptr
<
TrackerMedianFlow
>
TrackerMedianFlow
::
createTracker
(
const
TrackerMedianFlow
::
Params
&
parameters
){
return
Ptr
<
TrackerMedianFlowImpl
>
(
new
TrackerMedianFlowImpl
(
parameters
));
}
bool
TrackerMedianFlow
::
initImpl
(
const
Mat
&
image
,
const
Rect2d
&
boundingBox
){
bool
TrackerMedianFlow
Impl
::
initImpl
(
const
Mat
&
image
,
const
Rect2d
&
boundingBox
){
model
=
Ptr
<
TrackerMedianFlowModel
>
(
new
TrackerMedianFlowModel
(
params
));
((
TrackerMedianFlowModel
*
)
static_cast
<
TrackerModel
*>
(
model
))
->
setImage
(
image
);
((
TrackerMedianFlowModel
*
)
static_cast
<
TrackerModel
*>
(
model
))
->
setBoudingBox
(
boundingBox
);
return
true
;
}
bool
TrackerMedianFlow
::
updateImpl
(
const
Mat
&
image
,
Rect2d
&
boundingBox
){
bool
TrackerMedianFlow
Impl
::
updateImpl
(
const
Mat
&
image
,
Rect2d
&
boundingBox
){
Mat
oldImage
=
((
TrackerMedianFlowModel
*
)
static_cast
<
TrackerModel
*>
(
model
))
->
getImage
();
Rect2d
oldBox
=
((
TrackerMedianFlowModel
*
)
static_cast
<
TrackerModel
*>
(
model
))
->
getBoundingBox
();
if
(
!
(((
TrackerMedianFlowModel
*
)
static_cast
<
TrackerModel
*>
(
model
))
->
getMedianFlowCore
())
->
medianFlowImpl
(
oldImage
,
image
,
oldBox
)){
if
(
!
medianFlowImpl
(
oldImage
,
image
,
oldBox
)){
return
false
;
}
boundingBox
=
oldBox
;
...
...
@@ -168,7 +160,7 @@ bool TrackerMedianFlow::updateImpl( const Mat& image, Rect2d& boundingBox ){
return
true
;
}
std
::
string
MedianFlowCore
::
type2str
(
int
type
)
{
std
::
string
TrackerMedianFlowImpl
::
type2str
(
int
type
)
{
std
::
string
r
;
uchar
depth
=
type
&
CV_MAT_DEPTH_MASK
;
...
...
@@ -190,7 +182,7 @@ std::string MedianFlowCore::type2str(int type) {
return
r
;
}
bool
MedianFlowCore
::
medianFlowImpl
(
Mat
oldImage
,
Mat
newImage
,
Rect2d
&
oldBox
){
bool
TrackerMedianFlowImpl
::
medianFlowImpl
(
Mat
oldImage
,
Mat
newImage
,
Rect2d
&
oldBox
){
std
::
vector
<
Point2f
>
pointsToTrackOld
,
pointsToTrackNew
;
Mat
oldImage_gray
,
newImage_gray
;
...
...
@@ -251,7 +243,7 @@ bool MedianFlowCore::medianFlowImpl(Mat oldImage,Mat newImage,Rect2d& oldBox){
return
true
;
}
Rect2d
MedianFlowCore
::
vote
(
const
std
::
vector
<
Point2f
>&
oldPoints
,
const
std
::
vector
<
Point2f
>&
newPoints
,
const
Rect2d
&
oldRect
,
Point2f
&
mD
){
Rect2d
TrackerMedianFlowImpl
::
vote
(
const
std
::
vector
<
Point2f
>&
oldPoints
,
const
std
::
vector
<
Point2f
>&
newPoints
,
const
Rect2d
&
oldRect
,
Point2f
&
mD
){
static
int
iteration
=
0
;
//FIXME -- we don't want this static var in final release
Rect2d
newRect
;
Point2d
newCenter
(
oldRect
.
x
+
oldRect
.
width
/
2.0
,
oldRect
.
y
+
oldRect
.
height
/
2.0
);
...
...
@@ -310,7 +302,7 @@ Rect2d MedianFlowCore::vote(const std::vector<Point2f>& oldPoints,const std::vec
}
template
<
typename
T
>
T
MedianFlowCore
::
getMedian
(
std
::
vector
<
T
>&
values
,
int
size
){
T
TrackerMedianFlowImpl
::
getMedian
(
std
::
vector
<
T
>&
values
,
int
size
){
if
(
size
==-
1
){
size
=
(
int
)
values
.
size
();
}
...
...
@@ -323,7 +315,7 @@ T MedianFlowCore::getMedian(std::vector<T>& values,int size){
}
}
void
MedianFlowCore
::
computeStatistics
(
std
::
vector
<
float
>&
data
,
int
size
){
void
TrackerMedianFlowImpl
::
computeStatistics
(
std
::
vector
<
float
>&
data
,
int
size
){
int
binnum
=
10
;
if
(
size
==-
1
){
size
=
(
int
)
data
.
size
();
...
...
@@ -337,11 +329,11 @@ void MedianFlowCore::computeStatistics(std::vector<float>& data,int size){
dprintf
((
"[%4f,%4f] -- %4d
\n
"
,
mini
+
(
maxi
-
mini
)
/
binnum
*
i
,
mini
+
(
maxi
-
mini
)
/
binnum
*
(
i
+
1
),
bins
[
i
]));
}
}
double
MedianFlowCore
::
l2distance
(
Point2f
p1
,
Point2f
p2
){
double
TrackerMedianFlowImpl
::
l2distance
(
Point2f
p1
,
Point2f
p2
){
double
dx
=
p1
.
x
-
p2
.
x
,
dy
=
p1
.
y
-
p2
.
y
;
return
sqrt
(
dx
*
dx
+
dy
*
dy
);
}
void
MedianFlowCore
::
check_FB
(
const
Mat
&
oldImage
,
const
Mat
&
newImage
,
void
TrackerMedianFlowImpl
::
check_FB
(
const
Mat
&
oldImage
,
const
Mat
&
newImage
,
const
std
::
vector
<
Point2f
>&
oldPoints
,
const
std
::
vector
<
Point2f
>&
newPoints
,
std
::
vector
<
bool
>&
status
){
if
(
status
.
size
()
==
0
){
...
...
@@ -364,7 +356,7 @@ void MedianFlowCore::check_FB(const Mat& oldImage,const Mat& newImage,
status
[
i
]
=
(
FBerror
[
i
]
<
FBerrorMedian
);
}
}
void
MedianFlowCore
::
check_NCC
(
const
Mat
&
oldImage
,
const
Mat
&
newImage
,
void
TrackerMedianFlowImpl
::
check_NCC
(
const
Mat
&
oldImage
,
const
Mat
&
newImage
,
const
std
::
vector
<
Point2f
>&
oldPoints
,
const
std
::
vector
<
Point2f
>&
newPoints
,
std
::
vector
<
bool
>&
status
){
std
::
vector
<
float
>
NCC
(
oldPoints
.
size
(),
0.0
);
...
...
modules/tracking/src/trackerTLD.cpp
View file @
c06bb0dc
...
...
@@ -87,6 +87,7 @@ using namespace tld;
namespace
cv
{
class
TLDDetector
;
class
MyMouseCallbackDEBUG
{
public
:
...
...
@@ -127,7 +128,6 @@ public:
protected
:
friend
class
MyMouseCallbackDEBUG
;
Ptr
<
TrackerModel
>
model
;
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
);
...
...
@@ -209,6 +209,25 @@ class TrackerTLDModel : public TrackerModel{
std
::
vector
<
TLDEnsembleClassifier
>
classifiers
;
};
class
TrackerTLDImpl
:
public
TrackerTLD
{
public
:
TrackerTLDImpl
(
const
TrackerTLD
::
Params
&
parameters
=
TrackerTLD
::
Params
()
);
void
read
(
const
FileNode
&
fn
);
void
write
(
FileStorage
&
fs
)
const
;
protected
:
bool
initImpl
(
const
Mat
&
image
,
const
Rect2d
&
boundingBox
);
bool
updateImpl
(
const
Mat
&
image
,
Rect2d
&
boundingBox
);
TrackerTLD
::
Params
params
;
Ptr
<
Data
>
data
;
Ptr
<
TrackerProxy
>
tracker
;
Ptr
<
TLDDetector
>
detector
;
};
TrackerTLD
::
Params
::
Params
(){
}
...
...
@@ -218,11 +237,15 @@ void TrackerTLD::Params::read( const cv::FileNode& /*fn*/ ){
void
TrackerTLD
::
Params
::
write
(
cv
::
FileStorage
&
/*fs*/
)
const
{
}
TrackerTLD
::
TrackerTLD
(
const
TrackerTLD
::
Params
&
parameters
)
:
Ptr
<
TrackerTLD
>
TrackerTLD
::
createTracker
(
const
TrackerTLD
::
Params
&
parameters
){
return
Ptr
<
TrackerTLDImpl
>
(
new
TrackerTLDImpl
(
parameters
));
}
TrackerTLDImpl
::
TrackerTLDImpl
(
const
TrackerTLD
::
Params
&
parameters
)
:
params
(
parameters
){
isInit
=
false
;
privateInfo
.
push_back
(
Ptr
<
TrackerProxyImpl
<
TrackerMedianFlow
,
TrackerMedianFlow
::
Params
>
>
(
new
TrackerProxyImpl
<
TrackerMedianFlow
,
TrackerMedianFlow
::
Params
>
())
)
;
tracker
=
Ptr
<
TrackerProxyImpl
<
TrackerMedianFlow
,
TrackerMedianFlow
::
Params
>
>
(
new
TrackerProxyImpl
<
TrackerMedianFlow
,
TrackerMedianFlow
::
Params
>
());
}
TrackerTLD
::~
TrackerTLD
(){
...
...
@@ -240,9 +263,9 @@ void TrackerTLD::write( cv::FileStorage& fs ) const
bool
TrackerTLD
::
initImpl
(
const
Mat
&
image
,
const
Rect2d
&
boundingBox
){
Mat
image_gray
;
((
TrackerProxy
*
)
static_cast
<
Private
*>
(
privateInfo
[
0
]))
->
init
(
image
,
boundingBox
);
tracker
->
init
(
image
,
boundingBox
);
cvtColor
(
image
,
image_gray
,
COLOR_BGR2GRAY
);
Data
*
data
=
new
Data
(
boundingBox
);
data
=
new
Data
(
boundingBox
);
double
scale
=
data
->
getScale
();
Rect2d
myBoundingBox
=
boundingBox
;
if
(
scale
>
1.0
){
...
...
@@ -255,13 +278,10 @@ bool TrackerTLD::initImpl(const Mat& image, const Rect2d& boundingBox ){
myBoundingBox
.
height
*=
scale
;
}
model
=
Ptr
<
TrackerTLDModel
>
(
new
TrackerTLDModel
(
params
,
image_gray
,
myBoundingBox
,
data
->
getMinSize
()));
TLDDetector
*
detector
=
new
TLDDetector
(
params
,
model
);
detector
=
new
TLDDetector
(
params
,
model
);
data
->
confident
=
false
;
data
->
failedLastTime
=
false
;
privateInfo
.
push_back
(
Ptr
<
TLDDetector
>
(
detector
));
privateInfo
.
push_back
(
Ptr
<
Data
>
(
data
));
#if !1
dprintf
((
"here I am
\n
"
));
Mat
image_blurred
;
...
...
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