Exemplo n.º 1
0
def background_flow(next_image, current_bbox, backward_flow):
    mask = np.zeros(next_image.shape) + 0.3
    mask[current_bbox[1]:current_bbox[3],
         current_bbox[0]:current_bbox[2], :] = 1
    next_mask = flow_warp_backward(mask, backward_flow)

    return next_mask
Exemplo n.º 2
0
def LAB_mask(im1,im2,flow):
    warped_im1 = flow_warp_backward(im1, flow)
    diff, rgb_diff = color_confidence(warped_im1, im2)
    diff = diff/(np.max(diff)-np.min(diff))
    diff_mask = np.zeros((np.shape(diff)[0],np.shape(diff)[1],3),dtype='float')
    diff_mask[:,:,0] = diff
    diff_mask[:,:,1] = diff
    diff_mask[:,:,2] = diff
    #np.save(os.path.join(data_dir,format(i+1, '08')+"_lab.npy"), diff_mask)
    return diff_mask
Exemplo n.º 3
0
                    next_bbox = bbox_format(gts[i + 1], 'tlxy_wh_2_rect')
                    next_bbox = [int(j) for j in next_bbox]
                    flow = np.load(
                        os.path.join(confidence_dir,
                                     format(i + 1, '08') + '_flow.npy'))
                    entropy_data = np.load(
                        os.path.join(confidence_dir,
                                     format(i + 1, '08') + '_entropy.npy'))
                    entropy = (entropy_data - np.min(entropy_data)) / (
                        np.max(entropy_data) - np.min(entropy_data))
                    confidence = 1 - entropy
                    warped_im1 = flow_warp(im1, flow)
                    diff, rgb_diff = color_confidence(warped_im1, im2)

                    #next_mask = background_flow(im2, detection_box, flow)
                    next_mask = flow_warp_backward(foreground_candidate_mask,
                                                   flow)
                    # np.save(os.path.join(data_dir,format(i+1, '08')+"_fgmask.npy"), next_mask)
                    if (i > 0):
                        pre_flow_mask = np.load(
                            os.path.join(data_dir,
                                         format(i, '08') + "_fgmask.npy"))
                        double_warped = flow_warp(pre_flow_mask, flow)
                        # np.save(os.path.join(data_dir,format(i+1, '08')+"_prev_fgmask.npy"), double_warped)

                    overall_mask = (confidence[:, :, 0] * next_mask[:, :, 0] +
                                    entropy[:, :, 0]) / 2

                    state = SiamRPN_track(state, im2, overall_mask,
                                          confidence[:, :, 0],
                                          next_mask[:, :, 0], entropy[:, :, 0],
                                          index_1, index_2, gts[i + 1])
Exemplo n.º 4
0
def generate_masks(index, train_im_paths, train_labels):
    im_paths = train_im_paths[index]
    labels = train_labels[index]

    flow_data = []
    entropy_data = []
    scale_data = []
    lab_data = []
    iou_data = []
    detection_data = []
    box_data = []

    warped_images = []
    box_data = []
    for i in range(0, 3):
        im = np.copy(cv2.imread(im_paths[i]))
        im_h, im_w, im_c = im.shape
        names = im_paths[i].split('/')[-1].split('_')
        if (len(names) > 4):
            video_name = ''
            for more_index in range(0, len(names) - 3):
                if (more_index > 0):
                    video_name += '_'
                video_name += names[more_index]
            frame_name = names[len(names) - 3]
            type_name = names[len(names) - 2]
        else:
            video_name = names[0]
            frame_name = names[1]
            type_name = names[2]
        class_dir = os.path.join(data_dir, type_name, video_name)
        #x0,y0,w,h
        gt = youtube_to_rec(labels[i], im_h, im_w)
        flow = np.zeros((im_h, im_w, 2))
        if (i == 0):
            filename = os.path.join(class_dir, str(frame_name))
            with open(filename + '.txt') as ff:
                content = ff.readlines()
            ff.close()

        iou_result = []
        detection_score = []
        temp_result = []
        for j in range(0, 100):
            data = content[100 * i + j].split()
            x0, y0, w, h = data[0:4]
            res = [int(x0), int(y0), int(w), int(h)]
            temp_result.append(res)
            iou_result.append(float(data[4]))
            detection_score.append(float(data[5]))
        iou_data.append(iou_result)
        detection_data.append(detection_score)
        box_data.append(temp_result)

        if (i > 0):
            #im = cv2.imread(im_paths[i-1])
            flow = np.load(
                os.path.join(class_dir,
                             str(frame_name) + '_flow.npy'))
            entropy = np.load(
                os.path.join(class_dir,
                             str(frame_name) + '_entropy.npy'))
            warped_im = flow_warp_backward(im, flow)
            diff, rgb_diff = color_confidence(warped_im, im)
            flow_data.append(flow)
            lab_data.append(diff)
            entropy_data.append(entropy)

    return flow_data, entropy_data, lab_data, iou_data, detection_data, box_data