Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
97373901
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
97373901
编写于
10月 28, 2021
作者:
S
shangliang Xu
提交者:
GitHub
10月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[depoly] fix inconsistency between cpp and python (#4351)
上级
35a93b11
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
120 addition
and
74 deletion
+120
-74
deploy/cpp/src/main.cc
deploy/cpp/src/main.cc
+25
-10
deploy/cpp/src/main_jde.cc
deploy/cpp/src/main_jde.cc
+19
-7
deploy/cpp/src/main_keypoint.cc
deploy/cpp/src/main_keypoint.cc
+28
-13
deploy/python/det_keypoint_unite_infer.py
deploy/python/det_keypoint_unite_infer.py
+8
-6
deploy/python/infer.py
deploy/python/infer.py
+10
-10
deploy/python/keypoint_infer.py
deploy/python/keypoint_infer.py
+8
-6
deploy/python/mot_jde_infer.py
deploy/python/mot_jde_infer.py
+8
-8
deploy/python/mot_keypoint_unite_infer.py
deploy/python/mot_keypoint_unite_infer.py
+7
-7
deploy/python/mot_sde_infer.py
deploy/python/mot_sde_infer.py
+7
-7
未找到文件。
deploy/cpp/src/main.cc
浏览文件 @
97373901
...
@@ -128,27 +128,36 @@ static void MkDirs(const std::string& path) {
...
@@ -128,27 +128,36 @@ static void MkDirs(const std::string& path) {
}
}
void
PredictVideo
(
const
std
::
string
&
video_path
,
void
PredictVideo
(
const
std
::
string
&
video_path
,
PaddleDetection
::
ObjectDetector
*
det
)
{
PaddleDetection
::
ObjectDetector
*
det
,
const
std
::
string
&
output_dir
=
"output"
)
{
// Open video
// Open video
cv
::
VideoCapture
capture
;
cv
::
VideoCapture
capture
;
std
::
string
video_out_name
=
"output.mp4"
;
if
(
FLAGS_camera_id
!=
-
1
){
if
(
FLAGS_camera_id
!=
-
1
){
capture
.
open
(
FLAGS_camera_id
);
capture
.
open
(
FLAGS_camera_id
);
}
else
{
}
else
{
capture
.
open
(
video_path
.
c_str
());
capture
.
open
(
video_path
.
c_str
());
video_out_name
=
video_path
.
substr
(
video_path
.
find_last_of
(
OS_PATH_SEP
)
+
1
);
}
}
if
(
!
capture
.
isOpened
())
{
if
(
!
capture
.
isOpened
())
{
printf
(
"can not open video : %s
\n
"
,
video_path
.
c_str
());
printf
(
"can not open video : %s
\n
"
,
video_path
.
c_str
());
return
;
return
;
}
}
// Get Video info : resolution, fps
// Get Video info : resolution, fps
, frame count
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
int
video_frame_count
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_COUNT
));
printf
(
"fps: %d, frame_count: %d
\n
"
,
video_fps
,
video_frame_count
);
// Create VideoWriter for output
// Create VideoWriter for output
cv
::
VideoWriter
video_out
;
cv
::
VideoWriter
video_out
;
std
::
string
video_out_path
=
"output.mp4"
;
std
::
string
video_out_path
(
output_dir
);
if
(
output_dir
.
rfind
(
OS_PATH_SEP
)
!=
output_dir
.
size
()
-
1
)
{
video_out_path
+=
OS_PATH_SEP
;
}
video_out_path
+=
video_out_name
;
video_out
.
open
(
video_out_path
.
c_str
(),
video_out
.
open
(
video_out_path
.
c_str
(),
0x00000021
,
0x00000021
,
video_fps
,
video_fps
,
...
@@ -166,7 +175,7 @@ void PredictVideo(const std::string& video_path,
...
@@ -166,7 +175,7 @@ void PredictVideo(const std::string& video_path,
auto
colormap
=
PaddleDetection
::
GenerateColorMap
(
labels
.
size
());
auto
colormap
=
PaddleDetection
::
GenerateColorMap
(
labels
.
size
());
// Capture all frames and do inference
// Capture all frames and do inference
cv
::
Mat
frame
;
cv
::
Mat
frame
;
int
frame_id
=
0
;
int
frame_id
=
1
;
bool
is_rbox
=
false
;
bool
is_rbox
=
false
;
while
(
capture
.
read
(
frame
))
{
while
(
capture
.
read
(
frame
))
{
if
(
frame
.
empty
())
{
if
(
frame
.
empty
())
{
...
@@ -174,8 +183,14 @@ void PredictVideo(const std::string& video_path,
...
@@ -174,8 +183,14 @@ void PredictVideo(const std::string& video_path,
}
}
std
::
vector
<
cv
::
Mat
>
imgs
;
std
::
vector
<
cv
::
Mat
>
imgs
;
imgs
.
push_back
(
frame
);
imgs
.
push_back
(
frame
);
det
->
Predict
(
imgs
,
0.5
,
0
,
1
,
&
result
,
&
bbox_num
,
&
det_times
);
printf
(
"detect frame: %d
\n
"
,
frame_id
);
det
->
Predict
(
imgs
,
FLAGS_threshold
,
0
,
1
,
&
result
,
&
bbox_num
,
&
det_times
);
std
::
vector
<
PaddleDetection
::
ObjectResult
>
out_result
;
for
(
const
auto
&
item
:
result
)
{
for
(
const
auto
&
item
:
result
)
{
if
(
item
.
confidence
<
FLAGS_threshold
||
item
.
class_id
==
-
1
)
{
continue
;
}
out_result
.
push_back
(
item
);
if
(
item
.
rect
.
size
()
>
6
){
if
(
item
.
rect
.
size
()
>
6
){
is_rbox
=
true
;
is_rbox
=
true
;
printf
(
"class=%d confidence=%.4f rect=[%d %d %d %d %d %d %d %d]
\n
"
,
printf
(
"class=%d confidence=%.4f rect=[%d %d %d %d %d %d %d %d]
\n
"
,
...
@@ -202,7 +217,7 @@ void PredictVideo(const std::string& video_path,
...
@@ -202,7 +217,7 @@ void PredictVideo(const std::string& video_path,
}
}
cv
::
Mat
out_im
=
PaddleDetection
::
VisualizeResult
(
cv
::
Mat
out_im
=
PaddleDetection
::
VisualizeResult
(
frame
,
result
,
labels
,
colormap
,
is_rbox
);
frame
,
out_
result
,
labels
,
colormap
,
is_rbox
);
video_out
.
write
(
out_im
);
video_out
.
write
(
out_im
);
frame_id
+=
1
;
frame_id
+=
1
;
...
@@ -337,12 +352,12 @@ int main(int argc, char** argv) {
...
@@ -337,12 +352,12 @@ int main(int argc, char** argv) {
FLAGS_trt_min_shape
,
FLAGS_trt_max_shape
,
FLAGS_trt_opt_shape
,
FLAGS_trt_min_shape
,
FLAGS_trt_max_shape
,
FLAGS_trt_opt_shape
,
FLAGS_trt_calib_mode
);
FLAGS_trt_calib_mode
);
// Do inference on input video or image
// Do inference on input video or image
if
(
!
PathExists
(
FLAGS_output_dir
))
{
MkDirs
(
FLAGS_output_dir
);
}
if
(
!
FLAGS_video_file
.
empty
()
||
FLAGS_camera_id
!=
-
1
)
{
if
(
!
FLAGS_video_file
.
empty
()
||
FLAGS_camera_id
!=
-
1
)
{
PredictVideo
(
FLAGS_video_file
,
&
det
);
PredictVideo
(
FLAGS_video_file
,
&
det
,
FLAGS_output_dir
);
}
else
if
(
!
FLAGS_image_file
.
empty
()
||
!
FLAGS_image_dir
.
empty
())
{
}
else
if
(
!
FLAGS_image_file
.
empty
()
||
!
FLAGS_image_dir
.
empty
())
{
if
(
!
PathExists
(
FLAGS_output_dir
))
{
MkDirs
(
FLAGS_output_dir
);
}
std
::
vector
<
std
::
string
>
all_img_paths
;
std
::
vector
<
std
::
string
>
all_img_paths
;
std
::
vector
<
cv
::
String
>
cv_all_img_paths
;
std
::
vector
<
cv
::
String
>
cv_all_img_paths
;
if
(
!
FLAGS_image_file
.
empty
())
{
if
(
!
FLAGS_image_file
.
empty
())
{
...
...
deploy/cpp/src/main_jde.cc
浏览文件 @
97373901
...
@@ -128,27 +128,36 @@ static void MkDirs(const std::string& path) {
...
@@ -128,27 +128,36 @@ static void MkDirs(const std::string& path) {
}
}
void
PredictVideo
(
const
std
::
string
&
video_path
,
void
PredictVideo
(
const
std
::
string
&
video_path
,
PaddleDetection
::
JDEDetector
*
mot
)
{
PaddleDetection
::
JDEDetector
*
mot
,
const
std
::
string
&
output_dir
=
"output"
)
{
// Open video
// Open video
cv
::
VideoCapture
capture
;
cv
::
VideoCapture
capture
;
std
::
string
video_out_name
=
"output.mp4"
;
if
(
FLAGS_camera_id
!=
-
1
){
if
(
FLAGS_camera_id
!=
-
1
){
capture
.
open
(
FLAGS_camera_id
);
capture
.
open
(
FLAGS_camera_id
);
}
else
{
}
else
{
capture
.
open
(
video_path
.
c_str
());
capture
.
open
(
video_path
.
c_str
());
video_out_name
=
video_path
.
substr
(
video_path
.
find_last_of
(
OS_PATH_SEP
)
+
1
);
}
}
if
(
!
capture
.
isOpened
())
{
if
(
!
capture
.
isOpened
())
{
printf
(
"can not open video : %s
\n
"
,
video_path
.
c_str
());
printf
(
"can not open video : %s
\n
"
,
video_path
.
c_str
());
return
;
return
;
}
}
// Get Video info : resolution, fps
// Get Video info : resolution, fps
, frame count
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
int
video_frame_count
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_COUNT
));
printf
(
"fps: %d, frame_count: %d
\n
"
,
video_fps
,
video_frame_count
);
// Create VideoWriter for output
// Create VideoWriter for output
cv
::
VideoWriter
video_out
;
cv
::
VideoWriter
video_out
;
std
::
string
video_out_path
=
"mot_output.mp4"
;
std
::
string
video_out_path
(
output_dir
);
if
(
output_dir
.
rfind
(
OS_PATH_SEP
)
!=
output_dir
.
size
()
-
1
)
{
video_out_path
+=
OS_PATH_SEP
;
}
video_out_path
+=
video_out_name
;
video_out
.
open
(
video_out_path
.
c_str
(),
video_out
.
open
(
video_out_path
.
c_str
(),
0x00000021
,
0x00000021
,
video_fps
,
video_fps
,
...
@@ -164,14 +173,15 @@ void PredictVideo(const std::string& video_path,
...
@@ -164,14 +173,15 @@ void PredictVideo(const std::string& video_path,
double
times
;
double
times
;
// Capture all frames and do inference
// Capture all frames and do inference
cv
::
Mat
frame
;
cv
::
Mat
frame
;
int
frame_id
=
0
;
int
frame_id
=
1
;
while
(
capture
.
read
(
frame
))
{
while
(
capture
.
read
(
frame
))
{
if
(
frame
.
empty
())
{
if
(
frame
.
empty
())
{
break
;
break
;
}
}
std
::
vector
<
cv
::
Mat
>
imgs
;
std
::
vector
<
cv
::
Mat
>
imgs
;
imgs
.
push_back
(
frame
);
imgs
.
push_back
(
frame
);
mot
->
Predict
(
imgs
,
0.5
,
0
,
1
,
&
result
,
&
det_times
);
printf
(
"detect frame: %d
\n
"
,
frame_id
);
mot
->
Predict
(
imgs
,
FLAGS_threshold
,
0
,
1
,
&
result
,
&
det_times
);
frame_id
+=
1
;
frame_id
+=
1
;
times
=
std
::
accumulate
(
det_times
.
begin
(),
det_times
.
end
(),
0
)
/
frame_id
;
times
=
std
::
accumulate
(
det_times
.
begin
(),
det_times
.
end
(),
0
)
/
frame_id
;
...
@@ -215,7 +225,9 @@ int main(int argc, char** argv) {
...
@@ -215,7 +225,9 @@ int main(int argc, char** argv) {
FLAGS_cpu_threads
,
FLAGS_run_mode
,
FLAGS_batch_size
,
FLAGS_gpu_id
,
FLAGS_cpu_threads
,
FLAGS_run_mode
,
FLAGS_batch_size
,
FLAGS_gpu_id
,
FLAGS_trt_min_shape
,
FLAGS_trt_max_shape
,
FLAGS_trt_opt_shape
,
FLAGS_trt_min_shape
,
FLAGS_trt_max_shape
,
FLAGS_trt_opt_shape
,
FLAGS_trt_calib_mode
);
FLAGS_trt_calib_mode
);
if
(
!
PathExists
(
FLAGS_output_dir
))
{
PredictVideo
(
FLAGS_video_file
,
&
mot
);
MkDirs
(
FLAGS_output_dir
);
}
PredictVideo
(
FLAGS_video_file
,
&
mot
,
FLAGS_output_dir
);
return
0
;
return
0
;
}
}
deploy/cpp/src/main_keypoint.cc
浏览文件 @
97373901
...
@@ -138,27 +138,36 @@ static void MkDirs(const std::string& path) {
...
@@ -138,27 +138,36 @@ static void MkDirs(const std::string& path) {
void
PredictVideo
(
const
std
::
string
&
video_path
,
void
PredictVideo
(
const
std
::
string
&
video_path
,
PaddleDetection
::
ObjectDetector
*
det
,
PaddleDetection
::
ObjectDetector
*
det
,
PaddleDetection
::
KeyPointDetector
*
keypoint
)
{
PaddleDetection
::
KeyPointDetector
*
keypoint
,
const
std
::
string
&
output_dir
=
"output"
)
{
// Open video
// Open video
cv
::
VideoCapture
capture
;
cv
::
VideoCapture
capture
;
std
::
string
video_out_name
=
"output.mp4"
;
if
(
FLAGS_camera_id
!=
-
1
){
if
(
FLAGS_camera_id
!=
-
1
){
capture
.
open
(
FLAGS_camera_id
);
capture
.
open
(
FLAGS_camera_id
);
}
else
{
}
else
{
capture
.
open
(
video_path
.
c_str
());
capture
.
open
(
video_path
.
c_str
());
video_out_name
=
video_path
.
substr
(
video_path
.
find_last_of
(
OS_PATH_SEP
)
+
1
);
}
}
if
(
!
capture
.
isOpened
())
{
if
(
!
capture
.
isOpened
())
{
printf
(
"can not open video : %s
\n
"
,
video_path
.
c_str
());
printf
(
"can not open video : %s
\n
"
,
video_path
.
c_str
());
return
;
return
;
}
}
// Get Video info : resolution, fps
// Get Video info : resolution, fps
, frame count
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_width
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_height
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
int
video_fps
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FPS
));
int
video_frame_count
=
static_cast
<
int
>
(
capture
.
get
(
CV_CAP_PROP_FRAME_COUNT
));
printf
(
"fps: %d, frame_count: %d
\n
"
,
video_fps
,
video_frame_count
);
// Create VideoWriter for output
// Create VideoWriter for output
cv
::
VideoWriter
video_out
;
cv
::
VideoWriter
video_out
;
std
::
string
video_out_path
=
"output.mp4"
;
std
::
string
video_out_path
(
output_dir
);
if
(
output_dir
.
rfind
(
OS_PATH_SEP
)
!=
output_dir
.
size
()
-
1
)
{
video_out_path
+=
OS_PATH_SEP
;
}
video_out_path
+=
video_out_name
;
video_out
.
open
(
video_out_path
.
c_str
(),
video_out
.
open
(
video_out_path
.
c_str
(),
0x00000021
,
0x00000021
,
video_fps
,
video_fps
,
...
@@ -184,7 +193,7 @@ void PredictVideo(const std::string& video_path,
...
@@ -184,7 +193,7 @@ void PredictVideo(const std::string& video_path,
std
::
vector
<
int
>
colormap_kpts
=
PaddleDetection
::
GenerateColorMap
(
20
);
std
::
vector
<
int
>
colormap_kpts
=
PaddleDetection
::
GenerateColorMap
(
20
);
// Capture all frames and do inference
// Capture all frames and do inference
cv
::
Mat
frame
;
cv
::
Mat
frame
;
int
frame_id
=
0
;
int
frame_id
=
1
;
bool
is_rbox
=
false
;
bool
is_rbox
=
false
;
while
(
capture
.
read
(
frame
))
{
while
(
capture
.
read
(
frame
))
{
if
(
frame
.
empty
())
{
if
(
frame
.
empty
())
{
...
@@ -192,8 +201,14 @@ void PredictVideo(const std::string& video_path,
...
@@ -192,8 +201,14 @@ void PredictVideo(const std::string& video_path,
}
}
std
::
vector
<
cv
::
Mat
>
imgs
;
std
::
vector
<
cv
::
Mat
>
imgs
;
imgs
.
push_back
(
frame
);
imgs
.
push_back
(
frame
);
det
->
Predict
(
imgs
,
0.5
,
0
,
1
,
&
result
,
&
bbox_num
,
&
det_times
);
printf
(
"detect frame: %d
\n
"
,
frame_id
);
det
->
Predict
(
imgs
,
FLAGS_threshold
,
0
,
1
,
&
result
,
&
bbox_num
,
&
det_times
);
std
::
vector
<
PaddleDetection
::
ObjectResult
>
out_result
;
for
(
const
auto
&
item
:
result
)
{
for
(
const
auto
&
item
:
result
)
{
if
(
item
.
confidence
<
FLAGS_threshold
||
item
.
class_id
==
-
1
)
{
continue
;
}
out_result
.
push_back
(
item
);
if
(
item
.
rect
.
size
()
>
6
){
if
(
item
.
rect
.
size
()
>
6
){
is_rbox
=
true
;
is_rbox
=
true
;
printf
(
"class=%d confidence=%.4f rect=[%d %d %d %d %d %d %d %d]
\n
"
,
printf
(
"class=%d confidence=%.4f rect=[%d %d %d %d %d %d %d %d]
\n
"
,
...
@@ -221,9 +236,9 @@ void PredictVideo(const std::string& video_path,
...
@@ -221,9 +236,9 @@ void PredictVideo(const std::string& video_path,
if
(
keypoint
)
if
(
keypoint
)
{
{
int
imsize
=
result
.
size
();
int
imsize
=
out_
result
.
size
();
for
(
int
i
=
0
;
i
<
imsize
;
i
++
){
for
(
int
i
=
0
;
i
<
imsize
;
i
++
){
auto
item
=
result
[
i
];
auto
item
=
out_
result
[
i
];
cv
::
Mat
crop_img
;
cv
::
Mat
crop_img
;
std
::
vector
<
double
>
keypoint_times
;
std
::
vector
<
double
>
keypoint_times
;
std
::
vector
<
int
>
rect
=
{
item
.
rect
[
0
],
item
.
rect
[
1
],
item
.
rect
[
2
],
item
.
rect
[
3
]};
std
::
vector
<
int
>
rect
=
{
item
.
rect
[
0
],
item
.
rect
[
1
],
item
.
rect
[
2
],
item
.
rect
[
3
]};
...
@@ -239,7 +254,7 @@ void PredictVideo(const std::string& video_path,
...
@@ -239,7 +254,7 @@ void PredictVideo(const std::string& video_path,
if
(
imgs_kpts
.
size
()
==
FLAGS_batch_size_keypoint
||
((
i
==
imsize
-
1
)
&&!
imgs_kpts
.
empty
()))
if
(
imgs_kpts
.
size
()
==
FLAGS_batch_size_keypoint
||
((
i
==
imsize
-
1
)
&&!
imgs_kpts
.
empty
()))
{
{
keypoint
->
Predict
(
imgs_kpts
,
center_bs
,
scale_bs
,
0.5
,
0
,
1
,
&
result_kpts
,
&
keypoint_times
);
keypoint
->
Predict
(
imgs_kpts
,
center_bs
,
scale_bs
,
FLAGS_threshold
,
0
,
1
,
&
result_kpts
,
&
keypoint_times
);
imgs_kpts
.
clear
();
imgs_kpts
.
clear
();
center_bs
.
clear
();
center_bs
.
clear
();
scale_bs
.
clear
();
scale_bs
.
clear
();
...
@@ -251,7 +266,7 @@ void PredictVideo(const std::string& video_path,
...
@@ -251,7 +266,7 @@ void PredictVideo(const std::string& video_path,
else
{
else
{
// Visualization result
// Visualization result
cv
::
Mat
out_im
=
PaddleDetection
::
VisualizeResult
(
cv
::
Mat
out_im
=
PaddleDetection
::
VisualizeResult
(
frame
,
result
,
labels
,
colormap
,
is_rbox
);
frame
,
out_
result
,
labels
,
colormap
,
is_rbox
);
video_out
.
write
(
out_im
);
video_out
.
write
(
out_im
);
}
}
...
@@ -450,12 +465,12 @@ int main(int argc, char** argv) {
...
@@ -450,12 +465,12 @@ int main(int argc, char** argv) {
FLAGS_trt_calib_mode
,
FLAGS_use_dark
);
FLAGS_trt_calib_mode
,
FLAGS_use_dark
);
}
}
// Do inference on input video or image
// Do inference on input video or image
if
(
!
PathExists
(
FLAGS_output_dir
))
{
MkDirs
(
FLAGS_output_dir
);
}
if
(
!
FLAGS_video_file
.
empty
()
||
FLAGS_camera_id
!=
-
1
)
{
if
(
!
FLAGS_video_file
.
empty
()
||
FLAGS_camera_id
!=
-
1
)
{
PredictVideo
(
FLAGS_video_file
,
&
det
,
keypoint
);
PredictVideo
(
FLAGS_video_file
,
&
det
,
keypoint
,
FLAGS_output_dir
);
}
else
if
(
!
FLAGS_image_file
.
empty
()
||
!
FLAGS_image_dir
.
empty
())
{
}
else
if
(
!
FLAGS_image_file
.
empty
()
||
!
FLAGS_image_dir
.
empty
())
{
if
(
!
PathExists
(
FLAGS_output_dir
))
{
MkDirs
(
FLAGS_output_dir
);
}
std
::
vector
<
std
::
string
>
all_img_paths
;
std
::
vector
<
std
::
string
>
all_img_paths
;
std
::
vector
<
cv
::
String
>
cv_all_img_paths
;
std
::
vector
<
cv
::
String
>
cv_all_img_paths
;
if
(
!
FLAGS_image_file
.
empty
())
{
if
(
!
FLAGS_image_file
.
empty
())
{
...
...
deploy/python/det_keypoint_unite_infer.py
浏览文件 @
97373901
...
@@ -133,22 +133,24 @@ def topdown_unite_predict_video(detector,
...
@@ -133,22 +133,24 @@ def topdown_unite_predict_video(detector,
topdown_keypoint_detector
,
topdown_keypoint_detector
,
camera_id
,
camera_id
,
keypoint_batch_size
=
1
):
keypoint_batch_size
=
1
):
video_name
=
'output.mp4'
if
camera_id
!=
-
1
:
if
camera_id
!=
-
1
:
capture
=
cv2
.
VideoCapture
(
camera_id
)
capture
=
cv2
.
VideoCapture
(
camera_id
)
video_name
=
'output.mp4'
else
:
else
:
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
video_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
FLAGS
.
video_file
))[
video_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
FLAGS
.
video_file
))[
0
]
+
'.mp4'
0
]
+
'.mp4'
fps
=
30
# Get Video info : resolution, fps, frame count
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
# yapf: disable
fps
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FPS
))
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
# yapf: enable
print
(
"fps: %d, frame_count: %d"
%
(
fps
,
frame_count
))
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
os
.
makedirs
(
FLAGS
.
output_dir
)
os
.
makedirs
(
FLAGS
.
output_dir
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
index
=
0
index
=
0
while
(
1
):
while
(
1
):
...
@@ -156,7 +158,7 @@ def topdown_unite_predict_video(detector,
...
@@ -156,7 +158,7 @@ def topdown_unite_predict_video(detector,
if
not
ret
:
if
not
ret
:
break
break
index
+=
1
index
+=
1
print
(
'detect frame:%d'
%
(
index
))
print
(
'detect frame:
%d'
%
(
index
))
frame2
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
frame2
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
results
=
detector
.
predict
([
frame2
],
FLAGS
.
det_threshold
)
results
=
detector
.
predict
([
frame2
],
FLAGS
.
det_threshold
)
...
...
deploy/python/infer.py
浏览文件 @
97373901
...
@@ -664,30 +664,30 @@ def predict_image(detector, image_list, batch_size=1):
...
@@ -664,30 +664,30 @@ def predict_image(detector, image_list, batch_size=1):
def
predict_video
(
detector
,
camera_id
):
def
predict_video
(
detector
,
camera_id
):
video_out_name
=
'output.mp4'
if
camera_id
!=
-
1
:
if
camera_id
!=
-
1
:
capture
=
cv2
.
VideoCapture
(
camera_id
)
capture
=
cv2
.
VideoCapture
(
camera_id
)
video_name
=
'output.mp4'
else
:
else
:
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
video_out_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
fps
=
30
# Get Video info : resolution, fps, frame count
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
print
(
'frame_count'
,
frame_count
)
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
# yapf: disable
fps
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FPS
))
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
# yapf: enable
print
(
"fps: %d, frame_count: %d"
%
(
fps
,
frame_count
))
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
os
.
makedirs
(
FLAGS
.
output_dir
)
os
.
makedirs
(
FLAGS
.
output_dir
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_out_name
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
index
=
1
index
=
1
while
(
1
):
while
(
1
):
ret
,
frame
=
capture
.
read
()
ret
,
frame
=
capture
.
read
()
if
not
ret
:
if
not
ret
:
break
break
print
(
'detect frame:%d'
%
(
index
))
print
(
'detect frame:
%d'
%
(
index
))
index
+=
1
index
+=
1
results
=
detector
.
predict
([
frame
],
FLAGS
.
threshold
)
results
=
detector
.
predict
([
frame
],
FLAGS
.
threshold
)
im
=
visualize_box_mask
(
im
=
visualize_box_mask
(
...
...
deploy/python/keypoint_infer.py
浏览文件 @
97373901
...
@@ -284,28 +284,30 @@ def predict_image(detector, image_list):
...
@@ -284,28 +284,30 @@ def predict_image(detector, image_list):
def
predict_video
(
detector
,
camera_id
):
def
predict_video
(
detector
,
camera_id
):
video_name
=
'output.mp4'
if
camera_id
!=
-
1
:
if
camera_id
!=
-
1
:
capture
=
cv2
.
VideoCapture
(
camera_id
)
capture
=
cv2
.
VideoCapture
(
camera_id
)
video_name
=
'output.mp4'
else
:
else
:
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
fps
=
30
# Get Video info : resolution, fps, frame count
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
# yapf: disable
fps
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FPS
))
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
# yapf: enable
print
(
"fps: %d, frame_count: %d"
%
(
fps
,
frame_count
))
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
os
.
makedirs
(
FLAGS
.
output_dir
)
os
.
makedirs
(
FLAGS
.
output_dir
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
+
'.mp4'
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
+
'.mp4'
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
index
=
1
index
=
1
while
(
1
):
while
(
1
):
ret
,
frame
=
capture
.
read
()
ret
,
frame
=
capture
.
read
()
if
not
ret
:
if
not
ret
:
break
break
print
(
'detect frame:%d'
%
(
index
))
print
(
'detect frame:
%d'
%
(
index
))
index
+=
1
index
+=
1
results
=
detector
.
predict
([
frame
],
FLAGS
.
threshold
)
results
=
detector
.
predict
([
frame
],
FLAGS
.
threshold
)
im
=
draw_pose
(
im
=
draw_pose
(
...
...
deploy/python/mot_jde_infer.py
浏览文件 @
97373901
...
@@ -212,24 +212,24 @@ def predict_image(detector, image_list):
...
@@ -212,24 +212,24 @@ def predict_image(detector, image_list):
def
predict_video
(
detector
,
camera_id
):
def
predict_video
(
detector
,
camera_id
):
video_name
=
'mot_output.mp4'
if
camera_id
!=
-
1
:
if
camera_id
!=
-
1
:
capture
=
cv2
.
VideoCapture
(
camera_id
)
capture
=
cv2
.
VideoCapture
(
camera_id
)
video_name
=
'mot_output.mp4'
else
:
else
:
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
fps
=
30
# Get Video info : resolution, fps, frame count
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
print
(
'frame_count'
,
frame_count
)
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
# yapf: disable
fps
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FPS
))
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
# yapf: enable
print
(
"fps: %d, frame_count: %d"
%
(
fps
,
frame_count
))
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
os
.
makedirs
(
FLAGS
.
output_dir
)
os
.
makedirs
(
FLAGS
.
output_dir
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
if
not
FLAGS
.
save_images
:
if
not
FLAGS
.
save_images
:
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
frame_id
=
0
frame_id
=
0
timer
=
MOTTimer
()
timer
=
MOTTimer
()
...
@@ -270,7 +270,7 @@ def predict_video(detector, camera_id):
...
@@ -270,7 +270,7 @@ def predict_video(detector, camera_id):
write_mot_results
(
result_filename
,
[
results
[
-
1
]])
write_mot_results
(
result_filename
,
[
results
[
-
1
]])
frame_id
+=
1
frame_id
+=
1
print
(
'detect frame:%d'
%
(
frame_id
))
print
(
'detect frame:
%d'
%
(
frame_id
))
if
camera_id
!=
-
1
:
if
camera_id
!=
-
1
:
cv2
.
imshow
(
'Tracking Detection'
,
im
)
cv2
.
imshow
(
'Tracking Detection'
,
im
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
...
...
deploy/python/mot_keypoint_unite_infer.py
浏览文件 @
97373901
...
@@ -126,18 +126,18 @@ def mot_keypoint_unite_predict_video(mot_model,
...
@@ -126,18 +126,18 @@ def mot_keypoint_unite_predict_video(mot_model,
else
:
else
:
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
fps
=
30
# Get Video info : resolution, fps, frame count
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
print
(
'frame_count'
,
frame_count
)
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
# yapf: disable
fps
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FPS
))
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
# yapf: enable
print
(
"fps: %d, frame_count: %d"
%
(
fps
,
frame_count
))
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
os
.
makedirs
(
FLAGS
.
output_dir
)
os
.
makedirs
(
FLAGS
.
output_dir
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
if
not
FLAGS
.
save_images
:
if
not
FLAGS
.
save_images
:
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
frame_id
=
0
frame_id
=
0
timer_mot
=
FPSTimer
()
timer_mot
=
FPSTimer
()
...
@@ -195,7 +195,7 @@ def mot_keypoint_unite_predict_video(mot_model,
...
@@ -195,7 +195,7 @@ def mot_keypoint_unite_predict_video(mot_model,
im
=
np
.
array
(
online_im
)
im
=
np
.
array
(
online_im
)
frame_id
+=
1
frame_id
+=
1
print
(
'detect frame:%d'
%
(
frame_id
))
print
(
'detect frame:
%d'
%
(
frame_id
))
if
FLAGS
.
save_images
:
if
FLAGS
.
save_images
:
save_dir
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
.
split
(
'.'
)[
-
2
])
save_dir
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
.
split
(
'.'
)[
-
2
])
...
...
deploy/python/mot_sde_infer.py
浏览文件 @
97373901
...
@@ -355,18 +355,18 @@ def predict_video(detector, reid_model, camera_id):
...
@@ -355,18 +355,18 @@ def predict_video(detector, reid_model, camera_id):
else
:
else
:
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
capture
=
cv2
.
VideoCapture
(
FLAGS
.
video_file
)
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
video_name
=
os
.
path
.
split
(
FLAGS
.
video_file
)[
-
1
]
fps
=
30
# Get Video info : resolution, fps, frame count
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
print
(
'frame_count'
,
frame_count
)
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
width
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
height
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
))
# yapf: disable
fps
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FPS
))
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
frame_count
=
int
(
capture
.
get
(
cv2
.
CAP_PROP_FRAME_COUNT
))
# yapf: enable
print
(
"fps: %d, frame_count: %d"
%
(
fps
,
frame_count
))
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
if
not
os
.
path
.
exists
(
FLAGS
.
output_dir
):
os
.
makedirs
(
FLAGS
.
output_dir
)
os
.
makedirs
(
FLAGS
.
output_dir
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
out_path
=
os
.
path
.
join
(
FLAGS
.
output_dir
,
video_name
)
if
not
FLAGS
.
save_images
:
if
not
FLAGS
.
save_images
:
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
'mp4v'
)
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
frame_id
=
0
frame_id
=
0
timer
=
MOTTimer
()
timer
=
MOTTimer
()
...
@@ -425,7 +425,7 @@ def predict_video(detector, reid_model, camera_id):
...
@@ -425,7 +425,7 @@ def predict_video(detector, reid_model, camera_id):
write_mot_results
(
result_filename
,
[
result
])
write_mot_results
(
result_filename
,
[
result
])
frame_id
+=
1
frame_id
+=
1
print
(
'detect frame:%d'
%
(
frame_id
))
print
(
'detect frame:
%d'
%
(
frame_id
))
if
camera_id
!=
-
1
:
if
camera_id
!=
-
1
:
cv2
.
imshow
(
'Tracking Detection'
,
im
)
cv2
.
imshow
(
'Tracking Detection'
,
im
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录