Guest User

Untitled

a guest
Nov 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3. # for windows, mac users
  4. # from PIL import ImageGrab
  5. # for linux users
  6. import pyscreenshot as ImageGrab
  7.  
  8. # four character code object for video writer
  9. fourcc = cv2.VideoWriter_fourcc(*'XVID')
  10. # video writer object
  11. out = cv2.VideoWriter("output.avi", fourcc, 5.0, (1366, 768))
  12.  
  13. while True:
  14. # capture computer screen
  15. img = ImageGrab.grab()
  16. # convert image to numpy array
  17. img_np = np.array(img)
  18. # convert color space from BGR to RGB
  19. frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
  20. # show image on OpenCV frame
  21. cv2.imshow("Screen", frame)
  22. # write frame to video writer
  23. out.write(frame)
  24.  
  25. if cv2.waitKey(1) == 27:
  26. break
  27.  
  28. out.release()
  29. cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment