示例#1
0
文件: server.py 项目: wesleyck/vatic
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
示例#2
0
文件: server.py 项目: Jamesjue/vatic
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
示例#3
0
def dump_text(video_id, target_folder):
    if not os.path.exists(target_folder):
        os.makedirs(target_folder)

    video, data = getdata(video_id)

    print "Dumping video {0}".format(video.slug)

    dumpformat = dumptools.DEFAULT_FORMAT.split()
    output_file_path = os.path.join(target_folder,
                                    os.path.splitext(video.slug)[0])
    with open(output_file_path, 'wb') as f:
        dumptools.dumptext(f, data, False, dumpformat)
    print "finished"
示例#4
0
    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())
示例#5
0
文件: cli.py 项目: mmisono/vatic
    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())