1) 首先,不要系统默认安装,访问以下链接:
https://help.ubuntu.com/community/OpenCV
2)按照里面步骤安装即可。
然后sudo vim /etc/bash.bashrc
最后面添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存后,要重启,不重启用不了。
重启后,如何测试配置正确。
cd /usr/local/share/OpenCV/samples
cd c
sudo chmod +x build_all.sh
sudo ./build_all.sh
这时编译c文件会出现错误。
compiling contours.c
/usr/bin/ld: /tmp/cc7GbY6W.o: undefined reference to symbol 'cos@@GLIBC_2.0'
/usr/bin/ld: note: 'cos@@GLIBC_2.0' is defined in DSO /lib/i386-linux-gnu/libm.so.6 so try adding it to the linker command line
/lib/i386-linux-gnu/libm.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
解决办法是
Try adding -lm, to include the math library that provides lrint
在c后面添加-lm这个选项,修改build_all.sh
修改后的内容为
#!/bin/sh
if [ $# -gt 0 ] ; then
base=`basename $1 .c`
echo "compiling $base"
gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
else
for i in *.c; do
echo "compiling $i"
gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv` -lm;
done
for i in *.cpp; do
echo "compiling $i"
g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv`;
done
fi
然后再编译c文件就不会出错了。
有时下载的DLT包编译会失败
Scanning dependencies of target tld
[ 80%] Building CXX object CMakeFiles/tld.dir/TLD.o
In file included from /home/haiping/opentld/OpenTLD-master/src/TLD.cpp:8:0:
opentld/OpenTLD-master/src/../include/TLD.h:51:3: error: ‘PatchGenerator’ in namespace ‘cv’ does not name a type
opentld/OpenTLD-master/src/TLD.cpp: In member function ‘void TLD::init(const cv::Mat&, const Rect&, FILE*)’:
opentld/OpenTLD-master/src/TLD.cpp:68:3: error: ‘generator’ was not declared in this scope
opentld/OpenTLD-master/src/TLD.cpp:68:162: error: ‘PatchGenerator’ was not declared in this scope
opentld/OpenTLD-master/src/TLD.cpp: In member function ‘void TLD::generatePositiveData(const cv::Mat&, int)’:
opentld/OpenTLD-master/src/TLD.cpp:156:51: error: ‘generator’ was not declared in this scope
make[2]: *** [CMakeFiles/tld.dir/TLD.o] Error 1
make[1]: *** [CMakeFiles/tld.dir/all] Error 2
make: *** [all] Error 2
这个是新版opencv的库函数位置更新了,
TLD.h 添加上
#include <opencv2/legacy/legacy.hpp>
再编译就好了