"make" opencv2-4-9 in raspberry pi 3 model B v1.2 时出错

Error when i "make" opencv2-4-9 in raspberry pi 3 model B v1.2

我想在raspberry pi3 model b v1.2 2015上安装opencv2.4.9,我按照this page安装opencv。当我 "make" opencv 时,我看到这些错误:

[  1%] Built target opencv_ts_pch_dephelp
[  1%] Built target pch_Generate_opencv_ts
[  1%] Built target opencv_core_pch_dephelp
[  1%] Built target pch_Generate_opencv_core
[  3%] Built target opencv_core
[  3%] Built target opencv_imgproc_pch_dephelp
[  3%] Built target pch_Generate_opencv_imgproc
[  5%] Built target opencv_imgproc
[  6%] Built target opencv_highgui_pch_dephelp
[  6%] Built target pch_Generate_opencv_highgui
[  6%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_QT.cpp.o
In file included from /usr/include/GL/glx.h:32:0,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.cpp:59:
/usr/include/GL/gl.h:134:17: error: conflicting declaration ‘typedef double GLdouble’
 typedef double  GLdouble; /* double precision float */
                 ^
In file included from /usr/include/qt4/QtOpenGL/QtOpenGL:5:0,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.h:46,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.cpp:47:
/usr/include/qt4/QtOpenGL/qgl.h:85:17: note: previous declaration as ‘typedef GLfloat GLdouble’
 typedef GLfloat GLdouble;
                 ^
In file included from /usr/include/GL/gl.h:2055:0,
                 from /usr/include/GL/glx.h:32,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.cpp:59:
/usr/include/GL/glext.h:468:19: error: conflicting declaration ‘typedef std::ptrdiff_t GLsizeiptr’
 typedef ptrdiff_t GLsizeiptr;
                   ^
In file included from /usr/include/qt4/QtOpenGL/qgl.h:79:0,
                 from /usr/include/qt4/QtOpenGL/QtOpenGL:5,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.h:46,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.cpp:47:
/usr/include/GLES2/gl2.h:69:25: note: previous declaration as ‘typedef khronos_ssize_t GLsizeiptr’
 typedef khronos_ssize_t GLsizeiptr;
                         ^
In file included from /usr/include/GL/gl.h:2055:0,
                 from /usr/include/GL/glx.h:32,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.cpp:59:
/usr/include/GL/glext.h:469:19: error: conflicting declaration ‘typedef std::ptrdiff_t GLintptr’
 typedef ptrdiff_t GLintptr;
                   ^
In file included from /usr/include/qt4/QtOpenGL/qgl.h:79:0,
                 from /usr/include/qt4/QtOpenGL/QtOpenGL:5,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.h:46,
                 from /home/nao/Desktop/opencv-2.4.9/modules/highgui/src/window_QT.cpp:47:
/usr/include/GLES2/gl2.h:70:26: note: previous declaration as ‘typedef khronos_intptr_t GLintptr’
 typedef khronos_intptr_t GLintptr;
                          ^
modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:227: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_QT.cpp.o' failed
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_QT.cpp.o] Error 1
CMakeFiles/Makefile2:1868: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

我看到 this page 这个错误,但是当我将 OPENGL 更改为 OPENGL-ES 时没有任何变化。

我能做什么?

我遇到了同样的问题,我按照this page的步骤在raspberry中正确安装了opencv。

我是这样解决的。我是 运行 Ubuntu 16.04 LTS LXDE raspberry pi。 我不知道导致此问题的确切核心库(错误中提到的除外),因此这种方法可能有点通用。 (当所有其他方法都失败时)。

  1. 确保您拥有 opencv 和 opencv_contrib 对象的全新副本。

  2. git checkout --force 3.3.1(请通过运行 git log或在github页面检查下载中的头部位置)

  3. 创建一个构建文件夹并确保您拥有所有依赖库。这很棘手,因为其中一些是视觉的。示例包括:libgstreame1.0-base-dev.
  4. 使用 cmake CMAKE_BUILD_TYPE=RELEASE \

CMAKE_INSTALL_PREFIX=/usr/local \

INSTALL_C_EXAMPLES=ON \

INSTALL_PYTHON_EXAMPLES=ON \

WITH_TBB=ON \

WITH_V4L=ON \

WITH_QT=ON \

WITH_OPENGL=ON \

OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \

如果这不起作用,您可以在 cmake 命令后的每一行的开头添加 -D 符号。 如果你想使用cuda(如果你的显卡有合适的驱动程序),你必须通过在上面的命令中添加USE_CUDA=ON来添加一个变量。

更多帮助请参考this and this

希望对您有所帮助!

我在 raspi 3b 上遇到了与 U 相同的问题。

也许 this 会解决这个错误。

Do not include glx.h when using GLES.

GL/glx.h is included on all LINUX plattforms, which is wrong for a number of reasons:

  • GL_PERSPECTIVE_CORRECTION_HINT is defined in GL/gl.h, so we want gl.h not glx.h, the latter just includes the former.
  • GL/gl.h is a Desktop GL header, and should not be included on GLES plattforms.
  • GL/gl.h is already included via QtOpenGL -> QtGui/qopengl.h on desktop plattforms.
  • This fixes a problem when Qt is compiled with GLES, which is often done on ARM platforms where desktop GL is not or only poorly supported (e.g. slow due to emulation).
//modules/highgui/src/window_QT.cpp::54
#include <unistd.h>
#endif

//Get GL_PERSPECTIVE_CORRECTION_HINT definition, not available in GLES 2 or
//OpenGL 3 core profile or later
#ifdef HAVE_QT_OPENGL
//    #if defined Q_WS_X11 /* Qt4 */ || defined Q_OS_LINUX /* Qt5 */
//        #include <GL/glx.h>
    #if defined Q_WS_X11 /* Qt4 */ || \
            (!defined(QT_OPENGL_ES_2) && defined Q_OS_LINUX) /* Qt5 with desktop OpenGL */
        #include <GL/gl.h>
    #endif
#endif
    
//modules/highgui/src/window_QT.cpp::3226
//void OpenGlViewPort::updateGl()

void OpenGlViewPort::initializeGL() {
#ifdef GL_PERSPECTIVE_CORRECTION_HINT
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
#endif
}

void OpenGlViewPort::resizeGL(int w, int h)