加载关键点和绘图
Loading keypoints and drawing
我有一段代码可以计算图像的SURF关键点并将它们保存到yml
文件中。然后,我尝试加载该文件并在图像上绘制保存的关键点。
关键点和编写代码:
cv::Mat img_1 = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
detectKeypointsImage(img_1);
int minHessian = 400;
cv::SurfFeatureDetector detector(minHessian);
std::vector<cv::KeyPoint> keypoints_1;
detector.detect(img_1, keypoints_1);
cv::Mat img_keypoints_1;
drawKeypoints(img_1, keypoints_1, img_keypoints_1);
cv::FileStorage fs("keypointsVW.yml", cv::FileStorage::WRITE);
write(fs, "keypoints_1", keypoints_1);
fs.release();
为了测试这是否有效,我然后注释掉上面的块减去以下行:
cv::Mat img_1 = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat 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();
drawKeypoints(img_1, testPoints, img_keypoints_1);
cv::imshow("keypoints_1", img_keypoints_1);
但是,当程序启动时,它显示的图像减去任何关键点。为什么会这样?
我从未使用过存储功能,但凭直觉,我认为您在加载数据时命名了错误的 FileNode。
我测试了这段代码,它可以工作:
std::vector<cv::KeyPoint> testPoints;
cv::FileStorage fs2("keypointsVW.yml", cv::FileStorage::READ);
cv::FileNode kptFileNode = fs2["keypoints_1"]; // Here you must use the name that you used for writing the data within the file.
// You named it "keypoints_1" before.
// It must be the same name that you used in write(fs, "keypoints_1", keypoints_1);
// so for example write(storage, "nodeName", data); needs you to call cv::FileNode kptFileNode = fs2["nodeName"]; later
read(kptFileNode, testPoints);
fs2.release();
drawKeypoints(img_1, testPoints, img_keypoints_1);
cv::imshow("keypoints_1", img_keypoints_1);
相关文章:
- GTKMM:拍摄绘图区域的屏幕截图?
- GTKMM:如何将键盘事件附加到绘图区域?
- OpenGL:使用实例化绘图与我正在绘制的帧缓冲进行绘制
- 为什么在我释放左键单击后,我的绘图会消失
- 通过关键点向量从地图中获取地图
- 如何防止opengl绘图拉伸到窗口大小?
- QT 无法通过上下文菜单添加新绘图 (QCustomPlot)
- Wxwidgets - 如何添加调整大小事件处理程序以使"X"绘图随窗口调整大小?
- 单击"推送"按钮应使用Qt C++在不同的窗口中显示绘图
- 从 C++ 调用 GNU 绘图,无需用户输入
- 存储将单个查询图像与多个图像的列表匹配的关键点索引
- 播放视频时在 qwidget 上绘图
- 在 qt 中的绘图中拖动误差线
- 在作为表后面图层的标签上绘图
- 点云库:计算筛选关键点 - 输入云错误
- WinAPI - 获取用于绘图的可滚动框架
- 使用C Visual Studio创建一个绘图图
- 定期使用 QPainter 绘图
- 在 DIB 上绘图不起作用
- 加载关键点和绘图