Skip to content

Instantly share code, notes, and snippets.

@samson-wang
Last active March 23, 2018 11:30
Show Gist options
  • Save samson-wang/a52266118aacecd560fce22c429caf3b to your computer and use it in GitHub Desktop.
Save samson-wang/a52266118aacecd560fce22c429caf3b to your computer and use it in GitHub Desktop.
capture from video
import cv2
import sys
import numpy as np
import imutils
vids = [0] if len(sys.argv) < 2 else map(int, sys.argv[1].split(','))
caps = [cv2.VideoCapture(_) for _ in vids]
scale = .5
for cap in caps:
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
for k, cap in enumerate(caps):
ret, im = cap.read()
if not ret:
break
print im.shape
h, w, c = im.shape
im[:h:h/2, :, :] = 255
im[:, :w:w/2, :] = 255
cv2.circle(im, (w/2, h/2), 770, (0,0,255))
cv2.circle(im, (w/2, h/2), 800, (0,0,255))
# cv2.circle(im, (w/2, h/2), h/2 + 100, (0,0,255))
# cv2.circle(im, (w/2, h/2), h/2 + 200, (0,0,255))
# cv2.circle(im, (w/2, h/2), h/2 + 300, (0,0,255))
# cv2.circle(im, (w/2, h/2), h/2 + 400, (0,0,255))
# im = imutils.rotate_bound(im, 270)
cv2.imshow('test_%d' % k, cv2.resize(im, None,None,fx=scale,fy=scale))
pk = cv2.waitKey(1)
if pk & 0XFF == 113:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment