首页 > 解决方案 > 如何使用 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

标签: pythoncv2

解决方案


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()

推荐阅读