概述
问题1:dlib的C++接口编译
(1) 下载解压
tar -jxvf dlib-19.7.tar.bz2
cd dlib-19.7/dlib
mkdir build
cd build/
dlib目录是dlib本身所有的C++源代码目录,另外examples代码需要单独编译即可.
(2) 编译源码并安装
树莓派没有gpu,所以把dlib/CMakelists.txt中的选择项关闭了
cmake -DCMAKE_INSTALL_PREFIX=/yourpath/dlib ..
make
make install
(3) 安装后头文件和库文件路径
/usr/local/include
/usr/local/lib
(4) 在自己的项目中链接dlib库,下面是个实例作为参考
Tips:自己的项目老是提示找不到cblas的问题, undefined reference to symbol 'cblas',find查找本机也有,只好在最后连接的时候指定全路径了
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_STANDARD 17)
project(my_demo)
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
find_package(OpenCV REQUIRED)
find_package(Vulkan REQUIRED)
message(STATUS "Vulkan FOUND = ${Vulkan_FOUND}")
message(STATUS "Vulkan Include = ${Vulkan_INCLUDE_DIRS}")
message(STATUS "Vulkan Lib = ${Vulkan_LIBRARY}")
find_package(Vulkan REQUIRED)
set(NCNN_LIBS /home/pi/Downloads/ncnn/build/install/lib)
set(NCNN_INCLUDE_DIRS /home/pi/Downloads/ncnn/build/install/include)
set(DLIBD_LIBS /usr/local/lib)
set(DLIBD_INCLUDE_DIRS /usr/local/include)
include_directories(
${Vulkan_INCLUDE_DIRS}
${NCNN_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${DLIBD_INCLUDE_DIRS}
)
link_directories(
${NCNN_LIBS}
${DLIBD_LIBS}
)
add_executable(ultradet_demo main.cpp UltraFace.cpp facereg.cpp)
target_link_libraries(
ultradet_demo
ncnn.a
libdlib.a
/usr/lib/arm-linux-gnueabihf/blas/libblas.so
/usr/lib/arm-linux-gnueabihf/lapack/liblapack.so
#ncnn.lib
#glslang.lib
#OGLCompiler.lib
#OSDependent.lib
#SPIRV.lib
${Vulkan_LIBRARY}
${OpenCV_LIBS}
)
问题2:安装opencv2.4.13【老版本真是一堆问题,僵硬】
拿到的respberry已经被他人安装了opencv2【具体版本不详】,但自己项目中需要的是含有contrib的包,所以自己重新安装一下opencv2.4.13.
(1) 下载解压
unzip 2.4.13.zip
cd opencv-2.4.13
mkdir build
cd build/
(2) 编译
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/ -DENABLE_PRECOMPILED_HEADERS=OFF -DWITH_FFMPEG=1 -D INSTALL_C_EXAMPLES=OFF ..
make -j4
make install
(3)fatal error: linux/videodev.h: No such file or directory
sudo apt-get install libv4l-dev
sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h
(4)fatal error: linux/videodev.h: No such file or directory
参考:添加编译选项 -D WITH_LIBV4L=ON -D WITH_V4L=OFF 或者 -D INSTALL_C_EXAMPLES=OFF
https://stackoverflow.com/questions/39439783/error-sys-videoio-h-not-found-opencv-3-1-0
https://github.com/opencv/opencv/issues/6262
使用 -D WITH_LIBV4L=ON -D WITH_V4L=OFF选项,好像videoCapture()是打不开摄像头的,真是坑。所以使用: -D INSTALL_C_EXAMPLES=OFF
(5)fatal error: ffmpeg/avformat.h: No such file or directory
参考:使用find查找树莓派中libavcodec的位置
https://raspberrypi.stackexchange.com/questions/42283/cant-compile-opencv-3-1-on-raspberry-pi-missing-videoio-h-videodev-h
find / -name "libavcodec*"
/usr/share/doc/libavcodec58
/usr/share/doc/libavcodec-dev
/usr/share/lintian/overrides/libavcodec58
/usr/lib/arm-linux-gnueabihf/neon/vfp/libavcodec.so.58
/usr/lib/arm-linux-gnueabihf/neon/vfp/libavcodec.a
/usr/lib/arm-linux-gnueabihf/neon/vfp/libavcodec.so
/usr/lib/arm-linux-gnueabihf/neon/vfp/libavcodec.so.58.35.100
/usr/lib/arm-linux-gnueabihf/libavcodec.so.58
/usr/lib/arm-linux-gnueabihf/libavcodec.a
/usr/lib/arm-linux-gnueabihf/libavcodec.so
/usr/lib/arm-linux-gnueabihf/libavcodec.so.58.35.100
/usr/lib/arm-linux-gnueabihf/pkgconfig/libavcodec.pc
/usr/lib/arm-linux-gnueabihf/vlc/plugins/codec/libavcodec_plugin.so
/usr/include/arm-linux-gnueabihf/libavcodec
/var/lib/dpkg/info/libavcodec-dev:armhf.md5sums
/var/lib/dpkg/info/libavcodec58:armhf.md5sums
/var/lib/dpkg/info/libavcodec58:armhf.symbols
/var/lib/dpkg/info/libavcodec58:armhf.list
/var/lib/dpkg/info/libavcodec-dev:armhf.list
/var/lib/dpkg/info/libavcodec58:armhf.triggers
/var/lib/dpkg/info/libavcodec58:armhf.shlibs
/var/cache/apt/archives/libavcodec58_7%3a4.1.3-1+rpt1_armhf.deb
/var/cache/apt/archives/libavcodec58_7%3a4.1.6-1~deb10u1+rpt1_armhf.deb
/var/cache/apt/archives/libavcodec-dev_7%3a4.1.6-1~deb10u1+rpt1_armhf.deb
/var/cache/apt/archives/libavcodec-dev_7%3a4.1.4-1+rpt7~deb10u1_armhf.deb
/var/cache/apt/archives/libavcodec58_7%3a4.1.4-1+rpt7~deb10u1_armhf.deb
/var/cache/apt/archives/libavcodec-dev_7%3a4.1.3-1+rpt1_armhf.deb
/home/pi/Downloads/opencv-2.4.13/3rdparty/lib/libavcodec64.a
/home/pi/Downloads/opencv-2.4.13/3rdparty/lib/libavcodec.a
/home/pi/Downloads/opencv-2.4.13/3rdparty/include/ffmpeg_/libavcodec
find / -name "ffmpeg"
/usr/bin/ffmpeg
/usr/share/doc/ffmpeg
/usr/share/lintian/overrides/ffmpeg
/usr/share/ffmpeg
/home/pi/Downloads/opencv-2.4.13/3rdparty/ffmpeg
重新软连接
sudo mkdir /usr/include/ffmpeg
sudo ln -sf /usr/include/libavcodec/*.h /usr/include/ffmpeg
sudo ln -sf /usr/include/libavformat/*.h /usr/include/ffmpeg
sudo ln -sf /usr/include/libswscale/*.h /usr/include/ffmpeg
(6)CMake Warning at cmake/OpenCVPackaging.cmake:23 (message): CPACK_PACKAGE_VERSION does not match version provided by version.hpp
参考:https://blog.csdn.net/pragma_g/article/details/79553042
打开CMakeList.txt文件,查找到 OPENCV_VCSVERSION
# 修改前
if(NOT GIT_RESULT EQUAL 0)
set(OPENCV_VCSVERSION "unknow")
endif()
else()
# We don't have git:
set(OPENCV_VCSVERSION "unknow")
# 将 unknow 替换为自己的 opencv 版本
if(NOT GIT_RESULT EQUAL 0)
set(OPENCV_VCSVERSION "2.4.13")
endif()
else()
# We don't have git:
set(OPENCV_VCSVERSION "2.4.13")
(8)CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:89 (math): math cannot parse the expression: "*100 + ": syntax error, unexpected exp_TIMES, expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER
参考:
https://answers.opencv.org/question/65548/cmake-error-at-cmakeopencvdetectcxxcompilercmake/
https://github.com/opencv/opencv/pull/9430/files
原因:explanation is that in gcc with higher version, dumpversion function can't get true full version number of compiler so that cmake progress will fail.
解决:按照上面的链接中添加对应的代码即可
(8)/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
参考:
https://blog.csdn.net/Stackingrule/article/details/90146828
https://blog.csdn.net/u010003609/article/details/100086151
原因:
这是由于gcc7已经吧stdlib.h纳入了libstdc++以进行更好的优化,C Library的头文件stdlib.h使用 Include_next,而include_next对gcc系统头文件路径很敏感。
推荐的修复方法是不要把include路径作为系统目录,而是使用标准方式包含include 目录
解决:
在编译opecv时,加入如下选项:
-DENABLE_PRECOMPILED_HEADERS=OFF
ok,一步一个坑,再从头开始cmake... come on baby
(9)/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
参考:
https://blog.csdn.net/goodxin_ie/article/details/82856008
原因:由ffmpeg的版本问题引起。在最新版本的ffmpeg中对很多关键字进行了重命名.
在 opencv-2.4.13/modules/highgui/src/cap_ffmpeg_impl.hpp 里最顶端添加:
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020
其他由ffmpeg版本引起的错误处理方法类似,找到报错的宏对应的定义,将其复制到出错的源码文件头
(9)raspberry使用usb摄像头,调用opencv的videocapture失败
方向:
1: 查看 WITH_LIBV4L=ON WITH_V4L=ON编译选项是否打开,具体可参考问题(4);
2:检查raspberry是否识别到了插入的摄像头,
ls -ltr /dev/video*
如果有video0一般是识别到了,如果没有,找到下列文件:/etc/modules-load.d/modules.conf
vim /etc/modules-load.d/modules.conf
在末尾添加一行记录:bcm2835-v4l2 【注意是字母“l”不是数字“1”】
bcm2835-v4l2
然后重启raspberry
reboot
重启后,一般就可以了,不行的话再试试下面的语句进行模块载入
sudo modprobe bcm2835-v4l2
最后
以上就是发嗲石头为你收集整理的树莓派-环境配置-问题记录的全部内容,希望文章能够帮你解决树莓派-环境配置-问题记录所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复