Пример #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
Пример #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
Пример #3
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()
Пример #4
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()
Пример #5
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())
Пример #6
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
Пример #7
0
from __future__ import print_function
from __future__ import division

from skvideo.io import VideoCapture
from skvideo.metrics import ssim, psnr, vifp
import sys
import json

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