c++ - opencv中acos函数错误

标签 c++ linux opencv

我正在编写代码,通过在 OPENCV 中使用 SURF 从 2 张图像中提取特征及其描述符。描述符用于匹配两个图像的特征。为了计算最佳匹配,我计算了点积并找到了两个特征描述符矩阵之间的角度。我在 acos 功能上遇到错误。我在下面添加了代码和错误..

谁能指出程序中的错误。

int main( int argc, char** argv )
{
      //-- Step 1: Detect the keypoints using SURF Detector
      int minHessian = 400;

      SurfFeatureDetector detector( minHessian,1,3,false,true );

      std::vector<KeyPoint> keypoints_1, keypoints_2;

      detector.detect( img_1, keypoints_1 );
      detector.detect( img_2, keypoints_2 );


      // computing descriptors
      SurfDescriptorExtractor extractor(minHessian,1,1,1,0);
      Mat descriptors1, descriptors2;
      extractor.compute(img_1, keypoints_1, descriptors1);
      extractor.compute(img_2, keypoints_2, descriptors2);

      std::cout << descriptors1.rows << std::endl;
      std::cout << descriptors1.cols << std::endl;
      std::cout << descriptors2.rows << std::endl;
      std::cout << descriptors2.cols << std::endl;

      Mat a;
      Mat b(descriptors2.rows,descriptors2.cols, CV_32F);
      a=descriptors1;
      b=descriptors2;

      Mat m;  
      if(((descriptors2.rows)||(descriptors1.rows))==0)
      {
               m.push_back(0);
               return 0;
      }

      Mat des2t;
      std::cout << des2t.rows << std::endl;
      std::cout << des2t.cols << std::endl;


      des2t= b.t();
      std::cout << des2t.rows << std::endl;
      std::cout << des2t.cols << std::endl;

      m= Mat::zeros(descriptors1.rows,1,CV_32F);


      Mat dotprod = a*des2t;
      Mat angle ;

      angle = std::acos(dotprod);

      std::cout << dotprod.rows << std::endl;
      std::cout << dotprod.cols << std::endl;

      return 0;
}

错误:

In function ‘int main(int,    char**)’:
surf.cpp:116:29: error: no matching function for call to ‘acos(cv::Mat&)’     
surf.cpp:116:29: note: candidates are:
/usr/include/i386-linux-gnu/bits/mathcalls.h:55:1: note: double acos(double)
/usr/include/i386-linux-gnu/bits/mathcalls.h:55:1: note:   no known conversion for argument 1 from ‘cv::Mat’ to ‘double’
/usr/include/c++/4.6/cmath:102:3: note: float std::acos(float)
/usr/include/c++/4.6/cmath:102:3: note:   no known conversion for argument 1 from ‘cv::Mat’ to ‘float’
/usr/include/c++/4.6/cmath:106:3: note: long double std::acos(long double)
/usr/include/c++/4.6/cmath:106:3: note:   no known conversion for argument 1 from ‘cv::Mat’ to ‘long double’
/usr/include/c++/4.6/cmath:112:5: note: template<class _Tp> typename __gnu_cxx::__enable_if<std::__is_integer<_Tp>::__value, double>::__type std::acos(_Tp)
make[2]: *** [CMakeFiles/surf.dir/surf.cpp.o] Error 1
make[1]: *** [CMakeFiles/surf.dir/all] Error 2
make: *** [all] Error 2

最佳答案

您正在尝试将 acos 应用于 cv::Mat 对象而不是 double,这是您的错误。

我从未在 OpenCV 中使用过 SURF,因此我无法评论与此相关的代码的有效性,但您应该尝试获取 Mat dotprod 的第一个元素并将其传递给 acos .

如果 dotprod 不是 1x1 矩阵,那么您的代码中可能存在一些问题。

要获取 dotprod 中 0x0 处的元素,您可以执行以下操作:

dotprod.at<double>(0,0);

请注意,double 需要替换为 dotprod 用于存储其元素的数据类型,这可能与 double 不同。

关于c++ - opencv中acos函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22679440/

相关文章:

c++ - OpenCV destroyWindow() 不执行任何操作。

python - 自定义 Python Wheel 文件的 Yocto Warrior 自定义 Bitbake 配方无法安装,因为找不到 pip3

python - 如何根据用户名更改目录?

php - 如何设置php-fpm多线程工作?

python-2.7 - python cv2.Videocapture() 不起作用,cap.isOpened() 返回 false

c++ - 等价于 Matlab 的 sum(A)?

c++ - 类似 smartassembly 的程序,但适用于 C++?

c++ - 使用单一配置而不是将 Debug 和 Release 分开(在我们的例子中)是否可以?

java - 使用Chaquopy将python中的PyObject转换为android中的多个2d数组

python - pyplot正在更改图像的颜色