コード例 #1
0
 def __getitem__(self, index):
     img_path = self.filelist[index]
     img = convert_to_rgb(io.imread(img_path))
     img = resize_max_length(img, 240)
     img = img[:, :, 0].astype(np.float32)
     img /= 255.0
     return img
コード例 #2
0
def read_img(img_path, scale):
    img = convert_to_rgb(io.imread(img_path))
    oh, ow = img.shape[:2]
    if isinstance(scale, int):
        img = resize_max_length(img, scale)
    elif isinstance(scale, tuple):
        img = cv2.resize(img, scale)
    h, w = img.shape[:2]
    scale_h, scale_w = h / oh, w / ow
    return img, scale_h, scale_w
コード例 #3
0
    def __getitem__(self, index):
        img_path = self.img_paths[index]
        img = io.imread(img_path)
        img = convert_to_rgb(img)

        # img0 = img
        img0 = resize_max_length(img, 640)
        img1, H = homography_adaption(img0, angle=self.angle)
        pix_pos0, pix_pos1 = sample_ground_truth(img0, H)

        # img = draw_corspd_region(img0, img1, H)
        # import matplotlib.pyplot as plt
        # plt.imshow(img)
        # plt.show()

        if self.transforms is not None:
            img0, pix_pos0 = self.transforms(img0, pix_pos0)
            img1, pix_pos1 = self.transforms(img1, pix_pos1)

        pix_pos2 = sample_negative(img1, pix_pos1)

        img0 = torch.tensor(img0).permute(2, 0, 1).float()
        img1 = torch.tensor(img1).permute(2, 0, 1).float()

        # img = draw_triplet(img0, pix_pos0, img1, pix_pos1, img1, pix_pos2)
        # import matplotlib.pyplot as plt
        # plt.imshow(img)
        # plt.show()
        # return

        pix_pos0 = torch.tensor(pix_pos0).float()
        pix_pos1 = torch.tensor(pix_pos1).float()
        target = dict(
            kps0=pix_pos0,
            kps1=pix_pos1,
            kps2=pix_pos2,
            H=H,
        )

        return img0, img1, target, index