Question

I want to detect an object in an image using features from OpenCV. I have some images containing that kind of objects. I search the KeyPoints in them and store the descriptors of the ones inside the contour of the object. Based on those descriptors I want to do the matching between them and the descriptors of KeyPoints from an image that may, or may not contain the object.

My problem is that for some cases (eg. ORB) the descriptors are of type CV_8U and for others (eg. SIFT) they are CV_32F. If I want to store them in a file and if I do:

fileStream << descriptors.ptr<uchar>(rowIdx)[colIdx] << ";";

the CV_32F ones are not ok (but there is no error) and most of them are 255. And if I do:

fileStream << descriptors.ptr<float>(rowIdx)[colIdx] << ";";

the CV_8U ones are stored as 4.00897e-07 or 5.14004e+19, that is also not ok.

How do you suggest me to do it? If you know some better way to do the whole problem, please tell me.

Was it helpful?

Solution

You have to do just this:

cv::FileStorage fsWrite("YourDescriptors.txt", FileStorage::WRITE );
fsWrite["descriptors"] << descriptors;
fsWrite.release();

And to read from file:

cv::FileStorage fsRead("YourDescriptors.txt", FileStorage::READ );
fsRead["descriptors"] >>  descriptors;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top