问题
I am trying to create a codebook from a set of image patches. I have divided the images (Caltech 101) into 20 X 20 image patches. I want to create a SIFT descriptor for each patch. But for some of the image patches, it does not return any descriptor/keypoint. I have tried using OpenCV and vlfeat. The behavior is same using any of the libraries.
Following is my code using OpenCV -
sift = cv2.SIFT()
img = cv2.imread('patch_temp.jpg',0)
imgptch = cv2.imread('image_patch.jpg',cv2.CV_LOAD_IMAGE_GRAYSCALE)
kp, des = sift.detectAndCompute(imgptch,None)
print des
des is 'None'. Same is the case if I use vlfeat. Note : Above works if I use a different image. It returns None for some of the images (6 out of 10).
I have created the image patch using OpenCV indexing -
patch = img[0:20,0:20]
cv2.imwrite('image_patch.jpg',img)
回答1:
The function sift.detectAndCompute
will first try to detect a SIFT keypoint then compute a descriptor at the found location.
This is not what you want: you want to have a descriptor for each patch.
You can hand craft the keypoint locations first (by adjusting their pt
property to the center of your patches and adjusting their size
property to your patch size).
Then, call only the descriptor extractor on this set of locations.
来源:https://stackoverflow.com/questions/27099760/null-no-sift-descriptor-and-keypoints-generated-in-python