title: Python3 parallel process opencv video frames
body: <p>I have a video file which I need to process frame by frame and need to show the results in the frames afterwards. Currently I am doing the processing sequentially and showing the frames one by one.</p>
  
  <p>Now I would like to process the frames parallely instead of sequentially. Once X number of frames has been processed then the cv2.imshow has to appear and has to show the processed frames in correct order.</p>
  
  <p>Currently my sequential code looks like this</p>
  
  <pre><code>import cv2
  import requests
  
  
  def process_frame(bgr_image, jpg_as_text):
      try:
          # Post to api for processing and get the results
          # result = requests.post("example.com", data={"jpg": jpg_as_text})
  
          # Add results to bgr_image
          # cv2.putText()
      except Exception as e:
          print(e)
          pass
      # Show the frame
      cv2.imshow("frame", bgr_image)
  
  
  video = cv2.VideoCapture("video.mp4")
  i = 0
  
  
  while video.isOpened():
      ret, bgr_image = video.read()
      if ret == True:
          img_height, img_width, _ = bgr_image.shape
          jpg_as_text = cv2.imencode(".jpg", bgr_image)[1].tostring()
          process_frame(bgr_image, jpg_as_text)
          print(i)
          i += 1
      else:
          break
      if cv2.waitKey(1) &amp; 0xFF == ord("q"):
          break
  
  video.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Now what should I refactor to do parallel processing and preview the frames once X number of frames are processed.</p>