Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- cap = cv2.VideoCapture('/home/sm/Desktop/VIRB0022.MP4')
- frame_num = 0
- num_frames = 30000 #the total number of frames in the video
- cif = [] #the data for detected juggling balls
- while frame_num < num_frames: #look through each frame of video
- ret, img = cap.read()
- img = img[0:400, 420:800] #only look at the relevant part of image (faster processing)
- gimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- #find the juggling balls!
- circles = cv2.HoughCircles(gimg, cv2.HOUGH_GRADIENT, 2, 15, np.array([]), 100, 30, 1, 30)
- c = 0 #the number of circles in the frame
- try:
- a, b, c = circles.shape
- for i in range(b):
- if circles[0][i][2] > 6 and circles[0][i][2] <12:
- c+=1
- cv2.circle(img, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv2.LINE_AA)
- except: pass
- cv2.imshow("detected circles", img)
- cv2.waitKey(1)
- frame_num += 1
- cif.append(c)
- #determine if the frame contains juggling
- for i in range(len(cif)-20):
- if sum(cif[i:i+15])<17:
- cif[i] = 'e'
- run_num = 1
- cut_tally = 0
- while len(cif)>20:
- while cif[0]=='e':
- cif.remove('e')
- cut_tally+= 1
- try:
- #find the run length
- run_length = sum(cif[:cif.index('e')])/88.1
- if run_length > 13:
- #find when the runs starts, and make a video link
- video_link = 'https://youtu.be/sm-GxpeuMsA?t=' + str(int(cut_tally/60.01)) + 's'
- print 'Run number', run_num, 'was ', int(run_length) , 'catches:', video_link
- run_num += 1
- cut_tally += cif.index('e')
- cif = cif[cif.index('e'):]
- except: break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement