为Mac OS X构建OpenCV 3时出错

时间:2015-09-02 23:02:43

标签: python macos opencv

我正在尝试为Mac OS X构建OpenCV 3.我按照http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/

的说明进行操作

我得到以下输出:

...
[ 50%] Linking CXX executable ../../bin/opencv_test_latentsvm
[ 50%] Built target opencv_test_latentsvm
[ 50%] Building CXX object modules/features2d/CMakeFiles/opencv_perf_features2d.dir/perf/perf_main.cpp.o
[ 50%] Building CXX object modules/line_descriptor/CMakeFiles/opencv_line_descriptor.dir/src/binary_descriptor_matcher.cpp.o
[ 50%] Building CXX object modules/features2d/CMakeFiles/opencv_test_features2d.dir/test/test_keypoints.cpp.o
[ 50%] Building CXX object modules/features2d/CMakeFiles/opencv_perf_features2d.dir/perf/perf_orb.cpp.o
Scanning dependencies of target opencv_saliency
[ 50%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/BING/CmFile.cpp.o
[ 50%] Building CXX object modules/line_descriptor/CMakeFiles/opencv_line_descriptor.dir/src/draw.cpp.o
[ 50%] Building CXX object modules/features2d/CMakeFiles/opencv_test_features2d.dir/test/test_main.cpp.o
[ 50%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/BING/CmShow.cpp.o
[ 50%] Building CXX object modules/line_descriptor/CMakeFiles/opencv_line_descriptor.dir/src/LSDDetector.cpp.o
[ 50%] Linking CXX executable ../../bin/opencv_perf_features2d
[ 50%] Built target opencv_perf_features2d
[ 50%] Building CXX object modules/features2d/CMakeFiles/opencv_test_features2d.dir/test/test_matchers_algorithmic.cpp.o
[ 50%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/BING/FilterTIG.cpp.o
Scanning dependencies of target opencv_text
[ 50%] Building CXX object modules/text/CMakeFiles/opencv_text.dir/src/erfilter.cpp.o
/Users/samadwara/opencv_contrib/modules/line_descriptor/src/LSDDetector.cpp:182:37: error: call to 'pow' is ambiguous
      kl.lineLength = (float) sqrt( pow( extremes[0] - extremes[2], 2 ) + pow( extremes[1] - extremes[3], 2 ) );
                                    ^~~
/usr/include/c++/4.2.1/cmath:364:3: note: candidate function
  pow(double __x, int __i)
  ^
/usr/include/c++/4.2.1/cmath:368:3: note: candidate function
  pow(float __x, int __n)
  ^
/usr/include/c++/4.2.1/cmath:372:3: note: candidate function
  pow(long double __x, int __n)
  ^
/usr/include/math.h:436:15: note: candidate function
extern double pow(double, double);
              ^
/usr/include/c++/4.2.1/cmath:356:3: note: candidate function
  pow(float __x, float __y)
  ^
/usr/include/c++/4.2.1/cmath:360:3: note: candidate function
  pow(long double __x, long double __y)
  ^
/Users/samadwara/opencv_contrib/modules/line_descriptor/src/LSDDetector.cpp:182:75: error: call to 'pow' is ambiguous
      kl.lineLength = (float) sqrt( pow( extremes[0] - extremes[2], 2 ) + pow( extremes[1] - extremes[3], 2 ) );
                                                                          ^~~
/usr/include/c++/4.2.1/cmath:364:3: note: candidate function
  pow(double __x, int __i)
  ^
/usr/include/c++/4.2.1/cmath:368:3: note: candidate function
  pow(float __x, int __n)
  ^
/usr/include/c++/4.2.1/cmath:372:3: note: candidate function
  pow(long double __x, int __n)
  ^
/usr/include/math.h:436:15: note: candidate function
extern double pow(double, double);
              ^
/usr/include/c++/4.2.1/cmath:356:3: note: candidate function
  pow(float __x, float __y)
  ^
/usr/include/c++/4.2.1/cmath:360:3: note: candidate function
  pow(long double __x, long double __y)
  ^
2 errors generated.
make[2]: *** [modules/line_descriptor/CMakeFiles/opencv_line_descriptor.dir/src/LSDDetector.cpp.o] Error 1
make[1]: *** [modules/line_descriptor/CMakeFiles/opencv_line_descriptor.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 50%] Building CXX object modules/features2d/CMakeFiles/opencv_test_features2d.dir/test/test_mser.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/BING/objectnessBING.cpp.o
[ 51%] Building CXX object modules/text/CMakeFiles/opencv_text.dir/src/ocr_hmm_decoder.cpp.o
[ 51%] Building CXX object modules/features2d/CMakeFiles/opencv_test_features2d.dir/test/test_nearestneighbors.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/BING/ValStructVec.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/motionSaliency.cpp.o
[ 51%] Building CXX object modules/text/CMakeFiles/opencv_text.dir/src/ocr_tesseract.cpp.o
[ 51%] Building CXX object modules/features2d/CMakeFiles/opencv_test_features2d.dir/test/test_orb.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/motionSaliencyBinWangApr2014.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/objectness.cpp.o
[ 51%] Linking CXX shared library ../../lib/libopencv_text.dylib
[ 51%] Built target opencv_text
[ 51%] Building CXX object modules/features2d/CMakeFiles/opencv_test_features2d.dir/test/test_rotation_and_scale_invariance.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/saliency.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/staticSaliency.cpp.o
[ 51%] Building CXX object modules/saliency/CMakeFiles/opencv_saliency.dir/src/staticSaliencySpectralResidual.cpp.o
[ 51%] Linking CXX shared library ../../lib/libopencv_saliency.dylib
[ 51%] Linking CXX executable ../../bin/opencv_test_features2d
[ 51%] Built target opencv_saliency
[ 51%] Built target opencv_test_features2d
make: *** [all] Error 2
 ~/opencv/build $

有关如何解决此问题的任何想法?如果所有其他方法都失败了,我将只安装一个Linux VM并使用它。

2 个答案:

答案 0 :(得分:1)

我在这个过程中遇到了同样的问题。由于某种原因,cmath版本不包括处理幂函数的整数,整数参数的方法(极值是代码那部分的整数向量)。我添加了一个新函数来处理它,我在下面包含的代码。如果在对整数,浮点或整数,双参数执行上电时继续编译,则会引发一些其他问题。对于这些,您可以使用现有的内置方法进行电源功能。

在对cmath进行调整并继续安装之后,我没有遇到任何进一步的问题。

功能的C ++代码(整数,整数),改编自维基百科上的Sponaring Exponentiation文章:

inline double 
pow(int __x, int __n)
{
    double myx = __x, myn = __n;
    if (__n<0){
        myx = 1.0/ __x;
        myn = -__n;
    } 
    if(__n==0){
        return 1; 
    }
    double myy=1;
    while(myn > 1){
       if (((int)myn)%2==0){
           myx = myx * myx;
           myn = myn / 2;
       }else{
           myy = myx * myy;
           myx = myx * myx;
           myn = (myn - 1) / 2;
       }
    }
    return myx*myy;
}

答案 1 :(得分:0)

谢谢shapiromh。由于您的解决方案,我可以解决这个问题。为此,我像下面一样修改了cmath源代码。

  inline double
  pow(int __x, int __y)
  { return __builtin_powf(__x, __y); }