SHARE
TWEET

Untitled

a guest Sep 15th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # import the necessary packages
  2. from imutils.video import FileVideoStream
  3. from imutils.video import FPS
  4. import numpy as np
  5. import argparse
  6. import imutils
  7. import time
  8. import cv2
  9.  
  10. # construct the argument parse and parse the arguments
  11. ap = argparse.ArgumentParser()
  12. ap.add_argument("-v", "--video", required=True,
  13.     help="path to input video file")
  14. args = vars(ap.parse_args())
  15.  
  16. # start the file video stream thread and allow the buffer to
  17. # start to fill
  18. print("[INFO] starting video file thread...")
  19. fvs = FileVideoStream(args["video"]).start()
  20. time.sleep(1.0)
  21.  
  22. # start the FPS timer
  23. fps = FPS().start()
  24.  
  25. # loop over frames from the video file stream
  26. while fvs.more():
  27.     # grab the frame from the threaded video file stream, resize
  28.     # it, and convert it to grayscale (while still retaining 3
  29.     # channels)
  30.     frame = fvs.read()
  31.     frame = imutils.resize(frame, width=450)
  32.     frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  33.     frame = np.dstack([frame, frame, frame])
  34.  
  35.     # display the size of the queue on the frame
  36.     cv2.putText(frame, "Queue Size: {}".format(fvs.Q.qsize()),
  37.         (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)   
  38.  
  39.     # show the frame and update the FPS counter
  40.     cv2.imshow("Frame", frame)
  41.     cv2.waitKey(1)
  42.     fps.update()
  43.    
  44. # stop the timer and display FPS information
  45. fps.stop()
  46. print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
  47. print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
  48.  
  49. # do a bit of cleanup
  50. cv2.destroyAllWindows()
  51. fvs.stop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top