feat: add sh
parent
5b7cc14e76
commit
5e6fd3e138
27
README.md
27
README.md
|
@ -26,7 +26,7 @@ set_source_files_properties(${carotene_sources} COMPILE_FLAGS "--param ipa-cp-un
|
||||||
#### 2.2 配置CMake编译选项
|
#### 2.2 配置CMake编译选项
|
||||||
选择安装模块和安装路径,注意路径不要设置为系统路径,后面会手动拷贝到系统目录中:
|
选择安装模块和安装路径,注意路径不要设置为系统路径,后面会手动拷贝到系统目录中:
|
||||||
```sh
|
```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 \
|
-DWITH_CUDA=ON \
|
||||||
-DOPENCV_GENERATE_PKGCONFIG=TRUE \
|
-DOPENCV_GENERATE_PKGCONFIG=TRUE \
|
||||||
-DCMAKE_INSTALL_PREFIX=/home/autolabor/ThirdParty/opencv-build \
|
-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 ..
|
-DBUILD_opencv_sfm=OFF ..
|
||||||
```
|
```
|
||||||
|
|
||||||
或者通过cmake-gui选择这些编译选项,但在generate阶段可能会报错,可以作为参考使用。
|
或者通过cmake-gui选择这些编译选项
|
||||||
|
|
||||||
#### 2.3 编译和安装
|
#### 2.3 编译和安装
|
||||||
```sh
|
```sh
|
||||||
sudo make install -j8
|
sudo make install -j8
|
||||||
|
@ -43,16 +42,17 @@ sudo make install -j8
|
||||||
|
|
||||||
### 3. 覆盖系统OpenCV库
|
### 3. 覆盖系统OpenCV库
|
||||||
|
|
||||||
#### 3.1 创建软链接脚本
|
|
||||||
编译完成后会出现几个文件夹,创建一个软链接的脚本,脚本内容如下:
|
|
||||||
|
|
||||||
#### 3.2 拷贝文件夹内容
|
#### 3.1 拷贝文件夹内容
|
||||||
分别将右侧的`bin`、`include`、`lib`、`share`中的内容拷贝到:
|
分别将右侧的`bin`、`include`、`lib`、`share`中的内容拷贝到:
|
||||||
- `/build/bin` -> `/usr/bin`
|
- `/build/bin` -> `/usr/bin`
|
||||||
- `/build/include/opencv4` -> `/usr/include/opencv4`
|
- `/build/include/opencv4` -> `/usr/include/opencv4`
|
||||||
- `/build/share/opencv4` -> `/usr/share/opencv4`
|
- `/build/share/opencv4` -> `/usr/share/opencv4`
|
||||||
- `/build/lib/*.4.2.0` -> `/usr/lib/aarch64-linux-gnu/`
|
- `/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`
|
拷贝完成后,执行`create_link.sh`脚本,添加so库的链接 `*.so -> *.so.4.2`, `*.so.4.2 -> *.so.4.2.0`
|
||||||
|
|
||||||
#### 3.3 配置pkgconfig
|
#### 3.3 配置pkgconfig
|
||||||
|
@ -76,18 +76,3 @@ sudo make install -j8
|
||||||
同样,将Python2.7的上述路径进行覆盖。
|
同样,将Python2.7的上述路径进行覆盖。
|
||||||
|
|
||||||
此时,就可以在Python中调用`import cv2`了。
|
此时,就可以在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
|
|
||||||
```
|
|
||||||
|
|
|
@ -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 "所有文件和目录已成功拷贝。"
|
Loading…
Reference in New Issue