【问题标题】:Unable to capture image every 5 seconds using OpenCV使用 OpenCV 无法每 5 秒捕获一次图像
【发布时间】:2018-07-01 17:46:21
【问题描述】:

我试图通过笔记本电脑的内置网络摄像头使用 opencv 每 5 秒捕获一次图像。我正在使用 time.sleep(5) 进行所需的暂停。在每次运行中,第一张图像似乎都被正确保存,但之后所有图像都被保存为不受支持的格式(当我打开它们时)。我也无法通过按“q”来打破循环。 下面是我的代码。

import numpy as np
import cv2
import time
cap = cv2.VideoCapture(0)
framerate = cap.get(5)
x=1

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    cap.release()
    # Our operations on the frame come here



    filename = 'C:/Users/shjohari/Desktop/Retail_AI/MySection/to_predict/image' +  str(int(x)) + ".png"
    x=x+1
    cv2.imwrite(filename, frame)
    time.sleep(5)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

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

感谢任何帮助。

【问题讨论】:

    标签: python-3.x opencv


    【解决方案1】:

    只是一个小改动,解决了我的问题。 我在循环中包含了以下代码:P

    cap = cv2.VideoCapture(0)
    framerate = cap.get(5)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-10
      • 2015-01-10
      • 2020-01-08
      • 2019-06-15
      • 1970-01-01
      • 2017-11-11
      • 2016-09-15
      • 1970-01-01
      相关资源
      最近更新 更多