Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. cap = cv2.VideoCapture('/home/sm/Desktop/VIRB0022.MP4')
  4. frame_num = 0
  5. num_frames = 30000 #the total number of frames in the video
  6. cif = [] #the data for detected juggling balls
  7. while frame_num < num_frames: #look through each frame of video
  8.     ret, img = cap.read()
  9.     img = img[0:400, 420:800] #only look at the relevant part of image (faster processing)
  10.     gimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  11.     #find the juggling balls!
  12.     circles = cv2.HoughCircles(gimg, cv2.HOUGH_GRADIENT, 2, 15, np.array([]), 100, 30, 1, 30)
  13.     c = 0 #the number of circles in the frame
  14.     try:
  15.         a, b, c = circles.shape
  16.         for i in range(b):
  17.             if circles[0][i][2] > 6 and circles[0][i][2] <12:
  18.                 c+=1
  19.                 cv2.circle(img, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv2.LINE_AA)
  20.     except: pass
  21.     cv2.imshow("detected circles", img)
  22.     cv2.waitKey(1)
  23.     frame_num += 1
  24.     cif.append(c)
  25. #determine if the frame contains juggling
  26. for i in range(len(cif)-20):
  27.     if sum(cif[i:i+15])<17:
  28.         cif[i] = 'e'
  29. run_num = 1
  30. cut_tally = 0
  31. while len(cif)>20:
  32.     while cif[0]=='e':
  33.         cif.remove('e')
  34.         cut_tally+= 1
  35.     try:
  36.         #find the run length
  37.         run_length = sum(cif[:cif.index('e')])/88.1
  38.         if run_length > 13:
  39.             #find when the runs starts, and make a video link
  40.             video_link = 'https://youtu.be/sm-GxpeuMsA?t=' + str(int(cut_tally/60.01)) + 's'
  41.             print 'Run number', run_num, 'was ', int(run_length) , 'catches:', video_link
  42.             run_num += 1
  43.         cut_tally += cif.index('e')
  44.         cif = cif[cif.index('e'):]
  45.     except: break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement