linux-Ubantu系统,基于java基础镜像,dockerfile源码编译安装opencv,重新制作docker镜像

官方文档最准确的安装参考:https://docs.opencv.org/4.6.0/d7/d9f/tutorial_linux_install.html

安装参考:https://blog.csdn.net/Taylor_0522/article/details/119172807
使用参考:https://blog.wangqi.love/articles/Java/Java%E8%B0%83%E7%94%A8opencv.html

dockerfile

FROM coding-public-docker.pkg.coding.net/public/docker/openjdk:8

制作镜像并进入容器

docker build -t face-petition-java:1.0.0.0802 .
docker run -it --entrypoint=/bin/bash face-petition-java:1.0.0.0802

通过拷贝文件的方式更改镜像源

把内网地址mirrors.tencentyun.com换成外网mirrors.tencent.com

docker cp 3abdb23ac326:/etc/apt/sources.list /data/mart/face_insight/java_dockerfile/

docker cp /data/mart/face_insight/java_dockerfile/sources.list 3abdb23ac326:/etc/apt/

安装依赖

apt update
 
apt install build-essential cmake net-tools git vim unzip iputils-ping -y
 
apt install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libswresample-dev libavresample-dev libgphoto2-dev 
 
apt install libgtk3.0     #安装过程中选 6 Asia   70 Shanghai
 
apt install libgstreamer1.0-dev  libgstreamer1.0-dev
 
apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev  libdc1394-22-dev

apt install ant 

下载opencv

wget https://github.com/opencv/opencv/archive/4.6.0.zip
unzip 4.6.0.zip
cd opencv-4.6.0

mkdir build && cd build

cmake介绍

cmake参数指令介绍
CMAKE_BUILD_TYPE:build类型(Debug,Release,…),CMAKE_BUILD_TYPE=Debug;
CMAKE_INSTALL_PREFIX:工程安装目录,所有生成和调用所需的可执行程序,库文件,头文件都会安装到该路径下,Unix/Linux下默认为/usr/local, windows下默认为C:\Program Files;

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

注意:其中,BUILD_opencv_world=ON 将所有opencv必要库绑定到libopencv_world.so文件,工程中直接使用该 .so文件即可;CMAKE_INSTALL_PREFIX=/usr/local/opencv460 将opencv相关安装到/usr/local/opencv460目录中,工程中注意连接该目

编译安装

make -j8
 
make install

运行结束后,即可以用C++调用了。

用cmake生成java的jar

cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_opencv_world=ON -D CMAKE_INSTALL_PREFIX=/usr/local/opencv460 -DBUILD_TESTS=OFF -DBUILD_opencv_java=ON ..
make -j8
make install

以上操作结束后, 看看build文件夹, bin目录下是不是有一个opencv-460.jar文件:

以上操作结束后,/usr/local/opencv460/share/java/opencv4目录也有相关的库文件和jar文件:

/usr/local/opencv460/share/java/opencv4
libopencv_java460.so  opencv-460.jar

制作镜像并提交

    docker commit 3abdb23ac326 face-petition-java-new:1.0.0.0802

    docker tag face-petition-java-new:1.0.0.0802 xx/face-petition-java-new:1.0.0.0802   

    docker login -u xx -p xx xx-docker.pkg.coding.net

    docker push xx/face-petition-java-new:1.0.0.0802

报错

Failed to fetch http://mirrors.tencentyun.com/debian/pool/main/v/vim/xxd_8.1.0875-5_amd64.deb  Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)

linux-Ubantu系统,基于java基础镜像,dockerfile源码编译安装opencv,重新制作docker镜像_第1张图片

解决方案

报错解决
ping后发现网络不通

ping mirrors.tencentyun.com
cat /etc/apt/sources.list

把内网地址mirrors.tencentyun.com换成外网mirrors.tencent.com

deb http://mirrors.tencent.com/debian buster main contrib non-free
deb http://mirrors.tencent.com/debian buster-updates main contrib non-free
deb http://mirrors.tencent.com/debian-security buster/updates main
#deb http://mirrors.tencent.com/debian buster-backports main contrib non-free
#deb http://mirrors.tencent.com/debian buster-proposed-updates main contrib non-free

deb-src http://mirrors.tencent.com/debian buster main contrib non-free
deb-src http://mirrors.tencent.com/debian buster-updates main contrib non-free
deb-src http://mirrors.tencent.com/debian-security buster/updates main
#deb-src http://mirrors.tencent.com/debian buster-backports main contrib non-free
#deb-src http://mirrors.tencent.com/debian buster-proposed-updates main contrib non-free

通过拷贝文件的方式更改

docker cp 3abdb23ac326:/etc/apt/sources.list /data/mart/face_insight/java_dockerfile/

docker cp /data/mart/face_insight/java_dockerfile/sources.list 3abdb23ac326:/etc/apt/

报错1

未生成jar包问题:https://blog.csdn.net/weixin_43919656/article/details/121949469
完整生成jar包的配置以及最终的测试:https://www.bbsmax.com/A/x9J2X8kVd6/

你可能感兴趣的:(笔记,术语,NLP实战项目,java,opencv,开发语言)