# # Author: Yijun Zhang # import cv2 import math import numpy as np import skvideo.io as sv cap = sv.VideoCapture('czy1.mp4') out = sv.VideoWriter('czy_other.mp4', 'H264', 30.0, (640, 480), True) print out.open() ret, frame2 = cap.read() current_frame = frame2 ## extract background fgbg = cv2.createBackgroundSubtractorKNN() while True: ret, frame = cap.read() # The rgb structure is different in cv and scikit-video, thus reconstructing b, g, r = cv2.split(frame) ori_frame = frame ori_frame = cv2.merge([r, g, b]) cv2.imshow('frame', ori_frame) ## the frame we get from the camera # Edge Enhancement b, g, r = cv2.split(frame) b_gray = cv2.GaussianBlur(b, (5, 5), 0) b_edged = cv2.Canny(b_gray, 35, 125) g_gray = cv2.GaussianBlur(g, (5, 5), 0) g_edged = cv2.Canny(g_gray, 35, 125)
# # Author:Yijun Zhang # Zeyu Chen # This is the batch version of preprocessing. # data_path is the directory of target videos import cv2 import os import numpy as np import skvideo.io as sv data_path = './video/' index = 1 for fn in os.listdir(data_path): cap = sv.VideoCapture(data_path + fn) print cap.isOpened() print data_path + fn outname = 'sub_bg' + str(index) + '.mp4' out = sv.VideoWriter(outname, 'H264', 30.0, (640, 480), True) out.open() ret, frame2 = cap.read() current_frame = frame2 ## extract background fgbg = cv2.createBackgroundSubtractorKNN() while True: ret, frame = cap.read() try: frame.any() except AttributeError:
"""opencv test""" import numpy as np; import cv2 import skvideo.io as skv; import matplotlib.pyplot as plt; cap = skv.VideoCapture("/home/arlmonster/workspace/telaugesa/data/000046280.avi") while(cap.isOpened()): ret, frame = cap.read() if frame is None: break; frame=np.asarray(frame); plt.figure(1); plt.imshow(frame); plt.show(); print "hello"