Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
face_detect
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiajunjie
face_detect
Commits
beb02a13
Commit
beb02a13
authored
Jun 04, 2019
by
jiajunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update tracker,add filter function
parent
42a5d815
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
41 deletions
+120
-41
tracker.cpp
c++/tracker/src/tracker.cpp
+67
-23
tracker.h
c++/tracker/src/tracker.h
+28
-13
libtracker.so
libx64/libtracker.so
+0
-0
test-tracker-dnn.py
python/examples/test-tracker-dnn.py
+12
-2
test-tracker.py
python/examples/test-tracker.py
+13
-3
No files found.
c++/tracker/src/tracker.cpp
View file @
beb02a13
...
...
@@ -21,6 +21,17 @@
#include "tracker.h"
struct
tracker_info
{
vector
<
Rect2d
>
boxes
;
vector
<
int
>
trackerIds
;
tracker_info
()
{
boxes
.
clear
();
trackerIds
.
clear
();
}
};
struct
tracker_param
{
bool
bParamIsOk
;
...
...
@@ -144,7 +155,24 @@ muti_tracker_instance * muti_tracker_init_dnn(
instance
->
_param
->
bParamIsOk
=
true
;
return
instance
;
}
int
filterMaxFaceObject
(
cv
::
Mat
frame
,
vector
<
cv
::
Rect2d
>
faces
)
{
if
(
faces
.
size
()
==
0
)
return
-
1
;
int
index
=
0
;
for
(
int
i
=
0
;
i
<
faces
.
size
();
i
++
)
{
if
(
(
i
+
1
)
==
faces
.
size
()
)
break
;
if
(
(
faces
[
i
+
1
].
width
*
faces
[
i
+
1
].
height
)
>
(
faces
[
i
].
width
*
faces
[
i
].
height
)
)
index
=
i
+
1
;
}
rectangle
(
frame
,
faces
[
index
],
Scalar
(
255
,
0
,
255
),
2
,
1
);
return
index
;
}
FACE_ERROR_E
muti_tracker_estimate
(
muti_tracker_instance
*
instance
,
...
...
@@ -153,8 +181,8 @@ FACE_ERROR_E muti_tracker_estimate(
unsigned
char
*
imgdata
,
const
char
*
trackerType
,
const
int
extend
,
const
int
updatetime
/*
,
struct tracker_info* ptracker*/
const
int
updatetime
,
struct
getMaxTracker
*
ptracker
)
{
if
(
!
instance
||
!
instance
->
_param
->
bParamIsOk
)
{
...
...
@@ -167,8 +195,8 @@ FACE_ERROR_E muti_tracker_estimate(
return
FACE_ERR_INVALID_IMAGE
;
}
cv
::
Mat
inputImg
(
rows
,
cols
,
CV_8UC3
,
(
void
*
)
imgdata
);
if
(
inputImg
.
empty
())
cv
::
Mat
frame
(
rows
,
cols
,
CV_8UC3
,
(
void
*
)
imgdata
);
if
(
frame
.
empty
())
{
cout
<<
"input image can not be empty!"
<<
endl
;
return
FACE_ERR_INVALID_IMAGE
;
...
...
@@ -182,15 +210,11 @@ FACE_ERROR_E muti_tracker_estimate(
if
(
diffms
>
updatetime
)
{
cv
::
Mat
grayImg
;
cv
::
cvtColor
(
inputImg
,
grayImg
,
CV_BGR2GRAY
);
cv
::
cvtColor
(
frame
,
grayImg
,
CV_BGR2GRAY
);
vector
<
Rect
>
facesvec
;
instance
->
_param
->
cascade
.
detectMultiScale
(
grayImg
,
facesvec
,
1.1
,
2
,
0
//|CV_HAAR_FIND_BIGGEST_OBJECT
//|CV_HAAR_DO_ROUGH_SEARCH
|
CV_HAAR_SCALE_IMAGE
,
1.1
,
2
,
0
,
Size
(
50
,
50
));
instance
->
_param
->
algorithms
.
clear
();
...
...
@@ -202,14 +226,14 @@ FACE_ERROR_E muti_tracker_estimate(
return
FACE_ERR_NO_FACE
;
for
(
int
i
=
0
;
i
<
face_num
;
i
++
)
{
rectangle
(
inputImg
,
facesvec
[
i
],
Scalar
(
255
,
0
,
0
),
2
,
1
);
rectangle
(
frame
,
facesvec
[
i
],
Scalar
(
255
,
0
,
0
),
2
,
1
);
instance
->
_param
->
objects
.
boxes
.
push_back
(
facesvec
[
i
]);
//push boxes
instance
->
_param
->
algorithms
.
push_back
(
createTrackerByName
(
trackerType
)
);
}
MultiTracker
trackers
;
instance
->
_param
->
mttrackers
=
trackers
;
instance
->
_param
->
mttrackers
.
add
(
instance
->
_param
->
algorithms
,
inputImg
,
instance
->
_param
->
objects
.
boxes
);
instance
->
_param
->
mttrackers
.
add
(
instance
->
_param
->
algorithms
,
frame
,
instance
->
_param
->
objects
.
boxes
);
instance
->
_param
->
detect_time
=
now_time
;
}
...
...
@@ -254,14 +278,23 @@ FACE_ERROR_E muti_tracker_estimate(
string
strIdnum
=
" ID: "
+
Int_String
(
instance
->
_param
->
objects
.
trackerIds
[
i
]);
putText
(
inputImg
,
strIdnum
,
cv
::
Point
(
instance
->
_param
->
objects
.
boxes
[
i
].
x
,
putText
(
frame
,
strIdnum
,
cv
::
Point
(
instance
->
_param
->
objects
.
boxes
[
i
].
x
,
instance
->
_param
->
objects
.
boxes
[
i
].
y
-
5
),
FONT_HERSHEY_PLAIN
,
2
,
Scalar
(
0
,
0
,
255
),
1
,
8
);
}
//end of for i
instance
->
_param
->
objects_save
=
instance
->
_param
->
objects
;
instance
->
_param
->
mttrackers
.
update
(
inputImg
,
instance
->
_param
->
objects
.
boxes
);
instance
->
_param
->
mttrackers
.
update
(
frame
,
instance
->
_param
->
objects
.
boxes
);
//*ptracker = instance->_param->objects_save;
int
maxIndex
=
filterMaxFaceObject
(
frame
,
instance
->
_param
->
objects_save
.
boxes
);
if
(
maxIndex
>=
0
)
{
ptracker
->
rect_x
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
x
;
ptracker
->
rect_y
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
y
;
ptracker
->
rect_w
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
width
;
ptracker
->
rect_h
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
height
;
ptracker
->
tracker_id
=
instance
->
_param
->
objects_save
.
trackerIds
[
maxIndex
];
}
else
{
ptracker
=
NULL
;
}
return
FACE_OK
;
}
...
...
@@ -274,8 +307,8 @@ FACE_ERROR_E muti_tracker_estimate_dnn(
const
char
*
trackerType
,
const
int
extend
,
const
int
updatetime
,
const
float
threshold
/*
,
struct
tracker_info* ptracker*/
const
float
threshold
,
struct
getMaxTracker
*
ptracker
)
{
if
(
!
instance
||
!
instance
->
_param
->
bParamIsOk
)
{
...
...
@@ -395,12 +428,23 @@ FACE_ERROR_E muti_tracker_estimate_dnn(
string
strIdnum
=
" ID: "
+
Int_String
(
instance
->
_param
->
objects
.
trackerIds
[
i
]);
putText
(
frame
,
strIdnum
,
cv
::
Point
(
instance
->
_param
->
objects
.
boxes
[
i
].
x
,
instance
->
_param
->
objects
.
boxes
[
i
].
y
-
5
),
FONT_HERSHEY_PLAIN
,
2
,
Scalar
(
0
,
0
,
255
),
1
,
8
);
}
//end of for i
}
//end of for i
instance
->
_param
->
objects_save
=
instance
->
_param
->
objects
;
instance
->
_param
->
mttrackers
.
update
(
frame
,
instance
->
_param
->
objects
.
boxes
);
return
FACE_OK
;
instance
->
_param
->
objects_save
=
instance
->
_param
->
objects
;
instance
->
_param
->
mttrackers
.
update
(
frame
,
instance
->
_param
->
objects
.
boxes
);
int
maxIndex
=
filterMaxFaceObject
(
frame
,
instance
->
_param
->
objects_save
.
boxes
);
if
(
maxIndex
>=
0
)
{
ptracker
->
rect_x
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
x
;
ptracker
->
rect_y
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
y
;
ptracker
->
rect_w
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
width
;
ptracker
->
rect_h
=
instance
->
_param
->
objects_save
.
boxes
[
maxIndex
].
height
;
ptracker
->
tracker_id
=
instance
->
_param
->
objects_save
.
trackerIds
[
maxIndex
];
}
else
{
ptracker
=
NULL
;
}
return
FACE_OK
;
}
FACE_ERROR_E
muti_tracker_destory
(
...
...
c++/tracker/src/tracker.h
View file @
beb02a13
...
...
@@ -25,14 +25,28 @@ using namespace cv::dnn;
extern
"C"
{
struct
tracker_info
/*
*@brief 返回过滤后用户结构信息
*@param rect_x 跟踪矩形框X坐标
*@param rect_y 跟踪矩形框y坐标
*@param rect_w 跟踪矩形框宽
*@param rect_h 跟踪矩形框高
*@param tracker_id 跟踪目标id号
*/
struct
getMaxTracker
{
vector
<
Rect2d
>
boxes
;
vector
<
int
>
trackerIds
;
tracker_info
()
{
boxes
.
clear
();
trackerIds
.
clear
();
int
rect_x
;
int
rect_y
;
int
rect_w
;
int
rect_h
;
int
tracker_id
;
getMaxTracker
()
{
rect_x
=
0
;
rect_y
=
0
;
rect_w
=
0
;
rect_h
=
0
;
tracker_id
=
0
;
}
};
...
...
@@ -73,7 +87,7 @@ extern "C"
* @param trackerType 采用的跟踪方式
* @param extend 对边框增减的大小
* @param updatetime 检测器的校准时间(毫秒级)
* @param ptracker
获取跟踪的人脸框和ID号
* @param ptracker
返回过滤后追踪对象信息
*
* @return FACE_ERROR_E 返回错误码
*/
...
...
@@ -85,8 +99,8 @@ extern "C"
unsigned
char
*
imgdata
,
const
char
*
trackerType
,
const
int
extend
,
const
int
updatetime
/*
,
struct
tracker_info* ptracker*/
const
int
updatetime
,
struct
getMaxTracker
*
ptracker
);
/**
...
...
@@ -99,7 +113,8 @@ extern "C"
* @param trackerType 采用的跟踪方式
* @param extend 对边框增减的大小
* @param updatetime 检测器的校准时间(毫秒级)
* @param threshold 预测置信度(0~1),推荐值0.9
* @param threshold 预测置信度(0~1),推荐值0.9
* @param ptracker 返回过滤后追踪对象信息
*
* @return FACE_ERROR_E 返回错误码
*/
...
...
@@ -112,8 +127,8 @@ extern "C"
const
char
*
trackerType
,
const
int
extend
,
const
int
updatetime
,
const
float
threshold
/*
,
struct
tracker_info* ptracker*/
const
float
threshold
,
struct
getMaxTracker
*
ptracker
);
/**
...
...
libx64/libtracker.so
View file @
beb02a13
No preview for this file type
python/examples/test-tracker-dnn.py
View file @
beb02a13
...
...
@@ -11,6 +11,13 @@ cap = cv2.VideoCapture(0)
cap
.
set
(
3
,
640
)
cap
.
set
(
4
,
480
)
class
maxTrackerObject
(
Structure
):
_fields_
=
[(
"rect_x"
,
c_int
),
(
"rect_y"
,
c_int
),
(
"rect_w"
,
c_int
),
(
"rect_h"
,
c_int
),
(
"tracker_id"
,
c_int
)]
print
'start'
models_path
=
"/home/uboo/project/uboo/face_detect_git/models/"
instance
=
lib
.
muti_tracker_init_dnn
(
models_path
+
"res10_300x300_ssd_deploy.prototxt"
,
models_path
+
"res10_300x300_ssd_iter_140000_fp16.caffemodel"
)
...
...
@@ -20,9 +27,12 @@ while cap.isOpened():
img
=
cv2
.
flip
(
img
,
1
)
(
rows
,
cols
)
=
(
img
.
shape
[
0
],
img
.
shape
[
1
])
print
(
rows
,
cols
)
ret
=
lib
.
muti_tracker_estimate_dnn
(
instance
,
rows
,
cols
,
img
.
ctypes
.
data_as
(
POINTER
(
c_ubyte
)),
"KCF"
,
50
,
100
,
c_float
(
0.9
))
print
'result: '
+
str
(
ret
)
pTracker
=
pointer
(
maxTrackerObject
(
0
,
0
,
0
,
0
,
0
))
ret
=
lib
.
muti_tracker_estimate_dnn
(
instance
,
rows
,
cols
,
img
.
ctypes
.
data_as
(
POINTER
(
c_ubyte
)),
"KCF"
,
50
,
100
,
c_float
(
0.9
),
pTracker
)
print
'tracker_id: '
+
str
(
pTracker
.
contents
.
tracker_id
)
print
'result: '
+
str
(
ret
)
cv2
.
imshow
(
"FaceDetect"
,
img
)
k
=
cv2
.
waitKey
(
1
)
if
(
k
==
ord
(
'q'
)):
...
...
python/examples/test-tracker.py
View file @
beb02a13
...
...
@@ -3,13 +3,21 @@ import ctypes
import
cv2
so
=
ctypes
.
cdll
.
LoadLibrary
Library_path
=
"/home/uboo/project/uboo/face_detect_git/libx64/"
lib
=
so
(
Library_path
+
"libtracker.so"
)
#library_path="/home/uboo/project/uboo/face_detect_git/c++/tracker/build/"
library_path
=
"/home/uboo/project/uboo/face_detect_git/libx64/"
lib
=
so
(
library_path
+
"libtracker.so"
)
cap
=
cv2
.
VideoCapture
(
0
)
cap
.
set
(
3
,
640
)
cap
.
set
(
4
,
480
)
class
maxTrackerObject
(
Structure
):
_fields_
=
[(
"rect_x"
,
c_int
),
(
"rect_y"
,
c_int
),
(
"rect_w"
,
c_int
),
(
"rect_h"
,
c_int
),
(
"tracker_id"
,
c_int
)]
print
'start'
models_path
=
"/home/uboo/project/uboo/face_detect_git/models/"
instance
=
lib
.
muti_tracker_init
(
models_path
+
"haarcascade_frontalface_alt.xml"
)
...
...
@@ -19,7 +27,9 @@ while cap.isOpened():
img
=
cv2
.
flip
(
img
,
1
)
(
rows
,
cols
)
=
(
img
.
shape
[
0
],
img
.
shape
[
1
])
print
(
rows
,
cols
)
ret
=
lib
.
muti_tracker_estimate
(
instance
,
rows
,
cols
,
img
.
ctypes
.
data_as
(
POINTER
(
c_ubyte
)),
"KCF"
,
50
,
100
)
pTracker
=
pointer
(
maxTrackerObject
(
0
,
0
,
0
,
0
,
0
))
ret
=
lib
.
muti_tracker_estimate
(
instance
,
rows
,
cols
,
img
.
ctypes
.
data_as
(
POINTER
(
c_ubyte
)),
"KCF"
,
50
,
100
,
pTracker
)
print
'tracker_id: '
+
str
(
pTracker
.
contents
.
tracker_id
)
print
'result: '
+
str
(
ret
)
cv2
.
imshow
(
"FaceDetect"
,
img
)
...
...
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