我正在检测图像中的SURF特征,然后将它们写入yml
文件。然后,我想再次从yml
文件中加载功能,以尝试检测对象,但此刻我在加载要在图像上绘制关键点时遇到了麻烦。
我正在这样写关键点:
cv::FileStorage fs("keypointsVW.yml", cv::FileStorage::WRITE);
write(fs, "keypoints_1", keypoints_1);
fs.release();
我试图这样阅读它们:
cv::FileStorage fs2("keypointsVW.yml", cv::FileStorage::READ);
read(fs2, "keypoints_1", keypoints_1);
fs2.release();
但这会产生大量错误。
检测并绘制代码:
cv::Mat img_1 = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
int minHessian = 400;
cv::SurfFeatureDetector detector(minHessian);
std::vector<cv::KeyPoint> keypoints_1;
detector.detect(img_1, keypoints_1);
cv::Mat img_keypoints_1;
//......write code
//.......read code
drawKeypoints(img_1, keypoints_1, img_keypoints_1);
imshow("keypoints_1", img_keypoints_1);
最佳答案
找到了解决方案,如果有人遇到同样的问题,我将在这里发布。
std::vector<cv::KeyPoint> testPoints;
cv::FileStorage fs2("keypointsVW.yml", cv::FileStorage::READ);
cv::FileNode kptFileNode = fs2["keypointsVW"];
read(kptFileNode, testPoints);
fs2.release();
关于c++ - 加载保存的SURF关键点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27841067/