pos*_*sha 1 c++ opencv image-processing
在我的代码中,我将关键点插入到代码中所示的向量中,任何人都可以告诉我如何将其保存到文本文件中.
Mat object = imread("face24.bmp", CV_LOAD_IMAGE_GRAYSCALE);
if( !object.data )
{
// std::cout<< "Error reading object " << std::endl;
return -2;
}
//Detect the keypoints using SURF Detector
int minHessian = 500;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> kp_object;
detector.detect( object, kp_object );
Run Code Online (Sandbox Code Playgroud)
我想将kp_object vecor保存到文本文件中.
您可以使用FileStorage来编写和读取数据,而无需编写自己的序列化代码.写作你可以使用:
std::vector<KeyPoint> keypointvector;
cv::Mat descriptormatrix
// do some detection and description
// ...
cv::FileStorage store("template.bin", cv::FileStorage::WRITE);
cv::write(store,"keypoints",keypointvector;
cv::write(store,"descriptors",descriptormatrix);
store.release();
Run Code Online (Sandbox Code Playgroud)
阅读你可以做类似的事情:
cv::FileStorage store("template.bin", cv::FileStorage::READ);
cv::FileNode n1 = store["keypoints"];
cv::read(n1,keypointvector);
cv::FileNode n2 = store["descriptors"];
cv::read(n2,descriptormatrix);
store.release();
Run Code Online (Sandbox Code Playgroud)
这当然是二进制文件.这实际上取决于你想要的东西; 如果你以后想要将txt文件解析成Matlab,你会发现它很慢.
| 归档时间: |
|
| 查看次数: |
7174 次 |
| 最近记录: |