## OpenCV 项目 ### 如何编译该项目 **必须安装的环境** 1. 配置 `JAVA_HOME` 2. 安装 opencv ```shell git clone https://git.yishihui.com/VideoProcessing/PQCVMedia.git cd PQCVMedia ./build.sh echo "安装成功,在当前 output/lib 下" ``` #### Linux: **配置 JAVA_HOME 环境变量** ```shell export JAVA_HOME=xxx ``` **命令安装 必须 4.5.5 版本** ```shell sudo yum install opencv opencv-devel #检查版本 pkg-config --modversion opencv ``` **源码安装 4.5.5** ```shell #opencv 环境 4.5.5 #安装依赖包 sudo yum install freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel libv4l-devel libjpeg-turbo-devel libtiff-devel libdc1394-devel tbb-devel eigen3-devel gstreamer-plugins-base-devel python-devel numpy python34-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel python3 python3-devel python3-pip python3-devel python3-numpy #下载 OpenCV 源码 wget -O opencv-4.5.5.zip https://github.com/opencv/opencv/archive/refs/tags/4.5.5.zip wget -O opencv_contrib-4.5.5.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.5.zip unzip opencv-4.5.5.zip unzip opencv_contrib-4.5.5.zip cd opencv-4.5.5 mkdir build && cd build OPENCV_CONTRIB_DIR=/root/opencv/opencv_contrib-4.5.5/modules cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_EXTRA_MODULES_PATH="${OPENCV_CONTRIB_DIR}" \ -D BUILD_EXAMPLES=ON .. #使用 8cpu 编译并安装 make -j8 && make install ``` #### MAC: **命令安装** ```shell brew install opencv ``` 如果安装慢可以换一个源: ```shell cd "$(brew --repo)" git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile ``` ### 如何使用? #### java **将 jar copy 至你的项目** ```shell cp PQCVMedia/output/jar/libpq-cv-media.jar 你的目录 ``` **1、初始化 SDK** ```java PQCVMediaProcessor.initSDK("/root/libpiaoquan_java_opencv.so"); ``` **2、以 bytes 流形式传递** ```java PQCVMediaProcessor.blurDetectionFromImageBytes(byte[] data) ``` **2、以 path 流形式传递** ```java PQCVMediaProcessor.blurDetectionFromImagePath(String path); ```