1. 不同版本的ubuntu安装工具有所差异:
(1)Ubuntu14.04编译工具:sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy
sudo apt-get install libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev
(2)Ubuntu12.04编译工具:sudo apt-get install build-essential cmake
sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev
sudo apt-get install libtiff4-dev libswscale-dev libjasper-dev
2. 官网下载OpenCV任意版本源码,如:OpenCV2.4.5和OpenCV2.4.10。
3. 解压源码到用户根目录下,打开终端,输入如下命令(OpenCV2.4.5为例):cd
~/opencv2.4.5
mkdir build
cd build
cmake -D
CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
make
4. 在编译opencv2.4.5过程中会出现类似如下错误:/home/lu/autobuild/instance-0/output/build/opencv-2.4.10/modules/core/src/system.cpp:280:10:error:inconsistent operand constraints in an 'asm'
make[3]: *** [modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1
此时打开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]), "=b"(cpuid_data[1]), "=c"(cpuid_data[2]), "=d"(cpuid_data[3])
: "=a"(cpuid_data[0]), "=r"(cpuid_data[1]), "=c"(cpuid_data[2]), "=d"(cpuid_data[3])
:
: "cc"
);
5. 编译完成后,安装:sudo make install
6. 查看安装结果:pkg-config opencv --cflags --libs
注意:本站所有文章除特别说明外,均为原创,转载请务必以超链接方式并注明作者出处。