加载已保存的SURF关键点

时间:2015-01-08 13:16:44

标签: c++ opencv feature-detection surf

我正在检测图像中的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);

1 个答案:

答案 0 :(得分:2)

找到解决方案,我会在这里发布,以防其他人遇到同样的问题。

std::vector<cv::KeyPoint> testPoints;
cv::FileStorage fs2("keypointsVW.yml", cv::FileStorage::READ);
cv::FileNode kptFileNode = fs2["keypointsVW"];
read(kptFileNode, testPoints);
fs2.release();