加载保存的 SURF 关键点
Loading saved SURF keypoints
我正在检测图像中的 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);
找到解决方案,我会post在这里,以防其他人遇到同样的问题。
std::vector<cv::KeyPoint> testPoints;
cv::FileStorage fs2("keypointsVW.yml", cv::FileStorage::READ);
cv::FileNode kptFileNode = fs2["keypointsVW"];
read(kptFileNode, testPoints);
fs2.release();
我正在检测图像中的 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);
找到解决方案,我会post在这里,以防其他人遇到同样的问题。
std::vector<cv::KeyPoint> testPoints;
cv::FileStorage fs2("keypointsVW.yml", cv::FileStorage::READ);
cv::FileNode kptFileNode = fs2["keypointsVW"];
read(kptFileNode, testPoints);
fs2.release();