Exemplo n.º 1
0
def prepare_tracking(srcRoot, gtfile, videoname, imageSz):
    try:
        gtboxes = np.loadtxt(gtfile, delimiter=',')  # x y w h
    except:
        gtboxes = np.loadtxt(gtfile)
    if videoname == 'Tiger1':  # in OTB, for 'Tiger1', the starting frame is the 6th
        gtboxes = gtboxes[5:, :]
    firstframename = '0001.jpg'
    if videoname == 'David':
        firstframename = '0300.jpg'
    if videoname == 'Tiger1':  ##################################
        firstframename = '0006.jpg'
    img_path = srcRoot + videoname + '/' + 'img/' + firstframename
    firstframe = image_io.load_image(img_path)
    init_box = gtboxes[0, :].copy()  # x y w h
    nr_frames2track = gtboxes.shape[0]  # including first frame
    frameidx = range(2, nr_frames2track + 1)
    if videoname == 'David':
        frameidx = range(301, nr_frames2track + 300)
    if videoname == 'Tiger1':
        frameidx = range(7, nr_frames2track + 6)
    input_roi = np.zeros((1, 5))
    input_roi[0, 1] = init_box[0] * imageSz / firstframe.shape[1]
    input_roi[0, 2] = init_box[1] * imageSz / firstframe.shape[0]
    input_roi[0, 3] = (init_box[0] + init_box[2] -
                       1) * imageSz / firstframe.shape[1]
    input_roi[0, 4] = (init_box[1] + init_box[3] -
                       1) * imageSz / firstframe.shape[0]
    input_roi[0, 1:] -= 1  # starting from 0
    input_roi = input_roi[np.newaxis, :]

    return firstframe, input_roi, init_box, frameidx, nr_frames2track
def create_mask(image_path: hug.types.text,
                algorithm: image_mask_algorithm_type,
                morph: hug.types.number = 1):
    """Runs the masking algorithm and returns a serialized masked image."""

    image_rgb = load_image(image_path)

    mask = algorithm(image_rgb)

    if morph > 0:
        mask = apply_morphology(mask, iterations=morph)

    image_rgb[mask == 0] = MASK_COLOR

    serialized = serialize_image(image_rgb, OUTPUT_IMAGE_FORMAT)

    return {
        'type': 'image/{}'.format(OUTPUT_IMAGE_FORMAT),
        'encoding': 'base64',
        'content': serialized
    }
Exemplo n.º 3
0
def get_clip(clip, verbose=False):
    '''
    :param clip_name: str, the name of the clip (subfolder in c3d-pytorch/data)
    :param verbose: if True, show the unrolled clip
    :return:
    '''

    img_mean = np.asarray([128])
    imageSz = (128, 171)
    crop_size = 112

    # clip = sorted(glob(os.path.join('./c3d-pytorch/data', clip_name, '*.jpg')))

    clip = np.array([
        preproc_img(image_io.load_image(frame),
                    mean=img_mean,
                    imageSz=imageSz,
                    crop_size=crop_size) for frame in clip
    ])
    clip = clip.transpose(1, 0, 2, 3)
    clip = clip[np.newaxis, :, :, :, :]
    return torch.from_numpy(clip)
Exemplo n.º 4
0
            gtboxes = np.loadtxt(gtfile, delimiter=',')  # x y w h
        except:
            gtboxes = np.loadtxt(gtfile)

        if videoname == 'Tiger1':  # in OTB, for 'Tiger1', the starting frame is the 6th
            gtboxes = gtboxes[5:, :]

        firstframename = '0001.jpg'
        if videoname == 'David':
            firstframename = '0300.jpg'
        if videoname == 'Tiger1':  ##################################
            firstframename = '0006.jpg'

        img_path = srcRoot + videoname + '/' + 'img/' + firstframename

        firstframe = image_io.load_image(img_path)
        init_box = gtboxes[0, :].copy()  # x y w h
        nr_frames2track = gtboxes.shape[0]  # including first frame

        input_roi = np.zeros((1, 5))
        input_roi[0, 1] = init_box[0] * imageSz / firstframe.shape[1]
        input_roi[0, 2] = init_box[1] * imageSz / firstframe.shape[0]
        input_roi[0, 3] = (init_box[0] + init_box[2] -
                           1) * imageSz / firstframe.shape[1]
        input_roi[0, 4] = (init_box[1] + init_box[3] -
                           1) * imageSz / firstframe.shape[0]
        input_roi[0, 1:] -= 1  # starting from 0
        input_roi = input_roi[np.newaxis, :]

        model.bind(for_training=False,
                   data_shapes=[('data', (1, 3, imageSz, imageSz)),