|
|
@@ -1,46 +0,0 @@
|
|
|
-import numpy as np
|
|
|
-from matchers import TemplateMatcher, FeatureMatcher
|
|
|
-
|
|
|
-
|
|
|
-def test_template_matcher_finds_known_location():
|
|
|
- # 构造全景图 400x200,中间放一块带纹理的红色方块
|
|
|
- # 注意:纯色 ROI 会让 TM_CCOEFF_NORMED 产生退化(全图相关值相同),
|
|
|
- # 因此给红色通道附加单调渐变纹理,使模板匹配有唯一峰值。
|
|
|
- panorama = np.zeros((200, 400, 3), dtype=np.uint8)
|
|
|
- y, x = np.mgrid[80:120, 180:220]
|
|
|
- panorama[80:120, 180:220, 0] = ((x - 180) * 6).astype(np.uint8)
|
|
|
- panorama[80:120, 180:220, 1] = ((y - 80) * 6).astype(np.uint8)
|
|
|
- panorama[80:120, 180:220, 2] = 255
|
|
|
-
|
|
|
- # 构造 PTZ 图:只看这块红色方块的中心 ROI
|
|
|
- ptz = panorama[80:120, 180:220].copy()
|
|
|
-
|
|
|
- matcher = TemplateMatcher(scales=(0.8, 1.0, 1.2), score_threshold=0.5)
|
|
|
- result = matcher.match(ptz, panorama)
|
|
|
-
|
|
|
- assert result is not None
|
|
|
- x_ratio, y_ratio, score, scale = result
|
|
|
- # 中心应在 (200, 100) 附近
|
|
|
- assert 0.45 <= x_ratio <= 0.55
|
|
|
- assert 0.45 <= y_ratio <= 0.55
|
|
|
- assert score > 0.8
|
|
|
-
|
|
|
-
|
|
|
-def test_feature_matcher_finds_known_location():
|
|
|
- # 用真实纹理更丰富的图案,避免弱纹理下 ORB 关键点不足
|
|
|
- np.random.seed(1)
|
|
|
- panorama = np.random.randint(0, 255, (200, 400, 3), dtype=np.uint8)
|
|
|
- # 在中间嵌入一块带纹理的 PTZ 区域
|
|
|
- patch = np.random.randint(0, 255, (40, 40, 3), dtype=np.uint8)
|
|
|
- panorama[80:120, 180:220] = patch
|
|
|
-
|
|
|
- ptz = panorama[80:120, 180:220].copy()
|
|
|
-
|
|
|
- matcher = FeatureMatcher(lowe_ratio=0.8, min_matches=4, min_inliers=4)
|
|
|
- result = matcher.match(ptz, panorama)
|
|
|
-
|
|
|
- assert result is not None
|
|
|
- x_ratio, y_ratio, inliers, matches = result
|
|
|
- assert 0.45 <= x_ratio <= 0.55
|
|
|
- assert 0.45 <= y_ratio <= 0.55
|
|
|
- assert inliers >= 4
|