OpenCV Error: Bad argument (bytes must be 16, 32, or 64) in BriefDescriptorExtractorImpl

OpenCV Error: Bad argument (bytes must be 16, 32, or 64) in BriefDescriptorExtractorImpl

我正在尝试使用 SURF 检测特征点,并使用 BRIEF 检测描述符。

cv::Ptr<Feature2D> detector = xfeatures2d::SurfFeatureDetector::create(400);
Mat descriptors_img1, descriptors_img2;


//-- Step 2: Calculate descriptors (feature vectors)
detector->detect(img1, kp1);
detector->detect(img2, kp2);

cv::Ptr<DescriptorExtractor> extractor = xfeatures2d::BriefDescriptorExtractor::create(400);

extractor->compute(img1, kp1, descriptors_img1 );
extractor->compute(img2, kp2, descriptors_img2 );

但我收到错误

OpenCV Error: Bad argument (bytes must be 16, 32, or 64) in BriefDescriptorExtractorImpl, file /home/user/opencv_contrib-3.2.0/modules/xfeatures2d/src/brief.cpp, line 185
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/user/opencv_contrib-3.2.0/modules/xfeatures2d/src/brief.cpp:185: error: (-5) bytes must be 16, 32, or 64 in function BriefDescriptorExtractorImpl

谁能解释一下这个错误以及如何解决它。 我正在使用 OpenCV3.2

BriefDescriptorExtractor(int bytes=32,bool use_orientation = false)

第一个参数应该是字节。 因此,从您的代码中删除参数 400 并尝试。第一个参数应该是 2^ 而不是 400。 更改代码

cv::Ptr<DescriptorExtractor> extractor = xfeatures2d::BriefDescriptorExtractor::create(400);

cv::Ptr<DescriptorExtractor> extractor = xfeatures2d::BriefDescriptorExtractor::create();