[Python_OpenCV学习记录-自用] 调用摄像头报错

调用摄像头报错

  • [Python_OpenCV学习记录-自用] 调用摄像头报错
    • 代码:
    • 报错:
    • 原因:
    • 修改建议:

[Python_OpenCV学习记录-自用] 调用摄像头报错

代码:

import cv2 as cv


def video_demo():
    capture = cv.VideoCapture()
    while True:
        ret, frame = capture.read()
        cv.flip(frame, 1)
        cv.imshow("video", frame)
        c = cv.waitKey(50)
        if c == 27:
            break


# def get_image_info(image):
#     print(type(image))
#     print(image.shape)
#     print(image.size)
#     print(image.dtype)


# src = cv.imread("C:/Users/24541/Desktop/5.jpg")
# cv.namedWindow("image input", cv.WINDOW_AUTOSIZE)
video_demo()
# cv.imshow("image input", src)
print("hello motherfucker")
# get_image_info(src)
cv.waitKey(0)
cv.destroyAllWindows()

报错:

cv2.error: OpenCV(4.1.2) D:\Build\OpenCV\opencv-4.1.2\modules\highgui\src\window.cpp:384:
 error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

原因:

调用摄像头没有选择笔记本自带摄像头?

修改建议:

将“capture = cv.VideoCapture()”括号中添加“0”以选择笔记本摄像头

你可能感兴趣的:([Python_OpenCV学习记录-自用] 调用摄像头报错)