python - Raspberry PI 上的 USB 摄像头显示黑屏
问题描述
我正在做一个项目,我必须使用必须在 Raspberry PI(操作系统:Debian Raspberry PI Desktop)上访问的工业相机(型号 ID:Imaginsource DFK 33UX178)。相机以前工作正常。但是,一旦我连接到 Windows 机器并使用默认的 Windows 相机应用程序调整其设置,然后尝试使用 Raspberry PI OS 访问,它只会捕获黑色图像。
以下是我尝试过的命令。
此外,我尝试使用 OpenCV 脚本(如下),但它抛出错误。
import cv2
with cv2.VideoCapture(0) as camera:
ret = camera.set(3,640)
ret = camera.set(4,480)
try:
stream = io.BytesIO()
while(True):
t1 = cv2.getTickCount()
ret, frame = camera.read()
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame_expanded = np.expand_dims(frame_rgb, axis=0)
start_time = time.time()
results = classify_image(interpreter, frame)
elapsed_ms = (time.time() - start_time) * 1000
label_id, prob = results[0]
stream.seek(0)
stream.truncate()
# camera.annotate_text = '%s %.2f\n%.1fms' % (labels[label_id], prob,
# elapsed_ms)
cv2.putText(frame, labels[label_id],(30,50),font,1,(255,255,0),2,cv2.LINE_AA)
cv2.imshow('Object detector', frame)
if cv2.waitKey(1) == ord('q'):
break
finally:
camera.release()
错误:
Traceback (most recent call last):
File "usb_api.py", line 4, in <module>
with cv2.VideoCapture(0) as camera:
AttributeError: __enter__
虽然命令“lsusb”检测相机如下,它是“The Imaging Source Europe GmbH”
Bus 002 Device 004: ID 199e:9082 The Imaging Source Europe GmbH
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
我对相机的功能有疑问,所以我再次尝试使用 Windows 机器,它运行良好。
有人可以帮我解决这个问题吗?
谢谢
解决方案
推荐阅读
- python - Django Rest Framework - AttributeError:'function'对象没有属性'get_extra_actions'
- neo4j - neo4j 节点属性占用的最小磁盘空间是多少?
- angular - 从 Angular 11 升级到 12 后的神秘错误消息和名称
- reactjs - 维特斯 | 未捕获的错误:动态要求“
.svg" 不受支持 - python - MacOS 上的 Python 库
- azure - 使用 Azure CLI 进行 REST 调用时获取状态代码
- c# - 此方法中的执行时间
- python - 使用 python 脚本将 cvs 导入 postgres
- c# - 如何在 c# linq 中添加 sql 'when' 功能
- javascript - 如何在单个 Material-UI DataGrid 中呈现逗号分隔的链接列表?