python - 如何使用 python 访问相机?
问题描述
当我运行代码以访问相机时,实时提要会出现一秒钟,然后出现错误。
这是代码:
import cv2,time
video=cv2.VideoCapture(0)
check,frame=video.read()
print(check)
print(frame)
cv2.imshow("capturing", frame)
cv2.waitkey(1)
video.release()
错误是:
Traceback (most recent call last):
File "C:/1 Files and Folders/SHARAN/code/My Projects/os.py", line 8, in <module>
cv2.waitkey(1)
AttributeError: module 'cv2.cv2' has no attribute 'waitkey'
[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-cff9bdsm\opencv\modules\videoio\src\cap_msmf.cpp (435) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
解决方案
waitKey
是正确的代码。您应该将 k 更改为大写字母
import cv2,time
video=cv2.VideoCapture(0)
check,frame=video.read()
print(check)
print(frame)
cv2.imshow("capturing", frame)
cv2.waitKey(1) #you should change this
video.release()
推荐阅读
- html - 覆盖引导颜色
- javascript - 用变量填充 alpaca 属性
- r - 有什么方法可以先按出生日期排序数据框,然后在 R 中按字母顺序排序?
- python-3.x - 如何在python中的列表中添加新行?
- git - 在 VS Code 中提交 Git 后更新扩展 UI
- angular - 使用带有 NOOP 的 Angular 9 添加 Web 组件构建后,更改检测无法正常工作
- c# - “LinkAssemblies”任务意外失败。xamarinandroidException:错误 XA2006:无法解析引用
- sql - XML Where 子句上的 SQL 查询
- bootstrap-4 - Bootstrap/Flex: flex-wrap + justify-content-between // 即使最后一行元素不完整,如何在项目列之间放置相等的空间?
- python - django中的python错误中的订单对象不可迭代