2021年4月11日星期日

Not able to reach 60fps in opencv with a supported camera

For my project i need to process frames at high rate, the more the better but at least 60fps are mandatory. Im using opencv 4.1.1 in a Windows 10 machine vía Anaconda in case you need to know the platform. With the code provided im able to get 30 fps whatever is the frame rate or resolution setted.

My camera model is an ELP-USBFHD01M-L21, which is capable of:

  1. 1920 (H) x 1080 (V) MJPEG 30fps YUY2 6fps
  2. 1280 (H) x 1024 (V) MJPEG 30fps YUY2 6fps
  3. 1280 (H) x 720 (V) MJPEG 60fps YUY2 9fps
  4. 1024 (H) x 768 (V) MJPEG 30fps YUY2 9fps
  5. 800 (H) x 600 (V) MJPEG 60fps YUY2 21fps
  6. 640 (H) x 480 (V) MJPEG 120fps YUY2 30fps
  7. 352(H) x 288 (V) MJPEG 120fps YUY2 30fps
  8. 320 (H) x 240 (V) MJPEG 120fps YUY2 30fps

All of those frame rates are correctly tested with AMCAP software.

How can i reach the desired frame rate?

Code:

import cv2  import time  import numpy as np    if __name__ == "__main__":        VIDEO_SOURCE = 0      CAMERA_CAPTURE_FPS = 60      CAMERA_CAPTURE_WIDTH = 1280      CAMERA_CAPTURE_HEIGHT = 720        frameCounter = 0      fps = 0      startTime = time.time()        cap = cv2.VideoCapture(VIDEO_SOURCE)        print("Parameters BEFORE assignment: ")      print("WIDTH: " + str(cap.get(cv2.CAP_PROP_FRAME_WIDTH)))      print("HEIGHT: " + str(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))      print("FPS: " + str(cap.get(cv2.CAP_PROP_FPS)))      print("FOURCC: " + str(cap.get(cv2.CAP_PROP_FOURCC)))        # Noting seems to change adding or deleting this 2 lines      fourcc = cv2.VideoWriter_fourcc('M','J','P','G')      cap.set(cv2.CAP_PROP_FOURCC, fourcc)            cap.set(cv2.CAP_PROP_FRAME_WIDTH, CAMERA_CAPTURE_WIDTH)      cap.set(cv2.CAP_PROP_FRAME_HEIGHT, CAMERA_CAPTURE_HEIGHT)      cap.set(cv2.CAP_PROP_FPS, CAMERA_CAPTURE_FPS)        print()      print("Parameters AFTER assignment: ")      print("WIDTH: " + str(cap.get(cv2.CAP_PROP_FRAME_WIDTH)))      print("HEIGHT: " + str(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))      print("FPS: " + str(cap.get(cv2.CAP_PROP_FPS)))      print("FOURCC: " + str(cap.get(cv2.CAP_PROP_FOURCC)))          while True:            ret, frame = cap.read()            cv2.putText(frame, "FPS: " + str(fps), (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)          frameCounter += 1            if time.time() - startTime >= 1:              fps = frameCounter              frameCounter = 0              startTime = time.time()            cv2.imshow("Camera stream", frame)            if cv2.waitKey(1) & 0xFF == ord('q'):              break        cv2.destroyAllWindows()      cap.release()  
https://stackoverflow.com/questions/67007880/not-able-to-reach-60fps-in-opencv-with-a-supported-camera April 09, 2021 at 12:10AM

没有评论:

发表评论