convert keypoints to mat or save them to text file opencv

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

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<:keypoint> keypoints; detector.detect(input, keypoints); 

回答1:

Convert to cv::Mat is as follows.

std::vector<:keypoint> keypoints; std::vector<:point2f> points; std::vector<:keypoint>::iterator it;  for( it= keypoints.begin(); it!= keypoints.end();it++) {     points.push_back(it->pt); }  cv::Mat pointmatrix(points); 

Write to filestorage is

cv::FileStorage fs("test.yml", cv::FileStorage::WRITE); cv::FileStorage fs2("test2.xml", cv::FileStorage::WRITE);  detector.write(fs); detector.write(fs2); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!