Does descriptorType returns the int representing CV_TYPES?

asked 2015-04-15 10:05:37 -0600

thdrksdfthmn gravatar image

updated 2015-04-15 10:08:08 -0600

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;
   }
}
edit retag flag offensive close merge delete

Comments

looks fine to me. did you run into any problems like that ?

(i do not quite understand, why you're asking this ;)

berak gravatar imageberak ( 2015-04-16 06:32:43 -0600 )edit

Yes I have tested it and it seems to be ok, it works correctly. (I was asking if I can use the descriptorType and descriptorSize functions for creating the descriptors Mat - in the first line and in the switch, because I was thinking of another more complicated way :) )

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-16 07:32:08 -0600 )edit
1

Looks ok for me also. For example, with ORB the function returns CV_8U.

Eduardo gravatar imageEduardo ( 2015-04-16 07:38:53 -0600 )edit
1

@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 ?)

berak gravatar imageberak ( 2015-04-16 07:54:48 -0600 )edit

Why haven't I thought of a template? This means choose the template based n the extractorPtr->descriptorType()?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-16 08:42:17 -0600 )edit