简体   繁体   English

我认为我的代码是正确的但它无法与 opencv 一起使用,我试图让我的相机

[英]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.

相关问题 我的Python代码无法正常运行,我认为应该 - My Python code is not working like I think it should 我认为我的 if else 语句不起作用 - I think my if else statement is not working 我的 librosa MFCC 输出是否正确? 我想我在使用 librosa MFCC 时得到了错误的帧数 - Is my output of librosa MFCC correct? I think I get the wrong number of frames when using librosa MFCC 为什么我的 python 代码认为我试图连接<int>至<str>而实际上我不是?</str></int> - Why my python code think i was trying to concatenate <int> to <str> while actually i wasn't? 我无法获得此代码来打印所需的内容。 我认为我的函数编码不正确 - I'm not able to get this code to print what's needed. I think my functions are coded incorrectly 任何人都可以帮我解决这个列表的 python 代码,但我认为它没有工作 - Can anyone help me with my python code for this list, not working how I think it should 如何摆脱 OpenCV 代码中的 NoneType 错误 - How can I get rid of NoneType error in my OpenCV code 如何从我的多线程相机代码中返回 OpenCV 帧以显示在 Flask 中? - How can i return the the OpenCV Frame from my multithreaded camera code to be shown in Flask? 如何获得从相机到 OpenCV ArUco 标记的距离 - How can I get the distance from my camera to an OpenCV ArUco Marker 我在pygame中无法正确获得碰撞代码 - I can't get my collision code correct in pygame
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM