Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
7674414a
提交
7674414a
authored
8月 01, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
21ac0c5a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
53 行增加
和
45 行删除
+53
-45
motion_files.py
opencv-motion-detect/motion_files.py
+53
-45
没有找到文件。
opencv-motion-detect/motion_files.py
浏览文件 @
7674414a
...
@@ -19,6 +19,7 @@ class FrameFetcher(Thread):
...
@@ -19,6 +19,7 @@ class FrameFetcher(Thread):
self
.
fps
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
self
.
fps
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
self
.
frameCnt
=
0
self
.
frameCnt
=
0
self
.
failedPutCnt
=
0
self
.
failedPutCnt
=
0
self
.
frameSeq
=
0
print
(
self
.
width
,
self
.
height
,
self
.
fps
)
print
(
self
.
width
,
self
.
height
,
self
.
fps
)
else
:
else
:
self
.
cap
=
None
self
.
cap
=
None
...
@@ -37,6 +38,7 @@ class FrameFetcher(Thread):
...
@@ -37,6 +38,7 @@ class FrameFetcher(Thread):
if
self
.
videoProto
==
'RTSP'
:
if
self
.
videoProto
==
'RTSP'
:
while
True
:
while
True
:
while
self
.
cap
.
isOpened
():
while
self
.
cap
.
isOpened
():
start
=
datetime
.
datetime
.
now
()
.
timestamp
()
ret
,
frame
=
self
.
cap
.
read
()
ret
,
frame
=
self
.
cap
.
read
()
if
ret
:
if
ret
:
try
:
try
:
...
@@ -51,67 +53,73 @@ class FrameFetcher(Thread):
...
@@ -51,67 +53,73 @@ class FrameFetcher(Thread):
self
.
frameCnt
+=
1
self
.
frameCnt
+=
1
else
:
else
:
print
(
"error read frame"
)
print
(
"error read frame"
)
exit
(
1
)
break
time
.
sleep
(
1.0
/
self
.
fps
)
delta
=
datetime
.
datetime
.
now
()
.
timestamp
()
-
start
delta
=
1.0
/
self
.
fps
-
delta
if
delta
>
0
:
time
.
sleep
(
delta
)
time
.
sleep
(
1.0
/
self
.
fps
)
print
(
"error: cap is not opened, reconnecting..."
)
print
(
"error: cap is not opened, reconnecting..."
)
self
.
init
()
self
.
init
()
else
:
else
:
# it's folder, process video slices in double speed
# it's folder, process video slices in double speed
currentIdx
=
-
1
currentFile
=
None
lastIdx
=
-
1
startup
=
True
while
True
:
while
True
:
try
:
try
:
videos
=
[
'{}/{}'
.
format
(
self
.
env
[
'VIDEO_ADDR'
],
f
)
for
f
in
os
.
listdir
(
self
.
env
[
'VIDEO_ADDR'
])
if
f
.
startswith
(
self
.
env
[
'SLICE_BASENAME'
])]
videos
=
[{
'f'
:
'{}/{}'
.
format
(
self
.
env
[
'VIDEO_ADDR'
],
f
),
't'
:
os
.
stat
(
self
.
env
[
'VIDEO_ADDR'
]
+
'/'
+
f
)
.
st_mtime
}
for
f
in
os
.
listdir
(
self
.
env
[
'VIDEO_ADDR'
])
if
f
.
startswith
(
self
.
env
[
'SLICE_BASENAME'
])]
videos
=
sorted
(
videos
,
key
=
lambda
x
:
os
.
stat
(
x
)
.
st_mtime
)
videos
=
sorted
(
videos
,
key
=
lambda
x
:
x
[
't'
])
if
len
(
videos
)
<
2
:
idx
=
0
if
currentFile
:
for
k
,
v
in
enumerate
(
videos
):
if
v
[
'f'
]
==
currentFile
[
'f'
]
and
v
[
't'
]
==
currentFile
[
't'
]:
idx
=
k
if
len
(
videos
)
<
2
or
(
currentFile
and
(
idx
==
len
(
videos
)
-
2
)):
print
(
'waiting for next video ...'
)
print
(
'waiting for next video ...'
)
else
:
else
:
z
=
re
.
match
(
r'.*?'
+
self
.
env
[
'SLICE_BASENAME'
]
+
'(
\
d+)
\
..*?'
+
self
.
env
[
'SLICE_BASENAME'
]
+
'(
\
d+)
\
..*?'
,
videos
[
0
]
+
videos
[
-
1
])
for
f
in
videos
[
idx
:
-
1
]:
if
z
:
if
self
.
cap
!=
None
:
currentIdx
=
int
(
z
.
group
(
1
))
self
.
cap
.
release
()
lastIdx
=
int
(
z
.
group
(
2
))
print
(
'openning {}'
.
format
(
f
))
else
:
self
.
cap
=
cv2
.
VideoCapture
(
f
[
'f'
])
print
(
'no matched video files'
)
if
not
self
.
cap
.
isOpened
():
continue
print
(
'failed to open file: {}'
.
format
(
f
))
print
(
'currentIdx: {}, lastIdx: {}'
.
format
(
currentIdx
,
lastIdx
))
continue
if
not
currentFile
:
for
f
in
videos
[:
-
1
]:
self
.
height
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
)
if
self
.
cap
!=
None
:
self
.
width
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
)
self
.
cap
.
release
()
self
.
fps
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
self
.
cap
=
cv2
.
VideoCapture
(
f
)
self
.
fps
=
self
.
fps
*
2
if
not
self
.
cap
.
isOpened
():
self
.
frameCnt
=
0
print
(
'failed to open file: {}'
.
format
(
f
))
self
.
failedPutCnt
=
0
continue
print
(
self
.
width
,
self
.
height
,
self
.
fps
)
if
startup
:
self
.
height
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FRAME_HEIGHT
)
currentFile
=
f
self
.
width
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FRAME_WIDTH
)
while
True
:
self
.
fps
=
self
.
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
try
:
self
.
fps
=
self
.
fps
*
2
self
.
frameCnt
=
0
self
.
failedPutCnt
=
0
print
(
self
.
width
,
self
.
height
,
self
.
fps
)
while
True
:
ret
,
frame
=
self
.
cap
.
read
()
ret
,
frame
=
self
.
cap
.
read
()
if
ret
:
if
ret
:
try
:
self
.
frameHolder
.
append
(
frame
)
self
.
frameHolder
.
append
(
frame
)
self
.
frameSeq
+=
self
.
cap
.
get
(
cv2
.
CAP_PROP_POS_FRAMES
)
if
self
.
frameCnt
%
(
self
.
fps
*
2
)
==
0
:
# calc frame time
print
(
"frameCnt: "
,
self
.
frameCnt
)
except
:
self
.
frameCnt
+=
1
self
.
failedPutCnt
+=
1
if
self
.
frameCnt
%
(
self
.
fps
*
2
)
==
0
:
if
self
.
failedPutCnt
%
(
self
.
fps
*
2
)
==
0
:
print
(
"frameCnt:{}, file: {}, fseq: {}"
.
format
(
self
.
frameCnt
,
f
[
'f'
],
))
print
(
"failedPutCnt: "
,
self
.
failedPutCnt
)
finally
:
self
.
frameCnt
+=
1
else
:
else
:
print
(
"error read frame"
)
break
except
:
traceback
.
print_exc
()
print
(
"error read frame"
)
self
.
cap
.
release
()
self
.
cap
=
None
break
finally
:
time
.
sleep
(
1.0
/
self
.
fps
)
time
.
sleep
(
1.0
/
self
.
fps
)
except
:
except
:
traceback
.
print_exc
()
traceback
.
print_exc
()
finally
:
finally
:
time
.
sleep
(
2
)
time
.
sleep
(
2
)
exit
(
1
)
class
MotionDetector
(
Thread
):
class
MotionDetector
(
Thread
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论