I am using OpenCV-Python binding to write my image processing application. I am finding a way to write keypoints of a image in to a file which we can get back for matching purpose. There is code in C/C++ to do this, but could not find a way to this by using python
Please anyone have an idea about this, please share with me & all of us
Thanks
This is how you can do it, inspired from the link I gave earlier.
Save keypoints in a file
import cv2
import cPickle
im=cv2.imread("/home/bikz05/Desktop/dataset/checkered-3.jpg")
gr=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
d=cv2.FeatureDetector_create("SIFT")
kp=d.detect(gr)
index = []
for point in kp:
temp = (point.pt, point.size, point.angle, point.response, point.octave,
point.class_id)
index.append(temp)
# Dump the keypoints
f = open("/home/bikz05/Desktop/dataset/keypoints.txt", "w")
f.write(cPickle.dumps(index))
f.close()
Load and Display keypoints in the image
import cv2
import cPickle
im=cv2.imread("/home/bikz05/Desktop/dataset/checkered-3.jpg")
index = cPickle.loads(open("/home/bikz05/Desktop/dataset/keypoints.txt").read())
kp = []
for point in index:
temp = cv2.KeyPoint(x=point[0][0],y=point[0][1],_size=point[1], _angle=point[2],
_response=point[3], _octave=point[4], _class_id=point[5])
kp.append(temp)
# Draw the keypoints
imm=cv2.drawKeypoints(im, kp);
cv2.imshow("Image", imm);
cv2.waitKey(0)
INPUT IMAGE to 1st script
Displayed IMAGE in 2nd script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With