Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Commits
2fd8ad65
Commit
2fd8ad65
authored
Oct 04, 2012
by
Leonid Beynenson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made changes in cv::DetectionBasedTracker -- now it can return status of the tracked objects
parent
9218bdcb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletion
+54
-1
detection_based_tracker.hpp
...ntrib/include/opencv2/contrib/detection_based_tracker.hpp
+21
-0
detection_based_tracker.cpp
modules/contrib/src/detection_based_tracker.cpp
+33
-1
No files found.
modules/contrib/include/opencv2/contrib/detection_based_tracker.hpp
View file @
2fd8ad65
...
...
@@ -90,6 +90,26 @@ class DetectionBasedTracker
virtual
void
getObjects
(
std
::
vector
<
cv
::
Rect
>&
result
)
const
;
virtual
void
getObjects
(
std
::
vector
<
Object
>&
result
)
const
;
enum
ObjectStatus
{
DETECTED_NOT_SHOWN_YET
,
DETECTED
,
DETECTED_TEMPORARY_LOST
,
WRONG_OBJECT
};
struct
ExtObject
{
int
id
;
cv
::
Rect
location
;
ObjectStatus
status
;
ExtObject
(
int
_id
,
cv
::
Rect
_location
,
ObjectStatus
_status
)
:
id
(
_id
),
location
(
_location
),
status
(
_status
)
{
}
};
virtual
void
getObjects
(
std
::
vector
<
ExtObject
>&
result
)
const
;
virtual
int
addObject
(
const
cv
::
Rect
&
location
);
//returns id of the new object
protected
:
...
...
@@ -146,6 +166,7 @@ class DetectionBasedTracker
void
updateTrackedObjects
(
const
std
::
vector
<
cv
::
Rect
>&
detectedObjects
);
cv
::
Rect
calcTrackedObjectPositionToShow
(
int
i
)
const
;
cv
::
Rect
calcTrackedObjectPositionToShow
(
int
i
,
ObjectStatus
&
status
)
const
;
void
detectInRegion
(
const
cv
::
Mat
&
img
,
const
cv
::
Rect
&
r
,
std
::
vector
<
cv
::
Rect
>&
detectedObjectsInRegions
);
};
}
//end of cv namespace
...
...
modules/contrib/src/detection_based_tracker.cpp
View file @
2fd8ad65
#if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(ANDROID)
#include "opencv2/contrib/detection_based_tracker.hpp"
#if defined(DEBUG) || defined(_DEBUG)
#undef DEBUGLOGS
#define DEBUGLOGS 1
#endif
#ifndef DEBUGLOGS
#define DEBUGLOGS 0
#endif
#ifdef ANDROID
#include <android/log.h>
...
...
@@ -218,7 +225,7 @@ void* cv::workcycleObjectDetectorFunction(void* p)
void
cv
::
DetectionBasedTracker
::
SeparateDetectionWork
::
workcycleObjectDetector
()
{
static
double
freq
=
getTickFrequency
();
LOGD
0
(
"DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start"
);
LOGD
(
"DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- start"
);
vector
<
Rect
>
objects
;
CV_Assert
(
stateThread
==
STATE_THREAD_WORKING_SLEEPING
);
...
...
@@ -303,6 +310,7 @@ void cv::DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector()
int64
t2_detect
=
getTickCount
();
int64
dt_detect
=
t2_detect
-
t1_detect
;
double
dt_detect_ms
=
((
double
)
dt_detect
)
/
freq
*
1000.0
;
(
void
)(
dt_detect_ms
);
LOGI
(
"DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() --- objects num==%d, t_ms=%.4f"
,
(
int
)
objects
.
size
(),
dt_detect_ms
);
...
...
@@ -396,6 +404,7 @@ bool cv::DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingT
isObjectDetectingReady
=
false
;
double
lastBigDetectionDuration
=
1000.0
*
(((
double
)(
getTickCount
()
-
timeWhenDetectingThreadStartedWork
))
/
freq
);
(
void
)(
lastBigDetectionDuration
);
LOGD
(
"DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread: lastBigDetectionDuration=%f ms"
,
(
double
)
lastBigDetectionDuration
);
}
...
...
@@ -482,6 +491,7 @@ void DetectionBasedTracker::process(const Mat& imageGray)
{
double
delta_time_from_prev_call
=
1000.0
*
(((
double
)(
getTickCount
()
-
time_when_last_call_started
))
/
freq
);
(
void
)(
delta_time_from_prev_call
);
LOGD
(
"DetectionBasedTracker::process: time from the previous call is %f ms"
,
(
double
)
delta_time_from_prev_call
);
time_when_last_call_started
=
getTickCount
();
}
...
...
@@ -564,6 +574,17 @@ void cv::DetectionBasedTracker::getObjects(std::vector<Object>& result) const
LOGD
(
"DetectionBasedTracker::process: found a object with SIZE %d x %d, rect={%d, %d, %d x %d}"
,
r
.
width
,
r
.
height
,
r
.
x
,
r
.
y
,
r
.
width
,
r
.
height
);
}
}
void
cv
::
DetectionBasedTracker
::
getObjects
(
std
::
vector
<
ExtObject
>&
result
)
const
{
result
.
clear
();
for
(
size_t
i
=
0
;
i
<
trackedObjects
.
size
();
i
++
)
{
ObjectStatus
status
;
Rect
r
=
calcTrackedObjectPositionToShow
(
i
,
status
);
result
.
push_back
(
ExtObject
(
trackedObjects
[
i
].
id
,
r
,
status
));
LOGD
(
"DetectionBasedTracker::process: found a object with SIZE %d x %d, rect={%d, %d, %d x %d}, status = %d"
,
r
.
width
,
r
.
height
,
r
.
x
,
r
.
y
,
r
.
width
,
r
.
height
,
(
int
)
status
);
}
}
bool
cv
::
DetectionBasedTracker
::
run
()
{
...
...
@@ -699,6 +720,7 @@ void cv::DetectionBasedTracker::updateTrackedObjects(const vector<Rect>& detecte
int
numpos
=
it
->
lastPositions
.
size
();
CV_Assert
(
numpos
>
0
);
Rect
r
=
it
->
lastPositions
[
numpos
-
1
];
(
void
)(
r
);
LOGD
(
"DetectionBasedTracker::updateTrackedObjects: deleted object {%d, %d, %d x %d}"
,
r
.
x
,
r
.
y
,
r
.
width
,
r
.
height
);
it
=
trackedObjects
.
erase
(
it
);
...
...
@@ -718,17 +740,25 @@ int cv::DetectionBasedTracker::addObject(const Rect& location)
}
Rect
cv
::
DetectionBasedTracker
::
calcTrackedObjectPositionToShow
(
int
i
)
const
{
ObjectStatus
status
;
return
calcTrackedObjectPositionToShow
(
i
,
status
);
}
Rect
cv
::
DetectionBasedTracker
::
calcTrackedObjectPositionToShow
(
int
i
,
ObjectStatus
&
status
)
const
{
if
(
(
i
<
0
)
||
(
i
>=
(
int
)
trackedObjects
.
size
())
)
{
LOGE
(
"DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: wrong i=%d"
,
i
);
status
=
WRONG_OBJECT
;
return
Rect
();
}
if
(
trackedObjects
[
i
].
numDetectedFrames
<=
innerParameters
.
numStepsToWaitBeforeFirstShow
){
LOGI
(
"DetectionBasedTracker::calcTrackedObjectPositionToShow: trackedObjects[%d].numDetectedFrames=%d <= numStepsToWaitBeforeFirstShow=%d --- return empty Rect()"
,
i
,
trackedObjects
[
i
].
numDetectedFrames
,
innerParameters
.
numStepsToWaitBeforeFirstShow
);
status
=
DETECTED_NOT_SHOWN_YET
;
return
Rect
();
}
if
(
trackedObjects
[
i
].
numFramesNotDetected
>
innerParameters
.
numStepsToShowWithoutDetecting
)
{
status
=
DETECTED_TEMPORARY_LOST
;
return
Rect
();
}
...
...
@@ -737,6 +767,7 @@ Rect cv::DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const
int
N
=
lastPositions
.
size
();
if
(
N
<=
0
)
{
LOGE
(
"DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: no positions for i=%d"
,
i
);
status
=
WRONG_OBJECT
;
return
Rect
();
}
...
...
@@ -795,6 +826,7 @@ Rect cv::DetectionBasedTracker::calcTrackedObjectPositionToShow(int i) const
Rect
res
(
cvRound
(
tl
.
x
),
cvRound
(
tl
.
y
),
cvRound
(
w
),
cvRound
(
h
));
LOGD
(
"DetectionBasedTracker::calcTrackedObjectPositionToShow: Result for i=%d: {%d, %d, %d x %d}"
,
i
,
res
.
x
,
res
.
y
,
res
.
width
,
res
.
height
);
status
=
DETECTED
;
return
res
;
}
...
...
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