/** @brief Detect regions on the image and compute their attributes (description) @param image Image. @param regions The detected regions and attributes (the caller must delete the allocated data) @param mask 8-bit gray image for keypoint filtering (optional). Non-zero values depict the region of interest. */ bool Describe(const Image<unsigned char>& image, std::unique_ptr<Regions> ®ions, const Image<unsigned char> * mask = NULL) { cv::Mat img; cv::eigen2cv(image.GetMat(), img); std::vector< cv::KeyPoint > vec_keypoints; cv::Mat m_desc; cv::Ptr<cv::Feature2D> extractor = cv::AKAZE::create(cv::AKAZE::DESCRIPTOR_KAZE); extractor->detectAndCompute(img, cv::Mat(), vec_keypoints, m_desc); if (!vec_keypoints.empty()) { Allocate(regions); // Build alias to cached data AKAZE_OpenCV_Regions * regionsCasted = dynamic_cast<AKAZE_OpenCV_Regions*>(regions.get()); // reserve some memory for faster keypoint saving regionsCasted->Features().reserve(vec_keypoints.size()); regionsCasted->Descriptors().reserve(vec_keypoints.size()); typedef Descriptor<float, 64> DescriptorT; DescriptorT descriptor; int cpt = 0; for(std::vector< cv::KeyPoint >::const_iterator i_keypoint = vec_keypoints.begin(); i_keypoint != vec_keypoints.end(); ++i_keypoint, ++cpt){ SIOPointFeature feat((*i_keypoint).pt.x, (*i_keypoint).pt.y, (*i_keypoint).size, (*i_keypoint).angle); regionsCasted->Features().push_back(feat); memcpy(descriptor.getData(), m_desc.ptr<typename DescriptorT::bin_type>(cpt), DescriptorT::static_size*sizeof(typename DescriptorT::bin_type)); regionsCasted->Descriptors().push_back(descriptor); } } return true; };
static bool ComputeCVFeatAndDesc(const Image<unsigned char>& I, std::vector<SIOPointFeature>& feats, std::vector<DescriptorT >& descs) { //Convert image to OpenCV data cv::Mat img; cv::eigen2cv(I.GetMat(), img); cvFeature2DInterfaceT detectAndDescribeClass; std::vector< cv::KeyPoint > vec_keypoints; cv::Mat m_desc; detectAndDescribeClass(img, cv::Mat(), vec_keypoints, m_desc); if (!vec_keypoints.empty()) { feats.reserve(vec_keypoints.size()); descs.reserve(vec_keypoints.size()); DescriptorT descriptor; int cpt = 0; for(std::vector< cv::KeyPoint >::const_iterator i_keypoint = vec_keypoints.begin(); i_keypoint != vec_keypoints.end(); ++i_keypoint, ++cpt){ SIOPointFeature feat((*i_keypoint).pt.x, (*i_keypoint).pt.y, (*i_keypoint).size, (*i_keypoint).angle); feats.push_back(feat); memcpy(descriptor.getData(), m_desc.ptr<typename DescriptorT::bin_type>(cpt), DescriptorT::static_size*sizeof(typename DescriptorT::bin_type)); descs.push_back(descriptor); } return true; } return false; }