在寻找这个(1 , 2 , 3 , 4)的答案后,我仍然对这两个问题感到困惑
- 如果这是可能的
- 如果是这样,怎么做
我希望能够从.xml
已写入cv::Mat
包含内容的文件中Point2f keypoints
读取,并将其读回其原始状态std::vector<cv::KeyPoint>
。
我对文件的写入如下所示:
cv::Ptr<cv::FeatureDetector> detector = new cv::OrbFeatureDetector(featureSize);
cv::FileStorage fsKpts("keypoints.xml", cv::FileStorage::WRITE);
for(size_t i = 0; i < ImgVec.size(); i ++){
std::vector<cv::KeyPoint> imgKpts;
std::vector<cv::Point2f> points;
std::vector<cv::KeyPoint>::iterator it;
detector->detect(ImgVec[i], imgKpts);
for(it = imgKpts.begin(); it != imgKpts.end(); it ++) points.push_back(it->pt);
cv::Mat matKpts(points);
cv::string iValue = std::to_string(i);
cv::string filename = "Image_" + iValue;
fsKpts << filename << matKpts;
}
fsKpts.release();
但到目前为止,我完全无法将它读回原来的状态,std::vector<cv::KeyPoint>
以便进行keypoint
匹配。
有什么帮助吗?
编辑
当前的阅读猜测:
std::vector<cv::KeyPoint> fileKptsVec;
std::vector<cv::Point2f> filePoints;
cv::FileStorage fs("keypoints.xml", cv::FileStorage::READ);
for(size_t i = 0; i < imgVec.size(); i++){
cv::string iValue = std::to_string(i);
cv::string filename = "Image_" + iValue;
fs[filename] >> filePoints[i];
fileKptsVec.push_back(filePoints[i]); // -- Doesn't work
}
fs.release();
编辑 2
.xml
内容:
<?xml version="1.0"?>
<opencv_storage>
<Image_0 type_id="opencv-matrix">
<rows>500</rows>
<cols>1</cols>
<dt>"2f"</dt>
<data>
456. 640. 458. 638. 603. 525. 411. 353. 604. 548. 417. 334. 600.
515. 382. 334. 594. 448. 572. 481. 449. 603. 574. 612. 441. 648.
470. 334. 439. 650. 412. 387. 438. 550. 568. 514. 575. 602. 452.
...
</data></Image_0>
<Image_1 type_id="opencv-matrix">
<rows>500</rows>
<cols>1</cols>
<dt>"2f"</dt>
<data>
521. 353. 467. 563. 537. 510. 505. 378. 479. 286. 451. 552. 460.
554. 541. 545. 463. 554. 492. 404. 457. 552. 534. 546. 463. 562.
541. 550. 519. 350. 490. 285. 498. 473. 497. 635. 451. 578. 461.
...
</data></Image_1>
etc. etc.