convert keypoints to mat or save them to text file opencv

前端 未结 2 1352
执念已碎
执念已碎 2021-01-01 02:23

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

2条回答
  •  一整个雨季
    2021-01-01 02:56

    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 keypoints_vector) into a vector of Point2f (std::vector point2f_vector).

    In your case, it can be used as follows:

    std::vector keypoints_vector; //We define vector of keypoints
    std::vector point2f_vector; //We define vector of point2f
    cv::KeyPoint::convert(keypoints_vector, point2f_vector, std::vector< int >()); //Then we use this nice function from OpenCV to directly convert from KeyPoint vector to Point2f vector
    cv::Mat img1_coordinates(point2f_vector); //We simply cast the Point2f vector into a cv::Mat as Appleman1234 did
    

    For more details, refer this documentation here.

提交回复
热议问题