"""入口:裁剪模板、匹配关键点并在截图上标点;由 ``start.bat`` 调用本脚本。""" from __future__ import annotations import sys from pathlib import Path # 仓库根:``routing``、``thirdparty``;``img-match``:单应等;``img-match/superpoint-match``:AKAZE / LoFTR / LightGlue。 _REPO_ROOT = Path(__file__).resolve().parent _IMG_MATCH = _REPO_ROOT / "img-match" _SUPERPOINT_MATCH = _IMG_MATCH / "superpoint-match" for _p in (_REPO_ROOT, _IMG_MATCH, _SUPERPOINT_MATCH): if str(_p) not in sys.path: sys.path.insert(0, str(_p)) from thirdparty.crop_img import CropImg from thirdparty.draw_point import DrawPoint from keypoints_matching import KeypointsMatching from akaze_match import AkazeMatch from lightglue_match import LightglueMatch from loftr_match import LoftrMatch from fit_homography import fit_homography from corner_points_on_match_img import corner_points_on_match_img from thirdparty.draw_rect import draw_rect from thirdparty.round_corners import round_corner if __name__ == "__main__": CropImg().crop_edges( 0.2, 0.2, 0.0, 0.0, "input/template.webp", "output/crop-img.png" ) # ``degree`` 实为圆角半径(像素),贴近网页卡片约 8~12px;模板更大时可酌增至 20~40。 # round_corner( # degree=20, # image="input/template.webp", # output_path="output/round-corner-img.png", # ) # keypoints_obj = AkazeMatch( # template="output/crop-img.png", # match_image="input/screenshot.png", # ) # keypoints_obj = LightglueMatch( # template="output/crop-img.png", # match_image="input/screenshot.png", # ) keypoints_obj = LoftrMatch( template="output/crop-img.png", match_image="input/screenshot.png", ) kp_match = KeypointsMatching(keypoints_obj) keypoints_arr = kp_match.get_keypoints() DrawPoint( keypoints_arr, "input/screenshot.png", "output/keypoints_on_screenshot.png").draw_point() homography_obj = fit_homography( keypoints_arr, correspondence=kp_match.correspondence(), ) corner_points_arr = corner_points_on_match_img( homography_obj, keypoints_obj.template, keypoints_obj.match_image, ) draw_rect( corner_points_arr, match_image="input/screenshot.png", output_path="output/template_rect_on_screenshot.png", )