Base line detector/descriptor
- class limap.line2d.base_detector.BaseDetector(options=BaseDetectorOptions(set_gray=True, max_num_2d_segs=3000, do_merge_lines=False, visualize=False, weight_path=None))
Bases:
object
Virtual class for line detector
- detect(camview)
Virtual method (for detector) - detect 2D line segments
- Parameters:
view (
limap.base.CameraView
) – The limap.base.CameraView instance corresponding to the image- Returns:
line detections. Each row corresponds to x1, y1, x2, y2 and score.
- Return type:
np.array
of shape (N, 5)
- detect_all_images(output_folder, imagecols, skip_exists=False)
Perform line detection on all images and save the line segments
- Parameters:
output_folder (str) – The output folder
imagecols (
limap.base.ImageCollection
) – The input image collectionskip_exists (bool) – Whether to skip already processed images
- Returns:
The line detection for each image indexed by the image id. Each segment is with shape (N, 5). Each row corresponds to x1, y1, x2, y2 and score.
- Return type:
dict[int ->
np.array
]
- detect_and_extract(camview)
Virtual method (for dual-functional class that can perform both detection and extraction) - Detect and extract on a single image
- Parameters:
view (
limap.base.CameraView
) – The limap.base.CameraView instance corresponding to the image- Returns:
of shape (N, 5), line detections. Each row corresponds to x1, y1, x2, y2 and score. Computed from the detect method. descinfo: The features extracted from the function extract
- Return type:
segs (
np.array
)
- detect_and_extract_all_images(output_folder, imagecols, skip_exists=False)
Perform line detection and description on all images and save the line segments and descriptors
- Parameters:
output_folder (str) – The output folder
imagecols (
limap.base.ImageCollection
) – The input image collectionskip_exists (bool) – Whether to skip already processed images
- Returns:
The line detection for each image indexed by the image id. Each segment is with shape (N, 5). Each row corresponds to x1, y1, x2, y2 and score. descinfo_folder (str): Path to the extracted descriptors.
- Return type:
all_segs (dict[int ->
np.array
])
- extract(camview, segs)
Virtual method (for extractor) - extract the features for the detected segments
- Parameters:
view (
limap.base.CameraView
) – The limap.base.CameraView instance corresponding to the imagesegs –
np.array
of shape (N, 5), line detections. Each row corresponds to x1, y1, x2, y2 and score. Computed from the detect method.
- Returns:
The extracted feature
- extract_all_images(output_folder, imagecols, all_2d_segs, skip_exists=False)
Perform line descriptor extraction on all images and save the descriptors.
- Parameters:
output_folder (str) – The output folder.
imagecols (
limap.base.ImageCollection
) – The input image collectionall_2d_segs (dict[int ->
np.array
]) – The line detection for each image indexed by the image id. Each segment is with shape (N, 5). Each row corresponds to x1, y1, x2, y2 and score. Computed from detect_all_imagesskip_exists (bool) – Whether to skip already processed images.
- Returns:
The path to the saved descriptors.
- Return type:
descinfo_folder (str)
- get_descinfo_fname(descinfo_folder, img_id)
Virtual method (for extractor) - Get the target filename of the extracted feature
- Parameters:
descinfo_folder (str) – The output folder
img_id (int) – The image id
- Returns:
target filename
- Return type:
str
- get_descinfo_folder(output_folder)
Return the folder path to the extracted descriptors
- Parameters:
output_folder (str) – The output folder
- Returns:
The path to the saved descriptors
- Return type:
path_to_descinfos (str)
- get_module_name()
Virtual method (need to be implemented) - return the name of the module
- get_segments_folder(output_folder)
Return the folder path to the detected segments
- Parameters:
output_folder (str) – The output folder
- Returns:
The path to the saved segments
- Return type:
path_to_segments (str)
- read_descinfo(descinfo_folder, img_id)
Virtual method (for extractor) - Read in the extracted feature. Dual function for save_descinfo.
- Parameters:
descinfo_folder (str) – The output folder
img_id (int) – The image id
- Returns:
The extracted feature
- sample_descinfo_by_indexes(descinfo, indexes)
Virtual method (for dual-functional class that can perform both detection and extraction) - sample descriptors for a subset of images
- Parameters:
descinfo – The features extracted from the function extract.
indexes (list[int]) – List of image ids for the subset.
- save_descinfo(descinfo_folder, img_id, descinfo)
Virtual method (for extractor) - Save the extracted feature to the target folder
- Parameters:
descinfo_folder (str) – The output folder
img_id (int) – The image id
descinfo – The features extracted from the function extract
- namedtuple limap.line2d.base_detector.BaseDetectorOptions(set_gray: bool = True, max_num_2d_segs: int = 3000, do_merge_lines: bool = False, visualize: bool = False, weight_path: str | None = None)
Bases:
NamedTuple
Base options for the line detector
- Fields:
set_gray (
bool
) – whether to set the image to gray scale (sometimes depending on the detector)max_num_2d_segs (
int
) – maximum number of detected line segments (default = 3000)do_merge_lines (
bool
) – whether to merge close similar lines at post-processing (default = False)visualize (
bool
) – whether to output visualizations into output folder along with the detections (default = False)weight_path (
str
) – specify path to load weights (at default, weights will be downloaded to ~/.local)
- static __new__(_cls, set_gray: bool = True, max_num_2d_segs: int = 3000, do_merge_lines: bool = False, visualize: bool = False, weight_path: str | None = None)
Create new instance of BaseDetectorOptions(set_gray, max_num_2d_segs, do_merge_lines, visualize, weight_path)