在 Ubuntu 中下载 OpenCV 时出错

Errors with Downloading OpenCV in Ubuntu

我一直在按照这些说明下载 OpenCV 3.1.0:

http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/

然而,在 运行 执行 make -j4 命令后,代码处理到 14%,输出看起来像这样,给出了一个错误,表明存在 math.h 致命错误。 .

[  0%] Built target opencv_hal_pch_dephelp
[  0%] Built target opencv_core_pch_dephelp
[  0%] Built target opencv_test_core_pch_dephelp
[  0%] Built target opencv_perf_core_pch_dephelp
[  0%] Built target opencv_imgproc_pch_dephelp
[  0%] Built target opencv_highgui_pch_dephelp
[  0%] Built target opencv_videoio_pch_dephelp
[  0%] Built target pch_Generate_opencv_test_core
[  0%] Built target opencv_imgcodecs_pch_dephelp
[  0%] Built target opencv_ts_pch_dephelp
[  0%] Built target pch_Generate_opencv_perf_core
[  0%] Built target opencv_test_flann_pch_dephelp
[  0%] Built target opencv_flann_pch_dephelp
[  0%] Built target opencv_test_imgproc_pch_dephelp
[  0%] Built target opencv_ml_pch_dephelp
[  0%] Built target opencv_perf_imgproc_pch_dephelp
[  0%] Built target opencv_photo_pch_dephelp
[  0%] Built target opencv_test_ml_pch_dephelp
[  0%] Built target opencv_test_photo_pch_dephelp
[  0%] Built target opencv_perf_photo_pch_dephelp
[  1%] Built target opencv_reg_pch_dephelp
[  1%] Built target opencv_perf_reg_pch_dephelp
[  1%] Built target opencv_test_reg_pch_dephelp
[  1%] Built target opencv_surface_matching_pch_dephelp
[  1%] Built target opencv_video_pch_dephelp
[  1%] Built target opencv_perf_video_pch_dephelp
[  2%] Built target opencv_test_viz_pch_dephelp
[  2%] Built target opencv_test_video_pch_dephelp
[  2%] Built target opencv_face_pch_dephelp
[  2%] Built target opencv_viz_pch_dephelp
[  2%] Built target opencv_perf_imgcodecs_pch_dephelp
[  2%] Built target opencv_test_imgcodecs_pch_dephelp
[  2%] Built target opencv_shape_pch_dephelp
[  2%] Built target opencv_test_shape_pch_dephelp
[  2%] Built target opencv_test_videoio_pch_dephelp
[  2%] Built target opencv_test_highgui_pch_dephelp
[  2%] Built target opencv_perf_videoio_pch_dephelp
[  3%] Built target opencv_objdetect_pch_dephelp
[  4%] Built target opencv_perf_objdetect_pch_dephelp
[  4%] Built target opencv_optflow_pch_dephelp
[  4%] Built target opencv_test_objdetect_pch_dephelp
[  4%] Built target opencv_superres_pch_dephelp
[  6%] Built target opencv_test_optflow_pch_dephelp
[  6%] Built target opencv_test_superres_pch_dephelp
[  6%] Built target opencv_tracking_pch_dephelp
[  6%] Built target opencv_perf_superres_pch_dephelp
[  6%] Built target opencv_test_tracking_pch_dephelp
[  6%] Built target opencv_perf_tracking_pch_dephelp
[  6%] Built target opencv_ximgproc_pch_dephelp
[  7%] Built target opencv_test_ximgproc_pch_dephelp
[  7%] Built target opencv_perf_ximgproc_pch_dephelp
[  7%] Built target opencv_xobjdetect_pch_dephelp
[  7%] Built target opencv_test_xphoto_pch_dephelp
[  7%] Built target opencv_bgsegm_pch_dephelp
[  7%] Built target opencv_bioinspired_pch_dephelp
[  7%] Built target opencv_test_bgsegm_pch_dephelp
[  8%] Built target opencv_test_bioinspired_pch_dephelp
[  9%] Built target opencv_perf_bioinspired_pch_dephelp
[  9%] Built target opencv_perf_features2d_pch_dephelp
[ 10%] Built target opencv_features2d_pch_dephelp
[ 10%] Built target opencv_test_features2d_pch_dephelp
Scanning dependencies of target pch_Generate_opencv_perf_features2d
[ 10%] Built target opencv_latentsvm_pch_dephelp
[ 10%] Generating perf_precomp.hpp
[ 10%] Generating perf_precomp.hpp.gch/opencv_perf_features2d_RELEASE.gch
[ 10%] Built target opencv_perf_latentsvm_pch_dephelp
[ 10%] Built target opencv_test_latentsvm_pch_dephelp
[ 10%] Built target opencv_test_line_descriptor_pch_dephelp
[ 10%] Built target opencv_line_descriptor_pch_dephelp
Scanning dependencies of target pch_Generate_opencv_test_line_descriptor
[ 10%] Generating test_precomp.hpp
[ 10%] Generating test_precomp.hpp.gch/opencv_test_line_descriptor_RELEASE.gch
[ 10%] Built target pch_Generate_opencv_perf_features2d
[ 10%] Built target opencv_perf_line_descriptor_pch_dephelp
[ 10%] Built target opencv_saliency_pch_dephelp
[ 10%] Built target opencv_text_pch_dephelp
[ 10%] Built target opencv_test_calib3d_pch_dephelp
[ 10%] Built target opencv_calib3d_pch_dephelp
[ 10%] Built target opencv_perf_calib3d_pch_dephelp
[ 10%] Built target opencv_ccalib_pch_dephelp
[ 10%] Built target opencv_rgbd_pch_dephelp
[ 10%] Built target opencv_test_rgbd_pch_dephelp
[ 10%] Built target opencv_videostab_pch_dephelp
[ 12%] Built target opencv_xfeatures2d_pch_dephelp
[ 12%] Built target pch_Generate_opencv_test_line_descriptor
[ 12%] Built target opencv_test_xfeatures2d_pch_dephelp
[ 12%] Built target opencv_perf_xfeatures2d_pch_dephelp
[ 12%] Built target opencv_test_stitching_pch_dephelp
[ 13%] Built target opencv_perf_stitching_pch_dephelp
[ 14%] Built target opencv_stitching_pch_dephelp
[ 14%] Built target pch_Generate_opencv_hal
[ 14%] Generating precomp.hpp.gch/opencv_core_RELEASE.gch
In file included from /home/sciencefair/opencv/modules/hal/include/opencv2/hal/defs.h:329:0,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core/cvdef.h:59,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core.hpp:52,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core/utility.hpp:52,
                 from /home/sciencefair/opencv/build/modules/core/precomp.hpp:49:
/usr/include/c++/6/cmath:45:23: fatal error: math.h: No such file or directory
 #include_next <math.h>
                       ^
compilation terminated.
modules/core/CMakeFiles/pch_Generate_opencv_core.dir/build.make:62: recipe for target 'modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch' failed
make[2]: *** [modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch] Error 1
CMakeFiles/Makefile2:1875: recipe for target 'modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 14%] Built target pch_Generate_opencv_highgui
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
sciencefair@sciencefair-Vir

有什么想法吗?提前致谢。

更新:我将 math.h 添加到 PATH,错误消失了。但是,现在我收到 stdlib.h 的错误。输出如下所示。

    [  0%] Built target opencv_core_pch_dephelp
[  0%] Built target opencv_imgproc_pch_dephelp
[  0%] Built target opencv_perf_core_pch_dephelp
[  0%] Built target opencv_imgcodecs_pch_dephelp
[  0%] Built target opencv_test_core_pch_dephelp
[  0%] Built target opencv_videoio_pch_dephelp
[  0%] Built target opencv_ts_pch_dephelp
[  1%] Built target opencv_highgui_pch_dephelp
[  1%] Built target pch_Generate_opencv_perf_core
[  1%] Built target opencv_test_flann_pch_dephelp
[  1%] Built target opencv_flann_pch_dephelp
[  1%] Built target opencv_hdf_pch_dephelp
[  1%] Built target opencv_test_imgproc_pch_dephelp
[  1%] Built target opencv_test_ml_pch_dephelp
[  1%] Built target opencv_perf_imgproc_pch_dephelp
[  1%] Built target opencv_ml_pch_dephelp
[  1%] Built target opencv_perf_photo_pch_dephelp
[  1%] Built target opencv_photo_pch_dephelp
[  1%] Built target opencv_test_photo_pch_dephelp
[  1%] Built target opencv_reg_pch_dephelp
[  2%] Built target opencv_test_reg_pch_dephelp
[  2%] Built target opencv_perf_reg_pch_dephelp
[  2%] Built target opencv_surface_matching_pch_dephelp
[  2%] Built target opencv_video_pch_dephelp
[  2%] Built target opencv_test_video_pch_dephelp
[  2%] Built target opencv_perf_video_pch_dephelp
[  2%] Built target opencv_test_viz_pch_dephelp
[  2%] Built target opencv_viz_pch_dephelp
[  2%] Built target opencv_dnn_pch_dephelp
[  2%] Built target opencv_test_dnn_pch_dephelp
[  3%] Built target libprotobuf
[  3%] Built target opencv_fuzzy_pch_dephelp
[  3%] Built target opencv_test_imgcodecs_pch_dephelp
[  3%] Built target opencv_test_fuzzy_pch_dephelp
[  3%] Built target opencv_perf_imgcodecs_pch_dephelp
[  3%] Built target opencv_test_shape_pch_dephelp
[  3%] Built target opencv_shape_pch_dephelp
[  3%] Built target opencv_test_videoio_pch_dephelp
[  3%] Built target opencv_perf_objdetect_pch_dephelp
[  3%] Built target opencv_test_objdetect_pch_dephelp
[  3%] Built target opencv_test_highgui_pch_dephelp
[  3%] Built target opencv_perf_videoio_pch_dephelp
[  3%] Built target opencv_objdetect_pch_dephelp
[  3%] Built target opencv_test_superres_pch_dephelp
[  3%] Built target opencv_superres_pch_dephelp
[  5%] Built target opencv_plot_pch_dephelp
[  5%] Built target opencv_perf_superres_pch_dephelp
[  5%] Built target opencv_xobjdetect_pch_dephelp
[  5%] Built target opencv_test_xphoto_pch_dephelp
[  5%] Built target opencv_perf_xphoto_pch_dephelp
[  5%] Built target opencv_bgsegm_pch_dephelp
[  5%] Built target opencv_test_bioinspired_pch_dephelp
[  5%] Built target opencv_bioinspired_pch_dephelp
[  5%] Built target opencv_test_bgsegm_pch_dephelp
[  6%] Built target opencv_perf_bioinspired_pch_dephelp
[  6%] Built target opencv_dpm_pch_dephelp
[  7%] Built target opencv_face_pch_dephelp
[  8%] Built target opencv_features2d_pch_dephelp
[ 10%] Built target opencv_perf_features2d_pch_dephelp
[ 10%] Built target opencv_test_features2d_pch_dephelp
[ 10%] Built target opencv_test_line_descriptor_pch_dephelp
[ 10%] Built target opencv_line_descriptor_pch_dephelp
[ 10%] Built target opencv_perf_line_descriptor_pch_dephelp
[ 10%] Built target opencv_calib3d_pch_dephelp
[ 11%] Built target opencv_saliency_pch_dephelp
[ 12%] Built target opencv_text_pch_dephelp
[ 12%] Built target opencv_ccalib_pch_dephelp
[ 12%] Built target opencv_test_calib3d_pch_dephelp
[ 12%] Built target opencv_perf_calib3d_pch_dephelp
[ 13%] Built target opencv_rgbd_pch_dephelp
[ 13%] Built target opencv_test_rgbd_pch_dephelp
[ 15%] Built target opencv_perf_stereo_pch_dephelp
[ 16%] Built target opencv_stereo_pch_dephelp
[ 16%] Built target opencv_structured_light_pch_dephelp
[ 16%] Built target opencv_test_stereo_pch_dephelp
[ 16%] Built target opencv_test_structured_light_pch_dephelp
[ 16%] Built target opencv_tracking_pch_dephelp
[ 16%] Built target opencv_perf_tracking_pch_dephelp
[ 16%] Built target opencv_test_tracking_pch_dephelp
[ 16%] Built target opencv_videostab_pch_dephelp
[ 16%] Built target opencv_perf_xfeatures2d_pch_dephelp
[ 16%] Built target opencv_perf_ximgproc_pch_dephelp
[ 16%] Built target opencv_xfeatures2d_pch_dephelp
[ 16%] Built target opencv_test_ximgproc_pch_dephelp
[ 16%] Built target opencv_test_xfeatures2d_pch_dephelp
[ 16%] Built target opencv_ximgproc_pch_dephelp
[ 16%] Built target opencv_test_aruco_pch_dephelp
[ 17%] Built target opencv_aruco_pch_dephelp
[ 17%] Built target opencv_optflow_pch_dephelp
[ 17%] Built target opencv_test_optflow_pch_dephelp
[ 17%] Built target opencv_stitching_pch_dephelp
[ 17%] Built target opencv_test_stitching_pch_dephelp
[ 17%] Built target opencv_perf_stitching_pch_dephelp
[ 17%] Generating precomp.hpp.gch/opencv_core_RELEASE.gch
Scanning dependencies of target pch_Generate_opencv_imgproc
Scanning dependencies of target pch_Generate_opencv_imgcodecs
[ 17%] Generating precomp.hpp
[ 17%] Built target pch_Generate_opencv_test_core
[ 17%] Generating precomp.hpp
Scanning dependencies of target pch_Generate_opencv_videoio
[ 17%] Generating precomp.hpp.gch/opencv_imgcodecs_RELEASE.gch
In file included from /usr/include/c++/6/bits/stl_algo.h:59:0,
                 from /usr/include/c++/6/algorithm:62,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core/base.hpp:53,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core.hpp:54,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core/utility.hpp:52,
                 from /home/sciencefair/opencv/build/modules/core/precomp.hpp:49:
/usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>
                         ^
compilation terminated.
[ 17%] Generating precomp.hpp.gch/opencv_imgproc_RELEASE.gch
modules/core/CMakeFiles/pch_Generate_opencv_core.dir/build.make:62: recipe for target 'modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch' failed
make[2]: *** [modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch] Error 1
CMakeFiles/Makefile2:1887: recipe for target 'modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 17%] Generating precomp.hpp
[ 17%] Generating precomp.hpp.gch/opencv_videoio_RELEASE.gch
In file included from /usr/include/c++/6/bits/stl_algo.h:59:0,
                 from /usr/include/c++/6/algorithm:62,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core/base.hpp:53,
                 from /home/sciencefair/opencv/modules/core/include/opencv2/core.hpp:54,
                 from /home/sciencefair/opencv/modules/imgcodecs/include/opencv2/imgcodecs.hpp:46,
                 from /home/sciencefair/opencv/build/modules/imgcodecs/precomp.hpp:45:
/usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: No such file or directory
 #include_next <stdlib.h>
                         ^
compilation terminated.
modules/imgcodecs/CMakeFiles/pch_Generate_opencv_imgcodecs.dir/build.make:62: recipe for target 'modules/imgcodecs/precomp.hpp.gch/opencv_imgcodecs_RELEASE.gch' failed
make[2]: *** [modules/imgcodecs/precomp.hpp.gch/opencv_imgcodecs_RELEASE.gch] Error 1
CMakeFiles/Makefile2:5875: recipe for target 'modules/imgcodecs/CMakeFiles/pch_Generate_opencv_imgcodecs.dir/all' failed
make[1]: *** [modules/imgcodecs/CMakeFiles/pch_Generate_opencv_imgcodecs.dir/all] Error 2
[ 17%] Built target pch_Generate_opencv_imgproc
[ 17%] Built target pch_Generate_opencv_videoio
Makefile:160: recipe for target 'all' failed
make: *** [al

l] 错误 2

有什么想法吗?谢谢!

另一项更新: 我遵循了这些说明 http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/ 他们需要 运行 他们提供的 sh 文件。然而错误继续存在 stdlib.h。我检查了很多次 stdlib.h 是一个环境变量并且 stdlib.h 存在于 usr/include 中。 sh文件如下...

    #!/bin/bash

###########################################################
#
# OpenCV 3.0.0 alpha - instalação
# http://opencv.org/
#
###########################################################

#----------------------------------------------------------
# Criando um logger para registrar a instalação
#----------------------------------------------------------
# Tempo: início
dateformat="+%a %b %-eth %Y %I:%M:%S %p %Z"
starttime=$(date "$dateformat")
starttimesec=$(date +%s)

# Pega o diretório atual
curdir=$(cd `dirname [=13=]` && pwd)

# Cria o arquivo onde as ações ficarão registradas
logfile="$curdir/install-opencv.log"
rm -f $logfile

# Logger simples
log(){
    timestamp=$(date +"%Y-%m-%d %k:%M:%S")
    echo "\n$timestamp "
    echo "$timestamp " >> $logfile 2>&1
}

# Iniciando a instalação do OpenCV 3.0.0
log "Iniciando a instalação do OpenCV 3.0.0"


#----------------------------------------------------------
# Assegurando um ambiente atualizado
#----------------------------------------------------------

# Informa ao usuário a próxima ação
log "Executando apt-get update e apt-get upgrade"

# Executa a ação
sudo apt-get update
sudo apt-get upgrade


#----------------------------------------------------------
# Instalando os pacotes das dependências
#----------------------------------------------------------

log "Instalando as dependências"

# Executa a ação
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip


#----------------------------------------------------------
# Instalando OpenCV
#----------------------------------------------------------

log "Baixando a biblioteca OpenCV 3.0.0"

# Definição de constante
FOLDER_NAME="opencv"

# Cria um novo diretório para armazenar o código-fonte
mkdir ${FOLDER_NAME}

# Entra no diretório
cd ${FOLDER_NAME}

# Baixa o código-fonte
wget https://github.com/Itseez/opencv/archive/3.0.0-alpha.zip -O opencv-3.0.0-alpha.zip

# Extrai o conteúdo
unzip opencv-3.0.0-alpha.zip

log "Instalando a biblioteca OpenCV 3.0.0"

# Entra no diretório
cd opencv-3.0.0-alpha

# Cria um diretório chamado 'build'
mkdir build

# Entra no diretório
cd build

# Constrói o projeto usando CMake
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

# Compila o projeto
make -j $(nproc)

# Instala as bibliotecas na pasta apropriada
sudo make install

# Adiciona o caminho das bibliotecas do OpenCV aos caminhos de pesquisa de biblioteca padrão do Ubuntu
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'

# Atualiza os caminhos de pesquisa de biblioteca padrão do Ubuntu
sudo ldconfig

# Informa ao usuário que o OpenCV foi instalado com sucesso!
log "OpenCV 3.0.0 foi instalado com sucesso!"

#----------------------------------------------------------
# Mostra tempo gasto com a instalação
#----------------------------------------------------------

# Tempo: fim
endtime=$(date "$dateformat")
endtimesec=$(date +%s)

# Mostra tempo gasto com a instalação
elapsedtimesec=$(expr $endtimesec - $starttimesec)
ds=$((elapsedtimesec % 60))
dm=$(((elapsedtimesec / 60) % 60))
dh=$((elapsedtimesec / 3600))
displaytime=$(printf "%02d:%02d:%02d" $dh $dm $ds)
log "Tempo gasto: $displaytime\n"

问题是缺少 math.h 文件。 make 目标需要 cmath 文件,其中包含 math.hcmath 中的第 45 行)文件。通常,您会在 /usr/include/math.h 中找到 math.h

如果它在那里,那么只是为了让它工作,您可以在 $PATH 环境变量中添加 /usr/include 目录。可以上网搜索在$PATH添加目录也可以查看here.

如果不是,那么您需要在系统中找到该文件并将其路径提供给 make 目标。

好吧,这是一个漫长的解决方案...似乎向 PATH 添加变量不是问题所在。问题出在 G++ 和 GCC 版本 6 上。因此,在将 gcc 和 g++ 重定向到 gcc 和 g++ 版本 5 之后,一切正常。