Applies SIFT to the image.
Args:
image: Input image.
Returns:
np.ndarray: Image with keypoints drawn.
list: Keypoints detected.
np.ndarray: Descriptors of the keypoints.
Source code in inference/core/workflows/core_steps/classical_cv/sift/v1.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 | def apply_sift(image: np.ndarray) -> (np.ndarray, list, np.ndarray):
"""
Applies SIFT to the image.
Args:
image: Input image.
Returns:
np.ndarray: Image with keypoints drawn.
list: Keypoints detected.
np.ndarray: Descriptors of the keypoints.
"""
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT_create()
kp, des = sift.detectAndCompute(gray, None)
img_with_kp = cv2.drawKeypoints(gray, kp, image)
# Convert keypoints to the desired format
keypoints = [
{
"pt": (point.pt[0], point.pt[1]),
"size": point.size,
"angle": point.angle,
"response": point.response,
"octave": point.octave,
"class_id": point.class_id,
}
for point in kp
]
return img_with_kp, keypoints, des
|