Пример #1
0
    def extract_descriptor(self, image, feature):
        img = np.array(fu.all_to_gray(image), dtype='float32')
        _, desc, _ = self.fe.run(img)

        if desc is not None:
            desc = desc.T

        return desc
Пример #2
0
 def extract_descriptor(self, image, feature):
     image = feature_utils.all_to_gray(image)
     image = image / 255.0
     feature, descriptor = eng.vl_sift(
         matlab.single(image.tolist()), 'Magnif', self.Magnif,
         nargout=2)  # , peak_thresh=self.peak_thresh
     descriptor = np.transpose(np.array(descriptor))
     return descriptor
Пример #3
0
    def extract_all(self, image):
        img = np.array(fu.all_to_gray(image), dtype='float32')
        pts, desc, heatmap = self.fe.run(img)
        pts = pts[:2, :].T

        if desc is not None:
            desc = desc.T

        return (pts, desc)
Пример #4
0
    def extract_descriptor(self, image, feature):
        gray_image = utils.all_to_gray(image)
        patches = []
        for f in feature:
            patch = utils.extract_patch(gray_image, f, patch_sz=64)
            patches.append(patch)

        patches = np.array(patches)
        desc = self.extract_descriptors_from_patch_batch(patches)
        return desc
Пример #5
0
    def detect_feature(self, image):
        img = np.array(fu.all_to_gray(image), dtype='float32') / 255.0
        pts, _, _ = self.fe.run(img)

        nb_kpts = MAX_CV_KPTS
        #Already ordered by confidence
        if pts.shape[1] < MAX_CV_KPTS:
            nb_kpts = pts.shape[1]
        pts = pts[:2, :nb_kpts].T

        return pts
Пример #6
0
 def extract_all(self, image):
     # pdb.set_trace()
     image = feature_utils.all_to_gray(image)
     image = image / 255.0
     feature, descriptor = eng.vl_sift(
         matlab.single(image.tolist()), 'Magnif', self.Magnif,
         nargout=2)  # peak_thresh=self.peak_thresh,
     feature = np.transpose(np.array(feature))
     descriptor = np.transpose(np.array(descriptor))
     # pdb.set_trace()
     return feature, descriptor
Пример #7
0
    def extract_descriptor(self, image, feature):
        commands = self._get_command_list('desc')
        img = fu.all_to_gray(image)

        cv2.imwrite(self.temp_img_path, img)
        for command in commands:
            subprocess.run(command, shell=True)

        data_dict = loadh5(self.temp_desc_path)
        desc = data_dict.get('descriptors')

        return desc
Пример #8
0
    def extract_descriptor(self, image, feature):
        img = np.array(fu.all_to_gray(image), dtype='float32') / 255.0
        pts, desc, _ = self.fe.run(img)

        nb_kpts = MAX_CV_KPTS
        #Already ordered by confidence
        if pts.shape[1] < MAX_CV_KPTS:
            nb_kpts = pts.shape[1]

        if desc is not None:
            desc = desc[:, :nb_kpts].T

        return desc
Пример #9
0
    def extract_descriptor(self, image, feature):
        """
        feature = [[x, y, scale, angle]...]
        """
        gray_image = utils.all_to_gray(image)
        patches = []
        for f in feature:
            patch = utils.extract_patch(gray_image, f, patch_sz=32)
            patches.append(patch)
        patches = np.array(patches)

        desc = self.extract_descriptors_from_patch_batch(patches)

        return desc
Пример #10
0
    def extract_all(self, image):
        img = np.array(fu.all_to_gray(image), dtype='float32') / 255.0
        start = time.time()
        pts, desc, _ = self.fe.run(img)

        nb_kpts = MAX_CV_KPTS
        #Already ordered by confidence
        if pts.shape[1] < MAX_CV_KPTS:
            nb_kpts = pts.shape[1]
        pts = pts[:2, :nb_kpts].T

        if desc is not None:
            desc = desc[:, :nb_kpts].T

        return (pts, desc)
Пример #11
0
    def detect_feature(self, image):
        commands = self._get_command_list('kp')
        img = fu.all_to_gray(image)

        cv2.imwrite(self.temp_img_path, img)
        for command in commands:
            subprocess.run(command, shell=True)

        kpts_raw = loadKpListFromTxt(self.temp_kpts_path)
        kpts = []
        for k in kpts_raw:
            kpts.append([int(k[0]), int(k[1])])

        kpts = np.array(kpts)
        return kpts
Пример #12
0
    def detect_feature(self, image):
        image = fu.all_to_gray(image)
        out = self.forward_passer(image)
        kpts = out.ips_rc.T
        print(kpts.shape)
        order = np.argsort(out.ip_scores)[::-1]

        num_kpts = MAX_KPTS
        if len(order) < MAX_KPTS:
            num_kpts = len(order)

        order = order[:num_kpts]
        kpts = kpts[order, :]
        kpts = kpts[:, [1, 0]]

        return kpts
Пример #13
0
    def extract_all(self, image):
        commands = self._get_command_list('desc')
        img = fu.all_to_gray(image)

        cv2.imwrite(self.temp_img_path, img)
        for command in commands:
            subprocess.run(command, shell=True)

        kpts_raw = loadKpListFromTxt(self.temp_kpts_path)
        data_dict = loadh5(self.temp_desc_path)
        desc = data_dict.get('descriptors')
        kpts = []
        for k in kpts_raw:
            kpts.append([int(k[0]), int(k[1])])

        kpts = np.array(kpts)

        return (kpts, desc)
Пример #14
0
    def extract_descriptors_from_patch_batch(self, batch):
        gray_batch = list()
        for  p in batch:
            gray_batch.append(utils.all_to_gray(p))

        batch = np.array(gray_batch)
        batch = np.expand_dims(batch, axis=1)
        #make multiple batches of Max batch size
        splits = np.arange(0,batch.shape[0],MAX_BATCH)[1:]
        batch_list = np.split(batch, splits)
        descriptor_list = list()

        for bat in batch_list:
            if bat.size==0:
                continue
            bat = torch.from_numpy(bat)
            descriptors = self.model(bat.float())
            descriptor_list.extend(descriptors.detach().numpy().tolist())

        descriptors = np.array(descriptor_list)
        return descriptors
Пример #15
0
    def extract_all(self, image):
        img = fu.all_to_gray(image)
        kpts, desc = self.run(img)

        return (kpts, desc)
Пример #16
0
    def extract_descriptor(self, image, feature):
        img = fu.all_to_gray(image)
        _, desc = self.run(img)

        return desc
Пример #17
0
    def detect_feature(self, image):
        img = fu.all_to_gray(image)
        kpts, _ = self.run(img)

        return kpts
Пример #18
0
 def detect_feature(self, image):
     img = np.array(fu.all_to_gray(image), dtype='float32') / 255.0
     pts, _, _ = self.fe.run(img)
     pts = pts[:2, :].T
     return pts