def process(filename): fs = fr.read_frames(filename) kernel = np.ones((3,3), np.uint8) newFs = [] for f in fs: f = cv2.resize(f, None, fx=0.4, fy=0.4) f = cv2.equalizeHist(f) f1 = f.copy() # f = cv2.medianBlur(f, 3) # cnts = cd.contours(f) # cv2.drawContours(f, cnts, -1, 255) f[f < f.max()-10] = 0 f = cv2.morphologyEx(f, cv2.MORPH_OPEN, kernel) # show_frame(f) newFs.append(f) # params for ShiTomasi corner detection feature_params = dict( maxCorners = 100, qualityLevel = 0.3, minDistance = 7, blockSize = 7 ) # Parameters for lucas kanade optical flow lk_params = dict( winSize = (15,15), maxLevel = 2, criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03)) p0 = cv2.goodFeaturesToTrack(newFs[0], mask = None, **feature_params) # Create a mask image for drawing purposes mask = np.zeros_like(newFs[0]) # Create some random colors color = np.random.randint(0,255,(100,3)) for fo, fn in zip(newFs, newFs[1:]): # calculate optical flow p1, st, err = cv2.calcOpticalFlowPyrLK(fo, fn, p0, None, **lk_params) # Select good points good_new = p1[st==1] good_old = p0[st==1] # draw the tracks for i,(new,old) in enumerate(zip(good_new,good_old)): a,b = new.ravel() c,d = old.ravel() cv2.line(mask, (a,b),(c,d), color[i].tolist(), 2) cv2.circle(fn,(a,b),5,color[i].tolist(),-1) fn = cv2.add(fn, mask) show_frame(fn) # Now update the previous frame and previous points fo = fn.copy() p0 = good_new.reshape(-1,1,2)
def init(): global axes_, lines_ global cap_, args_ global data_ global frames_ global stride_ global t_, y_ global fps_ videoFile = args_['video'] print('[INFO] Processing %s' % videoFile ) frames_ = fr.read_frames( videoFile ) fps_ = args_['fps'] tmax = len(frames_) / float(fps_) stride_ = len(y_) / len(frames_) print('[INFO] Total frames: %s' % len(frames_)) print('[INFO] Computed fps: %s' % fps_) print('[INFO] Stride to take: %s' % stride_) return lines_.values()
def init(): global axes_, lines_ global cap_, args_ global data_ global frames_ global stride_ global t_, y_ global fps_ videoFile = args_['video'] frames_ = fr.read_frames( videoFile ) data_ = scipy.io.loadmat( args_['activity'] ) data_ = data_['final'] t_, y_ = data_[:,0], data_[:,1] fps_ = args_['fps'] tmax = len(frames_) / float(fps_) stride_ = len(y_) / len(frames_) print('[INFO] Total frames: %s' % len(frames_)) print('[INFO] Computed fps: %s' % fps_) print('[INFO] Stride to take: %s' % stride_) axes_['activity'].set_xlim([0, tmax]) axes_['activity'].set_ylim([y_.min() - 2, y_.max() + 2]) return lines_.values()
def main( inputfile, **kwargs): logger.info('Processing %s ' % inputfile) frames = fr.read_frames( inputfile, 10 ) fShape = frames[0].shape logger.info('Got total %s frames' % len(frames)) print("Done reading frames") data = np.dstack( frames ) rows, cols = data.shape[0], data.shape[1] pixals = [] for r in range(rows): for c in range(cols): vec = data[r, c, :] pixals.append( Pixal(vec, (r,c)) ) for p in pixals: add_pixal( p ) print("Total nice pixals: %s" % len(pixal_of_interest_)) img = np.zeros( shape = fShape ) for loc in pixal_of_interest_: img[loc] = pixal_of_interest_[loc].max pylab.imshow( img ) pylab.show()
def main(inputfile, **kwargs): logger.info('Processing %s ' % inputfile) frames = fr.read_frames(inputfile, 10) fShape = frames[0].shape logger.info('Got total %s frames' % len(frames)) print("Done reading frames") data = np.dstack(frames) rows, cols = data.shape[0], data.shape[1] pixals = [] for r in range(rows): for c in range(cols): vec = data[r, c, :] pixals.append(Pixal(vec, (r, c))) for p in pixals: add_pixal(p) print("Total nice pixals: %s" % len(pixal_of_interest_)) img = np.zeros(shape=fShape) for loc in pixal_of_interest_: img[loc] = pixal_of_interest_[loc].max pylab.imshow(img) pylab.show()