[英]I think my code is correct But it is not working it is with opencv ,i trying to get my camera
import cv2
vid=cv2.VideoCapture(0)
while True:
ret,frame=vid.read()
cv2.imshow('frame',frame)
vid.release()
cv2.destroyAllWindows()
error: (-215:Assertion failed) !_src.empty() in
function 'cv::cvtColor'
Every time you loop this line of code, the loop starts the camera and stops the camera:每次循环这行代码时,循环都会启动摄像头并停止摄像头:
vid.release()
cv2.destroyAllWindows()
You should try this code:你应该试试这段代码:
import cv2
cap = cv2.VideoCapture()
# The device number might be 0 or 1 depending on the device and the webcam
cap.open(1, cv2.CAP_DSHOW)
while(True):
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.