【问题标题】:openCV: Trying to understand capture video from camera codeopenCV:试图从相机代码中理解捕获视频
【发布时间】:2018-10-22 07:28:53
【问题描述】:

下面是openCV文档中打开和关闭网络摄像头的简单代码,

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

问题:

1) 上面代码中使用的numpy库是什么,为什么需要它?

2) 如何查看cv2.waitKey(0)的返回值?

【问题讨论】:

    标签: python python-3.x opencv


    【解决方案1】:
    1. 这里没用。尽管如此,由于它的多种用途(其中许多与 cv2 齐头并进),它是一个在许多代码 sn-ps 中找到自己的方式的模块。
    2. Python: cv.WaitKey(delay=0) → int Doc... 只需使用函数中的常规赋值即可
    3. cap.release()See example here

    【讨论】:

    • 感谢您的回复。我的第三个问题没有得到解决。使用 cap.release() 网络摄像头不会关闭。如何关闭它?
    • 从 codumentation 看来 .release() shuold 就足够了。试试cap.__del__() 并反馈
    • 获取属性错误。 AttributeError: 'cv2.VideoCapture' object has no attribute '__del__'
    • 您也可以尝试del(cap),但即使这可行,它也不是一个按常规解决方案,AFAIK
    • 另外,当你看到灯还亮着的时候cap.isOpened()的值是多少?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多