Loading saved SURF keypoints

六月ゝ 毕业季﹏ 提交于 2019-12-11 13:25:55

问题


I am detecting SURF features in an image and then writing them to a yml file. I then want to load the features from the yml file again to try and detect an object but at the moment I'm having trouble loading the keypoints to draw them on an image.

I'm writing the keypoints like so:

cv::FileStorage fs("keypointsVW.yml", cv::FileStorage::WRITE);
write(fs, "keypoints_1", keypoints_1);
fs.release();

I am trying to read them like so:

cv::FileStorage fs2("keypointsVW.yml", cv::FileStorage::READ);
read(fs2, "keypoints_1", keypoints_1);
fs2.release();

But this is producing a host of errors.

Detection and draw code:

    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:


Found the solution, I'll post it here in case anyone else has the same problem.

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


来源:https://stackoverflow.com/questions/27841067/loading-saved-surf-keypoints

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