def iterate_video(filename, x1, y1, x2, y2, x3, y3, x4, y4, down_scale=True): """ itereer over alle frames van de video tel het aantal wagens die door een van de twee rechthoeken rijden de visualizatie wordt opgeslaan als video in trafic.avi druk Q om te stoppen :param filename: bestandsnaam van de video :param x1, y1, x2, y2: twee hoekpunten van de eerste rechthoek :param x3, y3, x4, y4: twee hoekpunten van de tweede rechthoek :param down_scale: boolean: als True wordt de resolutie van de video gehalveerd :return: None """ queue = collections.deque() if not os.path.isfile(filename): raise Exception("file not found") reader = FFmpegReader(filename) shape = reader.getShape()[1:3] if down_scale: shape = [shape[0] // 2, shape[1] // 2] stepsize = 5 video_writer = cv2.VideoWriter('traffic.avi', cv2.VideoWriter_fourcc(*'XVID'), 30.0, (shape[1], shape[0])) for frame in reader.nextFrame(): if down_scale: frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA) queue.append(frame[:, :, ::-1]) if len(queue) > 2 * stepsize: res = traffic(queue[0], queue[stepsize], queue[stepsize * 2], x1, y1, x2, y2, x3, y3, x4, y4) cv2.imshow("Traffic", res) k = cv2.waitKey(1) queue.popleft() video_writer.write(res) if k == 113: # press Q to break break video_writer.release()
if os.path.isdir(os.path.join(rootDirLoad, subDir)): # Check if it is a folder classes.append(subDir) # Create a path files = os.listdir(os.path.join(rootDirLoad, subDir)) nVideos = 0 # Videos in class X pbar2 = trange(len(files), ncols=100, position=2, desc='Within-class progress ') for file in files: # Get all the videos if file.lower().endswith('.avi') or file.lower().endswith('.mp4'): filename = os.path.join(rootDirLoad, subDir, file) reader = FFmpegReader(filename) nFrames = reader.getShape()[0] nVideos += 1 dataList.write('\n{:<8} {:12} {:<12} {:02}.pyt'.format( nClasses, subDir, nFrames, nVideos)) # Create class directories if they do not exist classDir = os.path.join(rootDirSave, subDir) if not os.path.exists(classDir): os.makedirs(classDir) pbar3 = trange(nFrames, ncols=100, position=4, desc='Video progress ') frameCount = 0
def infer_video(paths): item_path, item_ann_path = paths vreader = FFmpegReader(item_path) return (vreader.getShape(), )