车牌识别之OpenCV安装配置篇

前端之家收集整理的这篇文章主要介绍了车牌识别之OpenCV安装配置篇前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

题记

上一篇中提到了OpenCV这个开源项目,由于我们国内的开源项目EasyPR是依赖于OpenCV的,又由于windows环境下的项目没有搭建成功,而且一般我们的项目都是要部署到linux环境下的。所以这篇我们就来搭建以linux环境下的OpenCV环境,好了废话不多说了下面进入正题。

安装篇

安装环境

CentOS release 6.7 (Final) 64 bit
物理cpu 1
cat /proc/cpuinfo |grep “physical id”|sort |uniq|wc -l
逻辑cpu 4
cat /proc/cpuinfo |grep “processor”|wc -l

以安装numpy1.9.1,gcc4.8.0,python2.7.9,cmake3.1.3,opencv3.0.0为例 。

安装步骤

1:查看下版本
查看centos :lsb_release -a

查看python:python –version

查看gcc:gcc –version

查看cmake:cmake –version

2:安装&升级相应软件(请按顺序安装升级
OpenCV安装流程参考文档
http://www.jianshu.com/p/a41da779f763
2.1:下载并安装ISL

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.11.1.tar.bz2
友情提示:如果下载不下来自行下载拷贝到服务器上
然后解压
下载依赖包:(手工编译ISL需要的)
yum install cloog-ppl gmp-devel
进入解压后的文件夹配置与安装
./configure
make && make install

2.2:下载并安装GCC4.8.0
GCC4.8安装参考文档
http://www.jb51.cc/article/p-mbhdmeql-hb.html

获取gcc4.8.2包并解压缩:
下载链接:http://gcc.skazkaforyou.com/releases 
里面有gcc所有的版本,自行下载。
也可以选择: wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.0/gcc-4.8.0.tar.bz2
友情提示:如果下载不下来自行下载拷贝到服务器上
然后解压缩: tar -vxjf gcc-4.8.0.tar.bz2
进入gcc-4.8.0目录
新建文件夹:
mkdir build
执行./contrib/download_prerequisities
脚本会自动下载三个依赖库别为gmp-4.3.2、mpfr-2.4.2、mpc-0.8.1
或者自己手动下载(本文档采用此方法ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2
http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2
http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz
改变当前路径:
cd build/
../configure --prefix=/usr   --build=x86_64-linux  --enable-languages=c,c++ --disable-multilib
下面进入问题多发地段
安装
可能会遇到的问题(我遇到了)
所以为了避免上面提到的错误先执行下面的两行命令然后再安装gcc
yum install gcc-c++
yum -y install glibc-devel.i686 glibc-devel
执行如下命令
make && make install
这个过程参考的文档中说的要大于30分钟,我执行的时候竟然用来1个小时,估计和机器性能有关系`这里写代码片`

验证安装成功提示如下

上面所述的进入问题多发地段详情参见如下
2.2.1:make && make install结束报错1
问题描述:

configure: error: C++ compiler missing or inoperational
make[2]: *** [configure-stage1-libcpp] 错误 1
make[2]: Leaving directory `/opencv/gcc-4.8.0/build'
make[1]: *** [stage1-bubble] 错误 2
make[1]: Leaving directory `/opencv/gcc-4.8.0/build'
make: *** [all] 错误 2

问题解决方案:

yum install gcc-c++

参考如下文档
http://www.cnblogs.com/baolinfang/p/5070360.html
2.2.2:make && make install结束报错2
问题描述:

checking for suffix of object files... configure: error: in `/opencv/gcc-4.8.0/build/x86_64-linux/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[2]: *** [configure-stage1-target-libgcc] 错误 1
make[2]: Leaving directory `/opencv/gcc-4.8.0/build'
make[1]: *** [stage1-bubble] 错误 2
make[1]: Leaving directory `/opencv/gcc-4.8.0/build'
make: *** [all] 错误 2

问题解决方案:
安装如下包

yum -y install glibc-devel.i686 glibc-devel

参考一下文档
http://www.linuxidc.com/Linux/2015-01/112595.htm

2.3:下载并安装CMAKE

下载CMAKE:
wget http://www.cmake.org/files/v3.1/cmake-3.1.3.tar.gz
友情提示:如果下载不下来自行下载拷贝到服务器上
解压
编译与安装:
./configure
make && make install
查看CMAKE版本:
cmake --version

2.4:下载并安装PYTHON279

由于之前系统里面带有python2.6.6,所以省去可以不下载依赖包
参考http://www.jb51.net/article/94266.htm
下载PYTHON:

wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz
友情提示:如果下载不下来自行下载拷贝到服务器上
解压
tar -vxJf Python-2.7.9.tar.xz
编译与安装:
./configure --prefix=/usr/local --enable-shared CFLAGS=-fPIC 
上面是64位安装
make
make install
make clean
配置当前python版本:
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
如果上述命令不起反应则运行下段命令会报错
参考
/usr/local/bin/python2.7 -V
查看下上面路径下的python版本(279)则运行(否,安装python错误 自行查阅)
mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python2.7 /usr/bin/python

检验python指向是否成功:
python -V
此时yum命令会报错运行下段命令:
vi /usr/bin/yum

将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.6.6
可以检测下yum是否ok!
yum

上述安装的时候遇到的问题
问题描述:
安装了python2.7,第一次执行时报错:

error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

解决方案:
http://www.jb51.cc/article/p-wytxfqpy-wt.html
2.5:下载并安装NUMPY

下载numpy:
wget https://pypi.python.org/packages/source/n/numpy/numpy-1.9.1.tar.gz#md5=78842b73560ec378142665e712ae4ad9
友情提示:如果下载不下来自行下载拷贝到服务器上
解压
改变当前路径:
cd numpy-1.9.1
安装:
python setup.py install

reboot
安装后要重启否则会报错
检测:
改变路径:
cd
python
import numpy

如果不报错,则成功,否则重新自行安装:
报错
exit()

安装NUMPY遇到的问题
问题描述:
安装完成后没有重启,发现检测的时候

[root@SZB-L0020233 ~]# python
Python 2.7.9 (default,Oct 13 2016,14:43:09) 
[GCC 4.8.0] on linux2
Type "help","copyright","credits" or "license" for more information.
>>> import numpy
报如下错误信息:
Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
  File "numpy/__init__.py",line 160,in <module>
    raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree,and relaunch
        your python interpreter from there.

解决方案:
重启服务器
reboot
2.6:下载并安装OPENCV
上面的流程走了1天多,主要时间都花在下载包,上传包到服务器(由于公司供开发用的机器上竟然不能下载包)。还有大部分时间花在安装过程中出现的问题解决上,真心累啊。下面正式进入主题安装,前面的铺垫都是为了它啊,大哥出场了,正是千呼万唤始出来啊。

Linux版本包下载地址如下
wget https://codeload.github.com/opencv/opencv/zip/3.1.0
友情提示:如果下载不下来自行下载拷贝到服务器上

同上面的包的安装,先把包拷贝到服务器上去
安装各种依赖包(宁可信其有):
yum install -y gcc gcc-c++ gtk+-devel libjpeg-devel libtiff-devel jasper-devel libpng-devel zlib-devel cmake
yum install git gtk2-devel pkgconfig numpy python python-pip python-devel gstreamer-plugins-base-devel libv4l ffmpeg-devel mplayer mencoder flvtool2
yum install libdc1394
yum install gtk*
下载opencv:
上面已经做过了,开始解压
unzip opencv-3.1.0.zip
改变当前路径:
cd opencv-3.1.0/
新建文件夹:
mkdir build
编译与安装:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=./build ../opencv-3.0.0
又报错了,不开森啊
包下载地址
https://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv/
下载ippicv_linux_20141027.tgz,重新上传到服务器上的对应如下目录
/opencv/opencv-3.0.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b
然后重新
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=./build ../opencv-3.0.0
正常了……继续安装
make -j8
又TM的报错了也是醉了
执行安装
make install
检查:
cd lib/
ls
查看是否存在cv2.so
存在则:ln cv2.so /usr/local/lib/python2.7/site-packages
否则重新安装,查找错误

上面遇到的错误详情:
Opencv3.0.0报错

CMake Error at 3rdparty/ippicv/downloader.cmake:71 (file):
  file DOWNLOAD HASH mismatch

    for file: [/opencv/opencv-3.0.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b/ippicv_linux_20141027.tgz]
      expected hash: [8b449a536a2157bcad08a2b9f266828b]
        actual hash: [d41d8cd98f00b204e9800998ecf8427e]
             status: [6;"couldn't resolve host name"]

Call Stack (most recent call first):
  3rdparty/ippicv/downloader.cmake:108 (_icv_downloader)
  cmake/OpenCVFindIPP.cmake:235 (include)
  cmake/OpenCVFindLibsPerf.cmake:12 (include)
  CMakeLists.txt:526 (include)
CMake Error at 3rdparty/ippicv/downloader.cmake:75 (message):
  ICV: Failed to download ICV package: ippicv_linux_20141027.tgz.
  Status=6;"couldn't resolve host name"
Call Stack (most recent call first):
  3rdparty/ippicv/downloader.cmake:108 (_icv_downloader)
  cmake/OpenCVFindIPP.cmake:235 (include)
  cmake/OpenCVFindLibsPerf.cmake:12 (include)
  CMakeLists.txt:526 (include)

解决方案:
参考文章如下
https://my.oschina.net/u/1046919/blog/479947
包下载地址
https://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv/
下载对应版本的包,重新上传到服务器上的对应如下目录,请对应上传自己的安装路径
/opencv/opencv-3.0.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b
make j8报错
错误描述:

Scanning dependencies of target opencv_python2
[100%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
Linking CXX shared library ../../lib/cv2.so
/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: 错误:ld 返回 1
make[2]: *** [lib/cv2.so] 错误 1
make[1]: *** [modules/python2/CMakeFiles/opencv_python2.dir/all] 错误 2
make: *** [all] 错误 2

解决方案:
重新安装python2.7.9
之前编译的时候未加–enable-shared CFLAGS=-fPIC 现在要加上详情参见1.2.2.4 下载并安装PYTHON279
./configure –prefix=/usr/local –enable-shared CFLAGS=-fPIC
2.7:最后检查

进入python
python
import cv2

如果不报错 则成功!!!!
终于走下来了,感觉脑细胞严重不够用了…..

至此OpenCV在linux中的安装总算成功了….

OpenCV官方说明文档:
http://docs.opencv.org/3.1.0/dd/dd5/tutorial_py_setup_in_fedora.html#gsc.tab=0

猜你在找的CentOS相关文章