user2746420
user2746420

Reputation: 55

Read yml file with OpenCV

With OpenCV, I want to find keypoints in different images and save them on my hard disk. This works very well for the saving part. To save the keypoints I use:

Mat it;
it = imread( "pic1.jpg", IMREAD_GRAYSCALE);
vector<KeyPoint> keypoints;
detector.detect( (it), keypoints );
FileStorage fs("keypoint1.yml", FileStorage::WRITE);
write( fs , "keypoint", keypoints );
fs.release();

When I try to read the file again with:

vector<KeyPoint> keypoint1s;
FileStorage fs2("keypoint1.yml", FileStorage::READ);
FileNode kptFileNode = fs2["keypoint1"];
read( kptFileNode, keypoint1s );
fs2.release();

If I do it like that, "keypoint1s" is empty. What is wrong?

Upvotes: 2

Views: 3407

Answers (1)

Simon G.
Simon G.

Reputation: 370

Your variable name is wrong when reading:

FileNode kptFileNode = fs2["keypoint1"];

should be

FileNode kptFileNode = fs2["keypoint"];

This works for me:

vector<int> keypoints;
keypoints.push_back(1);
keypoints.push_back(2);

FileStorage fs("keypoint1.yml", FileStorage::WRITE);
write(fs , "keypoint", keypoints);
fs.release();

vector<int> newKeypoints;
FileStorage fs2("keypoint1.yml", FileStorage::READ);
FileNode kptFileNode = fs2["keypoint"];
read(kptFileNode, newKeypoints);
fs2.release();

Upvotes: 5

Related Questions