title: how to make cv2.videoCapture.read() faster?
body: <p>My question : </p>
  
  <p>I was working on my computer vision project. I use opencv(4.1.2) and python to implement it.</p>
  
  <p>I need a faster way to pass the reading frame into image processing on my Computer(Ubuntu 18.04 8 cores i7 3.00GHz Memory 32GB). the <code>cv2.VideoCapture.read()</code> read frame (frame size : 720x1280) will take about 120~140ms. <strong>which is too slow.</strong> my processing module take about 40ms per run. And we desire 25~30 FPS.</p>
  
  <p>here is my demo code so far:</p>
  
  <pre><code>import cv2
  from collections import deque
  from time import sleep, time
  import threading
  
  
  class camCapture:
      def __init__(self, camID, buffer_size):
          self.Frame = deque(maxlen=buffer_size)
          self.status = False
          self.isstop = False
          self.capture = cv2.VideoCapture(camID)
  
  
      def start(self):
          print('camera started!')
          t1 = threading.Thread(target=self.queryframe, daemon=True, args=())
          t1.start()
  
      def stop(self):
          self.isstop = True
          print('camera stopped!')
  
      def getframe(self):
          print('current buffers : ', len(self.Frame))
          return self.Frame.popleft()
  
      def queryframe(self):
          while (not self.isstop):
              start = time()
              self.status, tmp = self.capture.read()
              print('read frame processed : ', (time() - start) *1000, 'ms')
              self.Frame.append(tmp)
  
          self.capture.release()
  
  cam = camCapture(camID=0, buffer_size=50)
  W, H = 1280, 720
  cam.capture.set(cv2.CAP_PROP_FRAME_WIDTH, W)
  cam.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, H)
  
  
  # start the reading frame thread
  cam.start()
  
  # filling frames
  sleep(5)
  
  while True:
    frame = cam.getframe() # numpy array shape (720, 1280, 3)
  
    cv2.imshow('video',frame)
    sleep( 40 / 1000) # mimic the processing time
  
    if cv2.waitKey(1) == 27:
          cv2.destroyAllWindows()
          cam.stop()
          break
  
  </code></pre>
  
  <p>What I tried : </p>
  
  <ol>
  <li><p>multiThread - one thread just reading the frame, the other do the image processing things.
  <strong>It's NOT what I want.</strong> because I could set a buffer deque saving 50 frames for example. but the frame-reading thread worked with the speed ~ frame/130ms. my image processing thread worked with the speed ~ frame/40ms. then the deque just running out. so I've been tried the solution. but not what I need.</p></li>
  <li><p>this <a href="https://stackoverflow.com/questions/52655841/opencv-python-multithreading-seeking-within-a-videocapture-object">topic</a> is the discussion I found out which is most closest to my question. but unfortunately, I tried the accepted solutions (both of two below the discussion).</p></li>
  </ol>
  
  <p><strong>One of the solution (6 six thumbs up) point out that he could reading and saving 100 frames at 1 sec intervals on his mac. why my machine cannot handle the frame reading work? Do I missing something? my installation used conda and pip <code>conda install -c conda-forge opencv</code>, <code>pip install opencv-python</code>(yes, I tried both.)</strong></p>
  
  <p><strong>The other of the solution(1 thumb up) using ffmpeg solution. but it seem's work with video file but not camera device?</strong></p>
  
  <ol start="3">
  <li>adjust c2.waitKey() : 
  the parameter just controls the frequency when video display. not a solution.</li>
  </ol>
  
  <p>Then, I know I just need some keywords to follow. </p>
  
  <p>code above is my demo code so far, I want some method or guide to make me videoCapture.read() faster. maybe a way to use multithread inside videoCapture object or other camera reading module.</p>
  
  <p>Any suggestions?</p>