Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
7d6af696
Unverified
提交
7d6af696
authored
6月 30, 2021
作者:
Feras Oughali
提交者:
GitHub
6月 30, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix `LoadStreams()` dataloader frame skip issue (#3833)
* Update datasets.py to read every 4th frame of streams * Update datasets.py Co-authored-by:
Glenn Jocher
<
glenn.jocher@ultralytics.com
>
上级
57c5d02b
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
5 行增加
和
22 行删除
+5
-22
datasets.py
utils/datasets.py
+5
-22
没有找到文件。
utils/datasets.py
浏览文件 @
7d6af696
...
@@ -4,7 +4,6 @@ import glob
...
@@ -4,7 +4,6 @@ import glob
import
hashlib
import
hashlib
import
json
import
json
import
logging
import
logging
import
math
import
os
import
os
import
random
import
random
import
shutil
import
shutil
...
@@ -15,6 +14,7 @@ from pathlib import Path
...
@@ -15,6 +14,7 @@ from pathlib import Path
from
threading
import
Thread
from
threading
import
Thread
import
cv2
import
cv2
import
math
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
...
@@ -210,15 +210,8 @@ class LoadWebcam: # for inference
...
@@ -210,15 +210,8 @@ class LoadWebcam: # for inference
def
__init__
(
self
,
pipe
=
'0'
,
img_size
=
640
,
stride
=
32
):
def
__init__
(
self
,
pipe
=
'0'
,
img_size
=
640
,
stride
=
32
):
self
.
img_size
=
img_size
self
.
img_size
=
img_size
self
.
stride
=
stride
self
.
stride
=
stride
self
.
pipe
=
eval
(
pipe
)
if
pipe
.
isnumeric
()
else
pipe
if
pipe
.
isnumeric
():
self
.
cap
=
cv2
.
VideoCapture
(
self
.
pipe
)
# video capture object
pipe
=
eval
(
pipe
)
# local camera
# pipe = 'rtsp://192.168.1.64/1' # IP camera
# pipe = 'rtsp://username:password@192.168.1.64/1' # IP camera with login
# pipe = 'http://wmccpinetop.axiscam.net/mjpg/video.mjpg' # IP golf camera
self
.
pipe
=
pipe
self
.
cap
=
cv2
.
VideoCapture
(
pipe
)
# video capture object
self
.
cap
.
set
(
cv2
.
CAP_PROP_BUFFERSIZE
,
3
)
# set buffer size
self
.
cap
.
set
(
cv2
.
CAP_PROP_BUFFERSIZE
,
3
)
# set buffer size
def
__iter__
(
self
):
def
__iter__
(
self
):
...
@@ -233,18 +226,8 @@ class LoadWebcam: # for inference
...
@@ -233,18 +226,8 @@ class LoadWebcam: # for inference
raise
StopIteration
raise
StopIteration
# Read frame
# Read frame
if
self
.
pipe
==
0
:
# local camera
ret_val
,
img0
=
self
.
cap
.
read
()
ret_val
,
img0
=
self
.
cap
.
read
()
img0
=
cv2
.
flip
(
img0
,
1
)
# flip left-right
img0
=
cv2
.
flip
(
img0
,
1
)
# flip left-right
else
:
# IP camera
n
=
0
while
True
:
n
+=
1
self
.
cap
.
grab
()
if
n
%
30
==
0
:
# skip frames
ret_val
,
img0
=
self
.
cap
.
retrieve
()
if
ret_val
:
break
# Print
# Print
assert
ret_val
,
f
'Camera Error {self.pipe}'
assert
ret_val
,
f
'Camera Error {self.pipe}'
...
@@ -308,12 +291,12 @@ class LoadStreams: # multiple IP or RTSP cameras
...
@@ -308,12 +291,12 @@ class LoadStreams: # multiple IP or RTSP cameras
def
update
(
self
,
i
,
cap
):
def
update
(
self
,
i
,
cap
):
# Read stream `i` frames in daemon thread
# Read stream `i` frames in daemon thread
n
,
f
=
0
,
self
.
frames
[
i
]
n
,
f
,
read
=
0
,
self
.
frames
[
i
],
1
# frame number, frame array, inference every 'read' frame
while
cap
.
isOpened
()
and
n
<
f
:
while
cap
.
isOpened
()
and
n
<
f
:
n
+=
1
n
+=
1
# _, self.imgs[index] = cap.read()
# _, self.imgs[index] = cap.read()
cap
.
grab
()
cap
.
grab
()
if
n
%
4
:
# read every 4th frame
if
n
%
read
==
0
:
success
,
im
=
cap
.
retrieve
()
success
,
im
=
cap
.
retrieve
()
self
.
imgs
[
i
]
=
im
if
success
else
self
.
imgs
[
i
]
*
0
self
.
imgs
[
i
]
=
im
if
success
else
self
.
imgs
[
i
]
*
0
time
.
sleep
(
1
/
self
.
fps
[
i
])
# wait time
time
.
sleep
(
1
/
self
.
fps
[
i
])
# wait time
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论