ubuntu16.04下编译安装配置opencv2.4.13+tesseract3.04

编程

最近在做一个自动识别的项目,原理是使用java通过jni调用opencv和tesseract的原生库来实现图像识别和数字识别。下面是linux运行环境的配置。

1.安装opencv

1.1 准备环境

#安装编译工具

sudo apt-get install build-essential

#安装依赖包

sudo apt-get install cmake git libgtk2.0-dev pkg-config

libavcodec-dev libavformat-dev libswscale-dev

#安装可选包

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev

libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

1.2 下载并编译程序

https://github.com/opencv/opencv/archive/2.4.13.5.tar.gz

tar xvf 2.4.13.5.tar.gz

cd opencv-2.4.13.5

mkdir release //新建一个文件夹用于存放临时文件

cd release

sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

sudo make //开始编译(大概15分钟)

sudo make install

注:此时可能会提示:

Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY

原因是找不到jdk或jdk安装的不对导致的,执行如下命令即可:

sudo apt-get install -y openjdk-8-jdk

sudo apt-get install -y default-jdk

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

执行cmake时如果提示Java的JNI不为NO就代表java的的环境配置是有效的。

1.3 配置库加载路径

sudo vim /etc/ld.so.conf.d/opencv.conf

加入/usr/local/lib,再执行

sudo ldconfig

安装后可以在/usr/local/share/OpenCV/java下看到安装的库和jar包。

另外,还要导出包配置路径

sudo vim /etc/bash.bashrc

加入

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

最后

source /etc/bash.bashrc

2.安装tesseract

2.1.安装相应lib

sudo apt-get install libpng12-dev

sudo apt-get install libjpeg62-dev

sudo apt-get install libtiff5-dev

sudo apt-get install libtool

sudo apt-get install gcc

sudo apt-get install g++

sudo apt-get install automake

2.2.下载安装leptonica

wget http://www.leptonica.org/source/leptonica-1.73.tar.gz

tar zxvf leptonica-1.73.tar.gz

cd leptonica-1.73

./configure

make

make install

2.3.下载安装tesseract

wget https://github.com/tesseract-ocr/tesseract/archive/3.04.01.tar.gz

tar zvf 3.04.01.tar.gz

cd tesseract-3.04.01

sudo ./autogen.sh

./configure

make

make install

ldconfig

3.参考网址

https://blog.csdn.net/cheneykl/article/details/79115131

https://blog.csdn.net/pangyunsheng/article/details/79372845

https://stackoverflow.com/questions/51047978/cmake-could-not-find-jni

以上是 ubuntu16.04下编译安装配置opencv2.4.13+tesseract3.04 的全部内容, 来源链接: utcz.com/z/510319.html

回到顶部