feat: statistics

This commit is contained in:
2025-12-22 12:46:34 +03:00
parent 9d4839aa2a
commit 0977a55cc2
2 changed files with 94 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ from pathlib import Path
from typing import Literal, Optional, Tuple
from PIL import Image
FeatureMethod = Literal["orb", "sift", "surf"]
FeatureMethod = Literal["orb", "sift", "surf", "akaze", "brisk"]
@dataclass
class VisionChunk:
@@ -33,6 +33,36 @@ class VisionChunk:
patchSize=31,
fastThreshold=20,
)
elif self.feature_method == "sift":
self._detector = cv2.SIFT_create(
nfeatures=1000,
nOctaveLayers=3,
contrastThreshold=0.04,
edgeThreshold=10,
sigma=1.6
)
elif self.feature_method == "surf":
self._detector = cv2.xfeatures2d.SURF_create(
hessianThreshold=400.0,
nOctaveLayers=3,
# nOctaveLayers=4,
upright=False
)
elif self.feature_method == "akaze":
self._detector = cv2.AKAZE_create(
descriptor_type=cv2.AKAZE_DESCRIPTOR_MLDB,
descriptor_size=0,
descriptor_channels=3,
threshold=0.001,
nOctaves=4,
diffusivity=cv2.KAZE_DIFF_PM_G2
)
elif self.feature_method == "brisk":
self._detector = cv2.BRISK_create(
thresh=30,
octaves=3,
patternScale=1.0
)
else:
raise ValueError(f"Unsupported feature method: {self.feature_method}")
return self._detector
@@ -40,6 +70,14 @@ class VisionChunk:
def _get_matcher(self) -> cv2.DescriptorMatcher:
if self._matcher is None:
self._matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
return self._matcher
if self.feature_method == 'orb':
self._matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
elif self.feature_method == 'sift':
FLANN_INDEX_LSH = 6
index_params = dict(algorithm=FLANN_INDEX_LSH, table_number=6, key_size=12, multi_probe_level=1)
search_params = dict(checks=50)
self._matcher = cv2.FlannBasedMatcher(index_params, search_params)
return self._matcher
def _preprocess(self, img_np: np.ndarray) -> np.ndarray: