I am using OpenCV-Python.
I have identified corner points using cv2.cornerHarris
. The output is of type dst
.
I need to compute SIFT features of the corner points. The input to sift.compute()
has to be of the type KeyPoint
.
I'm not able to figure out how to use cv2.KeyPoint()
.
How do I do this?
Harris detector return dst, which have same shape with your image. Harris mark on dst where it think the corner. So, you have to extract keypoint from dst.
def harris(self, img):'''Harris detector:param img: an color image:return: keypoint, image with feature marked corner'''gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)gray_img = np.float32(gray_img)dst = cv2.cornerHarris(gray_img, 2, 3, 0.04)result_img = img.copy() # deep copy image# Threshold for an optimal value, it may vary depending on the image.result_img[dst > 0.01 * dst.max()] = [0, 0, 255]# for each dst larger than threshold, make a keypoint out of itkeypoints = np.argwhere(dst > 0.01 * dst.max())keypoints = [cv2.KeyPoint(x[1], x[0], 1) for x in keypoints]return (keypoints, result_img)