def GetFrames(fileName, redFact = 0.5, skipLength = 1, debug = False): ''' returns numpy array of frames ''' cap = VideoCapture(fileName) cap.open() frameList = [] cnt = -1 if debug: print "Started creating Frame List" while True: retval, image = cap.read() cnt = (cnt+1)%skipLength if (cnt != 0): continue if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:,:,::-1] image = np.array(image, dtype = np.uint8) frameList.append(image) cap.release() if debug: print "Finished creating Frame List" frameList = np.array(frameList) return frameList
def GetFrames(fileName, redFact=0.5, skipLength=1, debug=False): ''' returns numpy array of frames ''' cap = VideoCapture(fileName) cap.open() frameList = [] cnt = -1 if debug: print "Started creating Frame List" while True: retval, image = cap.read() cnt = (cnt + 1) % skipLength if (cnt != 0): continue if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:, :, ::-1] image = np.array(image, dtype=np.uint8) frameList.append(image) cap.release() if debug: print "Finished creating Frame List" frameList = np.array(frameList) return frameList
def PlayVideo(fileName, redFact = 0.5): ''' Plays video using opencv functions Press 'q' to stop in between returns None ''' cap = VideoCapture(fileName) cap.open() while True: retval, image = cap.read() print len(image), len(image[0]) if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:,:,::-1] cv2.imshow('frame',image) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
def PlayVideo(fileName, redFact=0.5): ''' Plays video using opencv functions Press 'q' to stop in between returns None ''' cap = VideoCapture(fileName) cap.open() while True: retval, image = cap.read() print len(image), len(image[0]) if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:, :, ::-1] cv2.imshow('frame', image) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
def test_on_video(net, vid_fn, out_fn): # capture cap = VideoCapture(vid_fn) ret, img = cap.read() # writer orig_shape = (227, 227) # img.shape wri = VideoWriter(out_fn, frameSize=(orig_shape[1], orig_shape[0])) wri.open() frame = 0 while cap.isOpened(): ret, img = cap.read() if ret: img = draw_joints(img, net) # img = cv.resize(img, (orig_shape[1], orig_shape[0])) wri.write(img) frame += 1 print frame else: print 'finished' break cap.release() wri.release()
from __future__ import division from skvideo.io import VideoCapture, VideoWriter import sys cap_filename, wr_filename = sys.argv[1], sys.argv[2] cap = VideoCapture(cap_filename) cap.open() print(str(cap.get_info())) retval, image = cap.read() wr = VideoWriter(wr_filename, 'H264', 30, (image.shape[1], image.shape[0])) wr.open() frame_num = 0 while True: retval, image = cap.read() if not retval: break wr.write(image) print("frame %d" % (frame_num)) frame_num += 1 wr.release() cap.release() print("done")
def rgb_to_y(img): return 0.299 * img[:,:,0] + 0.587 * img[:,:,1] + 0.114 * img[:,:,2] frame_num = 0 while True: retval1, image1 = cap1.read() retval2, image2 = cap2.read() if not retval1 and not retval2: break elif not retval1 or not retval2: print("error: input files have different number of frames") break if image1.shape != image2.shape: print("error: input files have different resolutions") y_image1 = rgb_to_y(image1) y_image2 = rgb_to_y(image2) psnr_metric = psnr.psnr(image1, image2) ssim_metric = ssim.ssim(y_image1 / 255.0, y_image2 / 255.0) vifp_metric = vifp.vifp_mscale(y_image1, y_image2) print(json.dumps({ "frame_num":frame_num, "psnr":psnr_metric, "ssim":ssim_metric, "vifp":vifp_metric })) frame_num += 1 cap1.release() cap2.release() print("done")