I have extracted SIFT features in (opencv open source) and they are extracted as keypoints. Now, I would like to convert them to Matrix (With their x,y coordinates) or save them in a text file...
Here, you can see a sample code for extracting the keypoints and now I would like to know how convert them to MAT or save them in txt, xml or yaml...
cv::SiftFeatureDetector detector;
std::vector<cv::KeyPoint> keypoints;
detector.detect(input, keypoints);
Convert to cv::Mat is as follows.
Write to filestorage is
Today I came across the same problem as per this question. The answer proposed by Appleman1234 is nice if you don't care about runtime. I believe for loops will always cost you dearly if you care about runtime. So I stumbled upon and found this interesting function (
cv::KeyPoint::convert()
) in OpenCV, which allows you to directly convert a vector of KeyPoints (std::vector<KeyPoint> keypoints_vector
) into a vector of Point2f (std::vector<cv::Point2f> point2f_vector
).In your case, it can be used as follows:
For more details, refer this documentation here.