def videodump(slug, outputtype, groundplane, fields=None): logger.debug(os.getcwd()) query = session.query(Video).filter(Video.slug == slug) if query.count() != 1: raise ValueError("Invalid video slug") video = query.one() #mergemethod = merge.userid groundplane = (groundplane == 1) mergemethod = merge.getpercentoverlap(groundplane) if fields is None: if groundplane: fields = dumptools.GROUND_PLANE_FORMAT else: fields = dumptools.DEFAULT_FORMAT fields = fields.split() data = dumptools.getdata(video, True, mergemethod, 0.5, None, groundplane) outfile = tempfile.TemporaryFile() if outputtype == "json": dumptools.dumpjson(outfile, data, groundplane, fields) elif outputtype == "xml": dumptools.dumpxml(outfile, data, groundplane, fields) else: dumptools.dumptext(outfile, data, groundplane, fields) outfile.seek(0) text = outfile.readlines() outfile.close() return text
def __call__(self, args): video, data = self.getdata(args) if args.pascal: if not args.output: print "error: PASCAL output needs an output" return file = args.output print "Dumping video {0}".format(video.slug) elif args.output: file = open(args.output, 'w') print "Dumping video {0}".format(video.slug) else: file = cStringIO.StringIO() scale = args.scale if args.dimensions or args.original_video: if args.original_video: w, h = ffmpeg.extract(args.original_video).next().size else: w, h = args.dimensions.split("x") w = float(w) h = float(h) s = w / video.width if s * video.height > h: s = h / video.height scale = s for track in data: track.boxes = [x.transform(scale) for x in track.boxes] if args.lowercase: track.label = track.label.lower() dumpformat = args.dump_format.split() if args.xml: dumptools.dumpxml(file, data, args.groundplane, dumpformat) elif args.json: dumptools.dumpjson(file, data, args.groundplane, dumpformat) elif args.matlab: dumptools.dumpmatlab(file, data, video, scale, dumpformat) elif args.pickle: dumptools.dumppickle(file, data) elif args.labelme: dumptools.dumplabelme(file, data, args.slug, args.labelme) elif args.pascal: if scale != 1: print "Warning: scale is not 1, yet frames are not resizing!" print "Warning: you should manually update the JPEGImages" dumptools.dumppascal(file, video, data, args.pascal_difficult, args.pascal_skip, args.pascal_negatives) elif args.forecast: dumptools.dumpforecastdata(file, data) elif args.positions: dumptools.dumppositions(file, data) else: dumptools.dumptext(file, data, args.groundplane, dumpformat) if args.pascal: return elif args.output: file.close() else: sys.stdout.write(file.getvalue())
def __call__(self, args): video, data = self.getdata(args) if args.pascal or args.pascal2: if not args.output: print "error: PASCAL output needs an output" return file = args.output print "Dumping video {0}".format(video.slug) elif args.output: file = open(args.output, 'w') print "Dumping video {0}".format(video.slug) else: file = cStringIO.StringIO() scale = args.scale if args.dimensions or args.original_video: if args.original_video: w, h = ffmpeg.extract(args.original_video).next().size else: w, h = args.dimensions.split("x") w = float(w) h = float(h) s = w / video.width if s * video.height > h: s = h / video.height scale = s for track in data: track.boxes = [x.transform(scale) for x in track.boxes] if args.lowercase: track.label = track.label.lower() dumpformat = args.dump_format.split() if args.xml: dumptools.dumpxml(file, data, args.groundplane, dumpformat) elif args.json: dumptools.dumpjson(file, data, args.groundplane, dumpformat) elif args.matlab: dumptools.dumpmatlab(file, data, video, scale, dumpformat) elif args.pickle: dumptools.dumppickle(file, data) elif args.labelme: dumptools.dumplabelme(file, data, args.slug, args.labelme) elif args.pascal: if scale != 1: print "Warning: scale is not 1, yet frames are not resizing!" print "Warning: you should manually update the JPEGImages" dumptools.dumppascal(file, video, data, args.pascal_difficult, args.pascal_skip, args.pascal_negatives) elif args.pascal2: dumptools.dumppascal2(file, video, data, args.pascal_ratio) elif args.forecast: dumptools.dumpforecastdata(file, data) elif args.positions: dumptools.dumppositions(file, data) else: dumptools.dumptext(file, data, args.groundplane, dumpformat) if args.pascal or args.pascal2: return elif args.output: file.close() else: sys.stdout.write(file.getvalue())