【问题标题】:Capture image from video every 5 seconds, and save picutres using Python & OpenCV每 5 秒从视频中捕获图像,并使用 Python 和 OpenCV 保存图片
【发布时间】:2020-03-10 01:41:48
【问题描述】:

制作ocr程序的人。我想每 5 秒捕获一次视频图像并实时检查。

cap = cv2.VieoCapture(0)

while(True)
    ret,frame = cap.read()

    cv2.imwrite('Test.png'),frame,params=[cv2.IMWRITE_PNG_COMPRESSION,2]
    ocrcheck()    #Function to read 'Test.png' and check with ocr program

我想每5秒实时获取一帧,保存并将保存的图像打印到ocr程序。 请告诉我答案

【问题讨论】:

    标签: python opencv ocr


    【解决方案1】:

    您可以使用 cv2.waitKey(delay_in_ms) 或 time.sleep(delay_in_seconds) 休眠给定的时间。 还要考虑以下几点:您的 ocrcheck() 函数和 cv2.imwrite 将花费一些时间,因此最好不要睡 5 秒,而是睡 (5 - time_spent),其中 time_spent 是调用这两个函数所花费的时间。示例:

    while(True)
        start_time = time.time()
    
        ret,frame = cap.read()
    
        cv2.imwrite('Test.png'),frame,params=[cv2.IMWRITE_PNG_COMPRESSION,2]
        ocrcheck()    #Function to read 'Test.png' and check with ocr program
    
        spent = time.time() - start_time # how much you spent on calling functions above
    
        time.sleep(5 - spent) # sleep for a rest of time
    

    【讨论】:

      猜你喜欢
      • 2019-06-15
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多