windows:
1.官网下载windows安装包
2.安装完成后,复制opencv\build\java\x64\opencv_java451.dll 到 C:\Windows 下
centos:
参考https://www.cnblogs.com/huizhipeng/p/12732019.html
1.先安装cmake3 参考https://www.jianshu.com/p/20dfd94b717e
2.官网下载sources压缩包
3.解压unzip opencv.zip && cd opencv-4.5.1
4.创建build文件夹mkdir build
5.cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTS=OFF ..
6.make -j8
7.make install
8.在opencv-4.5.1/build/lib中查看libopencv_java451.so文件和 jar文件
9.将libopencv_java451.so复制到usr/lib中
1.java调用:
1.maven依赖
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>4.5.1-2</version>
</dependency>
2.加载库文件
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
之后可进行其他代码操作
3.可能的报错
no opencv_javaXXX in java.library.path: 复制dll文件到C:\Windows 或复制os文件到usr/lib下
cant find dependent librarie
二、open cv 安装
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON .. cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=user/local/opencv -D OPENCV_EXTRA_MODULES_PATH=/software/opencv-4.6.0/opencv_contrib-4.6.0/modules/ .. make&&make install
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON .. cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/software/opencv-4.6.0/ -D OPENCV_EXTRA_MODULES_PATH=/software/opencv-4.6.0/opencv_contrib-4.6.0/modules/ .. make&&make install
yum install ant
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX= -DBUILD_TESTS=OFF ..
make -j8
make install
三、opencv依赖包安装
#报错 cmake 编译命令用不着可以不用执行 ffmpeg 命令不能用单独安装
yum -y install epel-release 替换 sudo amazon-linux-extras install epel
yum install gcc gcc-c++
yum install cmake
yum install python-devel numpy
yum install ffmpeg-devel
yum install -y unzip zip 线上存在
yum install gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel
yum install gkt+-devel
yum install gimp-devel
yum install gimp-devel-tools
yum install gimp-help-browser
yum install zlib-devel
安装ffmpeg
sudo yum install epel-release
sudo rpm -v --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
sudo yum install ffmpeg ffmpeg-devel
ffmpeg -version
ffmpeg 命令无法执行就执行代码编译安装
wget https://johnvansickle.com/ffmpeg/release-source/ffmpeg-4.1.tar.xz
解压ffmpeg文件:
xz -d ffmpeg-4.1.tar.xz
tar -xf ffmpeg-4.1.tar
Linux下安装yasm-1.3.0详细说明
①wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz #下载源码包
②tar zxvf yasm-1.3.0.tar.gz #解压
③cd yasm-1.3.0 #进入目录
④./configure #配置
⑤make && make install #编译安装
##切换ffmpeg 命令 编译ffmpeg
./configure --enable-shared --prefix=/usr/local/ffmpeg make && make install
https://knight.blog.csdn.net/article/details/103736930?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7EPayColumn-1-103736930-blog-81742177.pc_relevant_aa2&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7EPayColumn-1-103736930-blog-81742177.pc_relevant_aa2&utm_relevant_index=1
1、修改环境变量
将ffmpeg的绝对路径添加到PATH环境变量中,以让系统能找到ffmpeg的安装路径。
vim ~/.bashrc # 打开系统环境变量配置文件
source ~/.bashrc 生效
在文件中添以下内容。
export PATH="/usr/local/ffmpeg/bin:${PATH}" export LD_LIBRARY_PATH="/usr/local/ffmpeg/lib:{LD_LIBRARY_PATH}"
1、ffmpeg-添加环境变量
编译完成后,进入/etc/profile中将ffmpeg加入到环境变量
vim /etc/profile
(在文件最后加上export PATH=/usr/local/ffmpeg/bin:$PATH)
# source /etc/profile
#ffmpeg 配置不生效 增加ffmpeg.config文件 /usr/local/ffmpeg/lib
刷新配置
ldconfig
测试ffmpeg版本号是否生效
ffmpeg -version
cd /etc
cd ld.so.conf.d
2、opencv-添加环境变量输入命令:vi /etc/profile在末尾加入:export PATH=/usr/local/bin:$PATH 变量:source /etc/profile
执行
opencv_version 验证是否起作用
sudo yum install -y libwebp-tools
//报错imison
yum install ImageMagick
//配置映射
linux 缺少动态连接库.so(cannot open shared object file: No such file or directory)解决办法_linux编译opencv缺少动态库文件_Kena_M的博客-CSDN博客
CentOS 7
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
apt-get 安装 先用yum 尝试安装
sudo apt-get install mesa-common-dev libglu1-mesa-dev libglew1.5-dev libxtst-dev libxrandr-dev libpng12-dev libjpeg-dev zlib1g-dev libbz2-dev libogg-dev libvorbis-dev libc6-dev yasm libasound-dev libpulse-dev libjack-dev binutils-dev libgtk2.0-dev libmad0-dev libjack0 libudev-dev libva-dev
#opencv 依赖项 安装
sudo apt-get install build-essential |
yum install make glibc-devel gcc patch
yum install gcc gcc-c++ kernel-devel 安装替代 build-essential
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
#替代方案
在centos7下安装OpenCV 3.4.4 - 简书
sudo libtiff5-dev 替代方案
yum list | grep "libtiff"
yum -y install libtiff.x86_64
sudo apt-get install pkg-config 备用方案
(40条消息) 如何安装pkg-config_Elonjelinek的博客-CSDN博客_pkg-config安装
apt-get remove python-opencv sudo yum install python-opencv
sudo yum install -y libwebp-tools
find / cd-name ".bashrc"
#配置所在目录
cd /etc
cd ld.so.conf.d
#增加opencv.confg 配置文件 /usr/local/lib64 /user/local/lib
//修改刷新配置
vim /etc/ld.so.conf 查看 加载所有配置文件
ldconfig
opencv_version
查看linux 空间
df -h