示例#1
0
def evaluate_ssim(name, reference_filename, source_filename=None):
    if source_filename is None:
        source_filename = 'out_filename.mp4'
        api.read(name, source_filename)
        #api.read(name, out_filename)
        #api.read(right_name, right_filename)

    source_video = cv2.VideoCapture(source_filename)
    reference_video = cv2.VideoCapture(reference_filename)
    ssim = []
    count = 0

    while reference_video.isOpened():
        sret, source = source_video.read()
        rret, reference = reference_video.read()

        if not rret:
            break

        count += 1
        ssim.append(compare_ssim(source, reference, multichannel=True))
        print(f'SSIM frame {len(ssim)} mean {sum(ssim)/len(ssim)}')
        #cv2.imwrite(f'ssim_left_{count}.png', source)
        #cv2.imwrite(f'ssim_right_{count}.png', reference)

    print('SSIM %d' % (sum(ssim) / len(ssim)))
    return sum(ssim) / len(ssim)
示例#2
0
def create_cache(n, name, T, R, P):
    with engine.VFS(transient=True):
        for i in range(n):
            r = random.choice(R)
            p = random.choice(P)
            t1 = random.randint(0, T-1)
            t2 = min(random.randint(t1 + 1, t1 + 60), T - 1)

            with open('cache.txt', 'w') as f:
                f.writelines([f'{i} cache {name} {(t1, t2)} {r} {p}\n'])

            print(f'{i} cache {name} {(t1, t2)} {r} {p}')
            api.read(name, f"out.{p}", resolution=r, t=(t1, t2), codec=p)
def search_vfs_single(data):
    name, fps, target_color, threshold, start_time, confidence, y1, x1, y2, x2 = data
    end_time = start_time + (1 / fps)
    #    prefix = uuid.uuid4().hex

    with engine.VFS(transient=True, child_process=True):
        reconstruction.POOL_SIZE = 1
        #prefix = uuid.uuid4().hex
        #api.read(name, f'out-{prefix}.rgb', t=(start_time, end_time), roi=(y1, x1, y2, x2), codec='rgb')
        #        pass

        with api.read(name,
                      t=(start_time, end_time),
                      roi=(y1, x1, y2, x2),
                      codec='rgb') as stream:
            #fn = api.read(name, t=(start_time, end_time), roi=(y1, x1, y2, x2), codec='rgb')
            #with open(fn, 'rb') as stream:
            buffer = np.frombuffer(stream.read(), dtype=np.uint8)
            frame = buffer.reshape(y2 - y1, x2 - x1, 3)
            #except:
            #    pass

        if is_dominant_color(frame, target_color, threshold):
            return start_time, confidence, y1, x1, y2, x2
        else:
            return None  #-1, -1, -1, -1, -1, -1
def temp():
    name = 'v'
    threshold = 50
    fps = 30

    with log_runtime('Search.VFS', level=logging.CRITICAL):
        with engine.VFS(transient=True):
            for start_time, confidence, y1, x1, y2, x2 in parse_index_file(
                    'index_cars_vfs.csv'):
                end_time = start_time + (1 / fps)
                api.read(name,
                         "foo.mp4",
                         t=(start_time, end_time),
                         roi=(y1, x1, y2, x2),
                         codec='rgb')
                pass
    exit(1)
def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument(
        'mode',
        choices=['init', 'read', 'write', 'list', 'delete', 'start', 'test'],
        help='Video operation mode')
    parser.add_argument('name',
                        nargs='?',
                        help='Video name to read, write, or delete')
    parser.add_argument('filename',
                        nargs='?',
                        help='Video name to read or write')
    parser.add_argument('-e',
                        '--codec',
                        type=regex_type('|'.join(extensions.values())),
                        help='Video resolution (read only)')
    parser.add_argument('-r',
                        '--resolution',
                        type=regex_type('\d+x\d+'),
                        help='Video resolution (read only)')
    parser.add_argument('-t',
                        '--time',
                        type=regex_type('\d+?-\d+?'),
                        help='Video times (read only)')
    parser.add_argument('-c',
                        '--crop',
                        type=regex_type('\d+:\d+:\d+:\d+'),
                        help='Video crop (read only)')
    parser.add_argument('-fps',
                        '--fps',
                        type=int,
                        help='Video FPS (read only)')
    arguments = parser.parse_args()  #['read', 'p3', 'foo.mp4'])

    if arguments.mode == 'init':
        Database.clear()
    else:
        with VFS(transient=True):
            time.sleep(1)

            if arguments.mode == 'start':
                while True:
                    time.sleep(60)
            elif arguments.mode == 'list':
                for name in list():
                    print(name)
            elif arguments.mode == 'read':
                read(
                    arguments.name,
                    arguments.filename,
                    resolution=tuple(map(int, arguments.resolution.split('x')))
                    if arguments.resolution else None,
                    roi=tuple(map(int, arguments.crop.split(':')))
                    if arguments.crop else None,
                    t=tuple(map(int, arguments.time.split('-')))
                    if arguments.time else None,
                    codec=arguments.codec,
                    fps=arguments.fps)
            elif arguments.mode == 'write':
                write(arguments.name, arguments.filename)
            elif arguments.mode == 'delete':
                delete(arguments.name)
            elif arguments.mode == 'test':
                #write('p2', "inputs/p2.rgb", (2160, 3840), RGB8, 30)
                write('p1', "inputs/p1.mp4")
                write('p2', "inputs/p2.mp4")

                read('p2',
                     'output.mp4',
                     resolution=(1000, 1000),
                     roi=(20, 20, 500, 500),
                     t=(0, 1),
                     codec=H264)
                read('p2',
                     'output2.mp4',
                     resolution=(1000, 1000),
                     roi=(20, 20, 500, 500),
                     t=(1, 3),
                     codec=H264,
                     fps=10)
        time.sleep(1)
示例#6
0
def read_vfs(i, source, r, t, p):
    #r = (2160, 3840)
    #t = (1990, 1991)
    #p = 'h264'
    t = (t[0] + 0.7, t[1] + 0.7)
    api.read(source, '/tmp/out.mp4', resolution=r, t=t, codec=p)
示例#7
0
import os
import logging
from vfs import api
from vfs import engine
from vfs.physicalvideo import PhysicalVideo
from vfs.rawcompression import compress
from vfs.videoio import encoded

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    t = (0, 12)
    level = 15
    #with engine.VFS(transient=True):
    #    api.write('v', 'inputs/visualroad-4k-30a.mp4')
    #    api.read('v', '/dev/null', t=t, codec='rgb')
    #os.remove('out.rgb')

    if level is not None:
        with engine.VFS(transient=True):
            for physical in PhysicalVideo.get_all():
                if not encoded[physical.codec]:
                    for gop in physical.gops():
                        if gop.zstandard != level:
                            compress(gop.id, level)

    with engine.VFS(transient=True):
        api.read('v', '/dev/null', t=t, codec='rgb')