cvg / Hierarchical-Localization

Visual localization made easy with hloc
Apache License 2.0
3.24k stars 599 forks source link

HLOC Returns Random Localization #434

Open IlanElfen opened 1 month ago

IlanElfen commented 1 month ago

Hi, I've created a reconstruction model in Metashape and exported it in the sfm format (points3d, images3d, cameras). I've also generated the global-feats-netvlad.h5 and feats-disk.h5.

The camera positions load correctly but the localization seems completely random, even when keeping the camera stationary. (The camera is currently at (54, 1)) image

Here is the relevant part of my code:

global_descriptor = extract_features.main2(
            model=self.global_model, device=self.device, image=image, gray=False
        )
        pairs = pairs_from_retrieval.main2(
            self.global_db, global_descriptor, self.k, self.global_names
        )
        matches = match_features.main2(
            pairs, local_descriptor, self.local_db, self.matcher, self.device
        )
        cv2.imwrite("tmp.png", cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
        camera = pycolmap.infer_camera_from_image(Path("tmp.png"))
        localizer = QueryLocalizer(self.model, self.conf)
        ret_files = pairs
        self.ref_ids = [self.model.find_image_with_name(n).image_id for n in ret_files]
        ret = pose_from_cluster(
            localizer, local_descriptor, camera, self.ref_ids, matches
        )
        if ret is None:
            return self.ax
        num_inliers = ret["num_inliers"]
        total_correspondences = len(ret["inliers"])
        R = ret["cam_from_world"].rotation.matrix()
        t = ret["cam_from_world"].translation

Any help is greatly appreciated!