最近在Linux下配置交叉编辑环境,安装Qt、ffmpeg,编译安装OpenCV各种版本,各种郁闷,终于都搞定了,趁着热乎着,赶紧吐槽一下!
好了,言归正传。
1. 关于交叉编译环境的配置,Qt与qtcreator的安装有很多博客已经详细讲解了,这里就不作为重点了,列出几个链接:
1)交叉编译环境——arm-xilinx-linux-gnueabi-
参考rainysky博客 http://www.eefocus.com/sj229335457/blog/13-06/294577_b3da0.html
2)安装Qt和qtcreator
参考emouse博客 http://www.cnblogs.com/emouse/archive/2013/01/28/2880142.html
不过,Qt 5.0及以上版本已经集成了qtcreator,即不用在单独安装qtcreator了。
(*) 友情提示一下:
若重新安装qtcreator,当打开或者关闭时,会提示无法覆盖文件 /home/your_name/.config/QtProject/qtversion.xml: Permission denied
正解:终端下输入:sudo chown -R your_name:your_name .config/
2.安装ffmpeg ——用于视频、音频方面
1)起初安装opencv时,没有安装ffmpeg,当调用opencv的视频处理函数时,读取视频失败。
2)安装ffmpeg,参考guo8113博客 http://blog.csdn.net/guo8113/article/details/33757761
3)当文件配置 ./configure 时,出现如下bug:
libavcodec/x86/h264_qpel_mmx.c: Assembler messages:
libavcodec/x86/h264_qpel_mmx.c:1294: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:1294: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:1298: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:1298: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for `cmp'
make[5]: *** [libavcodec/x86/dsputil_mmx.o] Error 1
解决方案:
将目录下~/ffmpeg/libavcodec/x86/h264_qpel_mmx.c的h264_qpel_mmx.c文件中的"g"替换为"rm"
[ http://permalink.gmane.org/gmane.comp.handhelds.openembedded/51954 ]
3.编译安装opencv-2.4.10
1) Cmake安装——终端输入:sudo apt-get install cmake 即可
2) 安装libgtk2.0-dev 和 pkg-config——终端输入:sudo apt-get install libgtk2.0-dev pkg-config
3) 下载opencv-2.4.10,见 http://sourceforge.net/projects/opencvlibrary/files/
4) 编译过程,库的配置,以及环境变量的设置,参考emouse博客 http://www.cnblogs.com/emouse/archive/2013/02/22/2922940.html 和 guo8113博客 http://blog.csdn.net/guo8113/article/details/29211041
特别说明一下,当文件编译 make时,出现如下2个bug:
(1) ~/opencv-2.4.10/modules/core/src/system.cpp:280:10: error: inconsistent operand constraints in an 'asm'
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make:*** [all] Error 2
解决方案:
[ http://www.yyearth.com/article/13-12/opencv.html ]
此时打开opencv-2.4.10/modules/core/src/system.cpp文件,定位到270行-280行(即:asm volation(...)); 利用如下内容替换:
- // We need to preserve ebx since we are compiling PIC code.
- // This means we cannot use "=b" for the 2nd output register.
- asm volatile
- (
- "pushl %%ebx\n\t"
- "movl $7,%%eax\n\t"
- "movl $0,%%ecx\n\t"
- "cpuid\n\t"
- "movl %%ebx,%1\n\t"
- "popl %%ebx\n\t"
- : "=a"(cpuid_data[0]), "=r"(cpuid_data[1]), "=c"(cpuid_data[2]), "=d"(cpuid_data[3])
- :
- : "cc"
- );
(2) ~/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp:1446:29:error: 'avformat_free_context' was not declared in this scope avformat_free_context(oc);
make[2]: *** [modules/core/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg_impl.o] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_highgui.dir/all] Error 2
make:*** [all] Error 2
解决方案:
方法一:
[ http://answers.opencv.org/question/32801/unresoved-avformat_free_context-was-not-declared-in-this-scope/ ]
打开opencv-2.4.9/modules/highgui/src/cap_ffmpeg_impl.hpp文件,定位到1445行,将其替换为
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0) avformat_free_context(oc);
#else av_free_format_context(oc);
#endif
方法二:
[http://sourceforge.net/p/emgucv/opencv/ci/emgucv_2.4.10/tree/modules/highgui/src/cap_ffmpeg_impl.hpp ]
直接在以上网站下载该文档,将原来的替换掉!