From 5e6fd3e138dae84a1c2b99a346406fec6e5eff85 Mon Sep 17 00:00:00 2001 From: zhuyahong Date: Thu, 25 Jul 2024 18:18:45 +0800 Subject: [PATCH] feat: add sh --- README.md | 27 ++++++--------------------- copy_opencv_files.sh | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 copy_opencv_files.sh diff --git a/README.md b/README.md index cc21592..dd52b9f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ set_source_files_properties(${carotene_sources} COMPILE_FLAGS "--param ipa-cp-un #### 2.2 配置CMake编译选项 选择安装模块和安装路径,注意路径不要设置为系统路径,后面会手动拷贝到系统目录中: ```sh -cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules-4.2.0 \ +cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules-4.2.0/modules \ -DWITH_CUDA=ON \ -DOPENCV_GENERATE_PKGCONFIG=TRUE \ -DCMAKE_INSTALL_PREFIX=/home/autolabor/ThirdParty/opencv-build \ @@ -34,8 +34,7 @@ cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules-4.2.0 \ -DBUILD_opencv_sfm=OFF .. ``` -或者通过cmake-gui选择这些编译选项,但在generate阶段可能会报错,可以作为参考使用。 - +或者通过cmake-gui选择这些编译选项 #### 2.3 编译和安装 ```sh sudo make install -j8 @@ -43,16 +42,17 @@ sudo make install -j8 ### 3. 覆盖系统OpenCV库 -#### 3.1 创建软链接脚本 -编译完成后会出现几个文件夹,创建一个软链接的脚本,脚本内容如下: -#### 3.2 拷贝文件夹内容 +#### 3.1 拷贝文件夹内容 分别将右侧的`bin`、`include`、`lib`、`share`中的内容拷贝到: - `/build/bin` -> `/usr/bin` - `/build/include/opencv4` -> `/usr/include/opencv4` - `/build/share/opencv4` -> `/usr/share/opencv4` - `/build/lib/*.4.2.0` -> `/usr/lib/aarch64-linux-gnu/` +#### 3.2 创建软链接脚本 +编译完成后会出现几个文件夹,创建一个软链接的脚本,脚本内容如下: + 拷贝完成后,执行`create_link.sh`脚本,添加so库的链接 `*.so -> *.so.4.2`, `*.so.4.2 -> *.so.4.2.0` #### 3.3 配置pkgconfig @@ -76,18 +76,3 @@ sudo make install -j8 同样,将Python2.7的上述路径进行覆盖。 此时,就可以在Python中调用`import cv2`了。 - - -### 示例代码 -```sh -# 创建软链接的脚本 (create_link.sh) -#!/bin/bash - -ln -sf /usr/lib/aarch64-linux-gnu/libopencv_core.so.4.2 /usr/lib/aarch64-linux-gnu/libopencv_core.so -ln -sf /usr/lib/aarch64-linux-gnu/libopencv_imgproc.so.4.2 /usr/lib/aarch64-linux-gnu/libopencv_imgproc.so -# 添加其他需要的软链接 - -# 运行脚本 -chmod +x create_link.sh -sudo ./create_link.sh -``` diff --git a/copy_opencv_files.sh b/copy_opencv_files.sh new file mode 100644 index 0000000..a5220ce --- /dev/null +++ b/copy_opencv_files.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# 源目录和目标目录的定义 +SOURCE_DIR=/home/autolabor/ThirdParty/opencv-build/build +TARGET_BIN=/usr/bin +TARGET_INCLUDE=/usr/include +TARGET_SHARE=/usr/share +TARGET_LIB=/usr/lib/aarch64-linux-gnu +TARGET_PKGCONFIG=/usr/lib/aarch64-linux-gnu/pkgconfig +TARGET_CMAKE=/usr/lib/aarch64-linux-gnu/cmake +TARGET_PYTHON38=/usr/lib/python3.8/dist-packages/cv2/python3.8 +TARGET_PYTHON27=/usr/lib/python2.7/dist-packages/cv2/python2.7 + +# 拷贝文件和目录 +cp -r $SOURCE_DIR/bin/* $TARGET_BIN/ +cp -r $SOURCE_DIR/include/opencv4 $TARGET_INCLUDE/ +cp -r $SOURCE_DIR/share/opencv4 $TARGET_SHARE/ +cp $SOURCE_DIR/lib/*.4.2.0 $TARGET_LIB/ +cp $SOURCE_DIR/lib/pkgconfig/opencv4.pc $TARGET_PKGCONFIG/ +cp -r $SOURCE_DIR/lib/cmake/opencv4 $TARGET_CMAKE/ +cp $SOURCE_DIR/lib/python3.8/dist-packages/cv2/python3.8/*.so $TARGET_PYTHON38/ +cp $SOURCE_DIR/lib/python2.7/dist-packages/cv2/python2.7/*.so $TARGET_PYTHON27/ + +echo "所有文件和目录已成功拷贝。" \ No newline at end of file