Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
from skvideo.io import VideoCapture

import sys

filename = sys.argv[1]
cap = VideoCapture(filename)
print(str(cap.get_info()))


cap.open()
retval, image = cap.read()



frame_num = 0


import numpy
import pygame

while True:
    retval, image = cap.read()

    if not retval:
        print("done")
        sys.exit()

    surface = pygame.surfarray.make_surface(image)

    surface = pygame.Surface((100, 100))
    numpy_surface = numpy.frombuffer(surface.get_buffer())
Exemplo n.º 8
0
from skvideo.io import VideoCapture

import sys
import matplotlib.pyplot as plt
import matplotlib.animation as animation

filename = sys.argv[1]
cap = VideoCapture(filename)
print(str(cap.get_info()))

cap.open()
retval, image = cap.read()

plt_fig = plt.figure()
plt_image = plt.imshow(image)

frame_num = 0


def updatefig(*args):
    global cap, frame_num

    retval, image = cap.read()

    if not retval:
        print("done")
        sys.exit()

    print("frame %d" % (frame_num))
    frame_num += 1
Exemplo n.º 9
0
filename1, filename2 = sys.argv[1], sys.argv[2]

cap1 = VideoCapture(filename1)
cap1.open()
print(str(cap1.get_info()))

cap2 = VideoCapture(filename2)
cap2.open()
print(str(cap2.get_info()))

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)