Does descriptorType returns the int representing CV_TYPES?
Hi, I have seen that there is a function cv::DescriptorExtractor::descriptorType
the is returning an int
. Is it the same as CV_8U, CV_32F, etc?
Is it ok to use it for creating a cv::Mat
for some descriptors stored in a file (that was not saved with cv::FileStorage
), so I can do :
cv::Mat descriptors(numOfDescriptors, extractorPtr->descriptorSize(), extractorPtr->descriptorType()); // extractorPtr is a cv::Ptr< cv::DescriptorExctractor >
for (std::size_t i = 0; i < numOfDescriptors; i++)
{
for (std::size_t j = 0; j < descriptorValues.size(); j++) // where descriptorValues is a vector of string
{
switch (extractorPtr->descriptorType())
{
case CV_8U:
descriptors.ptr< uchar >(i)[j] = std::strtoi(descriptorValues[j]);
break;
case CV_32F:
descriptors.ptr< float >(i)[j] = std::strtof(descriptorValues[j]);
break;
default:
std::cerr << "Wrong descriptor type" << std::endl;
break;
}
}
looks fine to me. did you run into any problems like that ?
(i do not quite understand, why you're asking this ;)
Yes I have tested it and it seems to be ok, it works correctly. (I was asking if I can use the
descriptorType
anddescriptorSize
functions for creating the descriptors Mat - in the first line and in the switch, because I was thinking of another more complicated way :) )Looks ok for me also. For example, with ORB the function returns CV_8U.
@thdrksdfthmn, if we assume, that all descriptors in your file have the same type, you could move the check out of the loop, or even make it a template function.
(on the other hand, apart from being ugly, is it important enough to refactor this ?)
Why haven't I thought of a template? This means choose the template based n the
extractorPtr->descriptorType()
?