Skip to content

Instantly share code, notes, and snippets.

@d0p3t
Created April 9, 2017 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d0p3t/d4ac90bdb8e1894b5e195169591b6ea1 to your computer and use it in GitHub Desktop.
Save d0p3t/d4ac90bdb8e1894b5e195169591b6ea1 to your computer and use it in GitHub Desktop.
Video capture using OpenCV if you wanna try it. Works on my mac
import numpy as np
import cv2
from PIL import ImageGrab
fourcc = cv2.cv.CV_FOURCC(*'XVID') # or cv2.VideoWriter_fourcc('X','V','I','D') if you use opencv 3.0
vid = cv2.VideoWriter('record.avi', fourcc, 8, (500,490))
while(True):
img = ImageGrab.grab(bbox=(100, 10, 600, 500)) #x, y, w, h
img_np = np.array(img)
#frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
vid.write(img_np)
cv2.imshow("frame", img_np)
key = cv2.waitKey(1)
if key == 27:
break
vid.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment