Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
f99bf983
提交
f99bf983
authored
2月 10, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ai.detect: region feature
上级
260a5a91
流水线
#34
已取消 于阶段
变更
2
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
67 行增加
和
16 行删除
+67
-16
evslicer.cpp
opencv-motion-detect/evslicer.cpp
+1
-0
detect_video.py
opencv-yolo/web/detect_video.py
+66
-16
没有找到文件。
opencv-motion-detect/evslicer.cpp
浏览文件 @
f99bf983
...
@@ -936,6 +936,7 @@ public:
...
@@ -936,6 +936,7 @@ public:
}
}
spdlog
::
info
(
"{} boot"
,
selfId
);
spdlog
::
info
(
"{} boot"
,
selfId
);
//TODO: single process
SingletonProcess
self
(
selfName
,
iid
);
SingletonProcess
self
(
selfName
,
iid
);
if
(
!
self
()){
if
(
!
self
()){
spdlog
::
error
(
"{} already running. ignore this instance"
,
selfId
);
spdlog
::
error
(
"{} already running. ignore this instance"
,
selfId
);
...
...
opencv-yolo/web/detect_video.py
浏览文件 @
f99bf983
...
@@ -2,21 +2,28 @@
...
@@ -2,21 +2,28 @@
import
argparse
import
argparse
import
torch
import
torch
from
src.config
import
COCO_CLASSES
,
colors
from
src.config
import
COCO_CLASSES
,
colors
import
cv2
,
datetime
import
cv2
import
datetime
import
numpy
as
np
import
numpy
as
np
def
get_args
():
def
get_args
():
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
"EfficientDet: Scalable and Efficient Object Detection implementation by Signatrix GmbH"
)
"EfficientDet: Scalable and Efficient Object Detection implementation by Signatrix GmbH"
)
parser
.
add_argument
(
"--image_size"
,
type
=
int
,
default
=
512
,
help
=
"The common width and height for all images"
)
parser
.
add_argument
(
"--image_size"
,
type
=
int
,
default
=
512
,
help
=
"The common width and height for all images"
)
parser
.
add_argument
(
"--cls_threshold"
,
type
=
float
,
default
=
0.5
)
parser
.
add_argument
(
"--cls_threshold"
,
type
=
float
,
default
=
0.5
)
parser
.
add_argument
(
"--nms_threshold"
,
type
=
float
,
default
=
0.5
)
parser
.
add_argument
(
"--nms_threshold"
,
type
=
float
,
default
=
0.5
)
parser
.
add_argument
(
"-c"
,
"--pretrained_model"
,
type
=
str
,
default
=
"edet_model.pth"
)
parser
.
add_argument
(
"-s"
,
"--scale"
,
type
=
str
,
default
=
'0,0,1,1'
)
parser
.
add_argument
(
"-c"
,
"--pretrained_model"
,
type
=
str
,
default
=
"edet_model.pth"
)
parser
.
add_argument
(
"input"
,
type
=
str
,
default
=
"input.mp4"
)
parser
.
add_argument
(
"input"
,
type
=
str
,
default
=
"input.mp4"
)
parser
.
add_argument
(
"-o"
,
"--output"
,
type
=
str
,
default
=
"detect_person.jpg"
)
parser
.
add_argument
(
"-o"
,
"--output"
,
type
=
str
,
default
=
"detect_person.jpg"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
return
args
return
args
def
test
(
opt
):
def
test
(
opt
):
tsEpoch
=
datetime
.
datetime
.
utcfromtimestamp
(
0
)
tsEpoch
=
datetime
.
datetime
.
utcfromtimestamp
(
0
)
model
=
torch
.
load
(
opt
.
pretrained_model
,
map_location
=
'cpu'
)
.
module
model
=
torch
.
load
(
opt
.
pretrained_model
,
map_location
=
'cpu'
)
.
module
...
@@ -31,19 +38,58 @@ def test(opt):
...
@@ -31,19 +38,58 @@ def test(opt):
fname
=
opt
.
output
+
"_"
+
str
(
ts
)
+
".jpg"
fname
=
opt
.
output
+
"_"
+
str
(
ts
)
+
".jpg"
frameCnt
=
0
frameCnt
=
0
tsStart
=
datetime
.
datetime
.
now
()
tsStart
=
datetime
.
datetime
.
now
()
x1
,
y1
,
x2
,
y2
=
opt
.
scale
.
split
(
','
)
try
:
x1
=
float
(
x1
)
y1
=
float
(
y1
)
x2
=
float
(
x2
)
y2
=
float
(
y2
)
if
x1
<
0
or
y1
<
0
or
x2
>
1
or
y2
>
1
or
x1
>
x2
or
y1
>
y2
:
raise
except
:
print
(
"invalid region config: {}"
.
format
(
opt
.
scale
))
x1
=
0
y2
=
0
x2
=
1
y2
=
1
hasRegion
=
False
if
x1
==
0
and
y1
==
0
and
x2
==
1
and
y2
==
1
:
pass
else
:
print
(
"region: {}, {}, {}, {}"
.
format
(
x1
,
y1
,
x2
,
y2
))
hasRegion
=
True
while
cap
.
isOpened
():
while
cap
.
isOpened
():
image
=
None
flag
,
image
=
cap
.
read
()
flag
,
image
=
cap
.
read
()
output_image
=
np
.
copy
(
image
)
height
=
None
width
=
None
if
flag
:
if
flag
:
height
,
width
=
image
.
shape
[:
2
]
output_image
=
np
.
copy
(
image
)
if
hasRegion
:
ratio
=
width
/
(
height
*
1.0
)
px1
=
int
(
width
*
x1
)
py1
=
int
(
height
*
y1
)
px2
=
int
(
width
*
x2
)
py2
=
int
(
height
*
y2
)
# height = py2 - py1
# width = px2 - px1
# image = image[py1:py2, px1:px2]
image
[
0
:
py1
,:,:]
=
0
image
[
py2
:,
:,
:]
=
0
image
[:,
0
:
px1
,
:]
=
0
image
[:,
px2
:,
:]
=
0
#output_image = np.copy(image)
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2RGB
)
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2RGB
)
else
:
else
:
break
break
frameCnt
+=
1
frameCnt
+=
1
if
frameCnt
%
(
18
*
3
)
==
0
:
if
frameCnt
%
(
18
*
3
)
==
0
:
pass
pass
else
:
else
:
continue
continue
height
,
width
=
image
.
shape
[:
2
]
image
=
image
.
astype
(
np
.
float32
)
/
255
image
=
image
.
astype
(
np
.
float32
)
/
255
image
[:,
:,
0
]
=
(
image
[:,
:,
0
]
-
0.485
)
/
0.229
image
[:,
:,
0
]
=
(
image
[:,
:,
0
]
-
0.485
)
/
0.229
image
[:,
:,
1
]
=
(
image
[:,
:,
1
]
-
0.456
)
/
0.224
image
[:,
:,
1
]
=
(
image
[:,
:,
1
]
-
0.456
)
/
0.224
...
@@ -81,21 +127,24 @@ def test(opt):
...
@@ -81,21 +127,24 @@ def test(opt):
continue
continue
xmin
,
ymin
,
xmax
,
ymax
=
boxes
[
box_id
,
:]
xmin
,
ymin
,
xmax
,
ymax
=
boxes
[
box_id
,
:]
color
=
colors
[
pred_label
]
color
=
colors
[
pred_label
]
color
=
(
255
,
0
,
0
)
color
=
(
255
,
0
,
0
)
font
=
cv2
.
FONT_HERSHEY_PLAIN
font
=
cv2
.
FONT_HERSHEY_PLAIN
cv2
.
rectangle
(
output_image
,
(
xmin
,
ymin
),
(
xmax
,
ymax
),
color
,
1
)
cv2
.
rectangle
(
output_image
,
(
xmin
,
ymin
),
(
xmax
,
ymax
),
color
,
1
)
text_size
=
cv2
.
getTextSize
(
COCO_CLASSES
[
pred_label
]
+
' :
%.2
f'
%
pred_prob
,
font
,
1
,
1
)[
0
]
text_size
=
cv2
.
getTextSize
(
cv2
.
rectangle
(
output_image
,
(
xmin
,
ymin
),
(
xmin
+
text_size
[
0
]
+
1
,
ymin
+
text_size
[
1
]
+
1
),
color
,
-
1
)
COCO_CLASSES
[
pred_label
]
+
' :
%.2
f'
%
pred_prob
,
font
,
1
,
1
)[
0
]
cv2
.
rectangle
(
output_image
,
(
xmin
,
ymin
),
(
xmin
+
text_size
[
0
]
+
1
,
ymin
+
text_size
[
1
]
+
1
),
color
,
-
1
)
cv2
.
putText
(
cv2
.
putText
(
output_image
,
COCO_CLASSES
[
pred_label
]
+
':
%.3
f'
%
pred_prob
,
output_image
,
COCO_CLASSES
[
pred_label
]
+
':
%.3
f'
%
pred_prob
,
(
xmin
,
ymin
+
text_size
[
1
]
+
1
),
font
,
1
,
(
xmin
,
ymin
+
text_size
[
1
]
+
1
),
font
,
1
,
(
255
,
255
,
255
),
1
)
(
255
,
255
,
255
),
1
)
if
not
bDetected
:
if
not
bDetected
:
elapse
=
0
elapse
=
0
if
fps
:
if
fps
:
elapse
=
int
(
frameCnt
/
fps
)
elapse
=
int
(
frameCnt
/
fps
)
strDetMsg
=
"edet found human {:.3f} x: {}, y: {}, w: {}, h: {}; written image: {}; time: {}"
.
format
(
pred_prob
,
int
(
xmin
),
int
(
ymin
),
int
(
xmax
-
xmin
),
int
(
ymax
-
ymin
),
fname
,
elapse
)
strDetMsg
=
"edet found human {:.3f} x: {}, y: {}, w: {}, h: {}; written image: {}; time: {}"
.
format
(
bDetected
=
True
pred_prob
,
int
(
xmin
),
int
(
ymin
),
int
(
xmax
-
xmin
),
int
(
ymax
-
ymin
),
fname
,
elapse
)
bDetected
=
True
if
frameCnt
%
1000
==
0
:
if
frameCnt
%
1000
==
0
:
tsEnd
=
datetime
.
datetime
.
now
()
tsEnd
=
datetime
.
datetime
.
now
()
...
@@ -109,6 +158,7 @@ def test(opt):
...
@@ -109,6 +158,7 @@ def test(opt):
break
break
cap
.
release
()
cap
.
release
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
opt
=
get_args
()
opt
=
get_args
()
opt
.
output
=
opt
.
output
[
0
:
opt
.
output
.
rfind
(
"."
)]
opt
.
output
=
opt
.
output
[
0
:
opt
.
output
.
rfind
(
"."
)]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论