Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Created March 30, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aravindpai/c791efb5b7a817f5c7c6a36c0739bec0 to your computer and use it in GitHub Desktop.
Save aravindpai/c791efb5b7a817f5c7c6a36c0739bec0 to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
import imutils
video='28.mp4'
# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
cap = cv2.VideoCapture(video)
cnt=0
# Check if camera opened successfully
if (cap.isOpened()== False):
print("Error opening video stream or file")
ret,first_frame = cap.read()
# Read until video is completed
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
#removing scorecard
roi = frame[:800,:]
#cropping center of an image
thresh=600
end = roi.shape[1] - thresh
roi = roi[:,thresh:end]
cv2.imshow("image",roi)
# Press Q on keyboard to exit
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cv2.imwrite('frames/'+str(cnt)+'.png',roi)
cnt=cnt+1
# Break the loop
else:
break
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment