温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

OpenCV2.4.9版本编译

发布时间:2020-03-04 22:50:42 来源:网络 阅读:749 作者:fengyuzaitu 栏目:软件技术

1)linux查看opencv安装路径及版本号
查看linux下的opencv安装库:
pkg-config opencv --libs
查看linux下的opencv安装版本:
pkg-config opencv --modversion
查看linux下的opencv安装路径:
find / -iname "*opencv*"



2)编译指令

创建库目录:    mkdir install

创建生成目录 :   mkdir build

进入目录: cd build

执行生成Makefile:


cmake -D WITH_CUDA=OFF \
            -D CMAKE_BUILD_TYPE=Release \
            -D CMAKE_INSTALL_PREFIX=cmake -D WITH_CUDA=OFF \
            -D CMAKE_BUILD_TYPE=Release \
            -D CMAKE_INSTALL_PREFIX=/home/packages/opencv/install \
            -D WITH_IPP=OFF \
            -D WITH_FFMPEG=ON  \
            -D BUILD_TESTS=OFF \
            -D BUILD_PERF_TESTS=OFF \
            -D INSTALL_PYTHON_EXAMPLES=OFF \
            -D INSTALL_C_EXAMPLES=OFF \
            -D PYTHON_EXECUTABLE=$(which python) \
            -D BUILD_EXAMPLES=OFF .. \
            -D WITH_IPP=OFF \
            -D WITH_FFMPEG=ON  \
            -D BUILD_TESTS=OFF \
            -D BUILD_PERF_TESTS=OFF \
            -D INSTALL_PYTHON_EXAMPLES=OFF \
            -D INSTALL_C_EXAMPLES=OFF \
            -D PYTHON_EXECUTABLE=$(which python) \
            -D BUILD_EXAMPLES=OFF ..


生成安装:make && make install


编译异常

1)[ 98%] Linking CXX executable ../../bin/opencv_performance
../../lib/libopencv_highgui.so.2.4.9: undefined reference to `avcodec_alloc_frame'
../../lib/libopencv_highgui.so.2.4.9: undefined reference to `avcodec_encode_video'
collect2: error: ld returned 1 exit status
apps/haartraining/CMakeFiles/opencv_performance.dir/build.make:105: recipe for target 'bin/opencv_performance' failed
make[2]: *** [bin/opencv_performance] Error 1
CMakeFiles/Makefile2:3388: recipe for target 'apps/haartraining/CMakeFiles/opencv_performance.dir/all' failed
make[1]: *** [apps/haartraining/CMakeFiles/opencv_performance.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

问题:undefined reference to `avcodec_alloc_frame'

通过grep -r "avcodec_alloc_frame"  / 查询全局文本返回空

最新版本的FFmpeg该函数的实现名称已经改变,下载ffmpeg-2.3.tar.bz2源码编译

2)已经编译ffmpeg-2.3.tar.bz2,生成libswresample.so.0无法找到,将libswresample.so.0拷贝到/lib64目录下

/usr/bin/ld: warning: libswresample.so.0, needed by //home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55, not found (try using -rpath or -rpath-link)
//home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_init@LIBSWRESAMPLE_0'
//home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_close@LIBSWRESAMPLE_0'
//home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_is_initialized@LIBSWRESAMPLE_0'
//home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_free@LIBSWRESAMPLE_0'
//home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_alloc@LIBSWRESAMPLE_0'
//home/dong/ffmpeg/ffmpeg-2.3/build/lib/libavcodec.so.55: undefined reference to `swr_convert@LIBSWRESAMPLE_0'
collect2: error: ld returned 1 exit status
apps/haartraining/CMakeFiles/opencv_performance.dir/build.make:105: recipe for target 'bin/opencv_performance' failed
make[2]: *** [bin/opencv_performance] Error 1
CMakeFiles/Makefile2:3388: recipe for target 'apps/haartraining/CMakeFiles/opencv_performance.dir/all' failed
make[1]: *** [apps/haartraining/CMakeFiles/opencv_performance.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error

3)export PKG_CONFIG_PATH=/home/dong/opencv-2.4.9/install/lib/pkgconfig/;$PKG_CONFIG_PATH

指定OpenCV优先查找编译好的FFmpeg,而不是系统的FFmpeg库

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI