feat: 修改文档

master
邱棚 2024-07-25 18:27:24 +08:00
parent 5e6fd3e138
commit 2a3c57124d
1 changed files with 40 additions and 23 deletions

View File

@ -17,24 +17,33 @@
sudo apt-get install cmake-gui
```
#### 2.1 更改`opencv/3rdparty/carotene/CMakeList.txt`
将以下内容添加到文件中:
```cmake
set_source_files_properties(${carotene_sources} COMPILE_FLAGS "--param ipa-cp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
```
#### 2.1 更改CMakeList
- `opencv/3rdparty/carotene/CMakeList.txt`
将以下内容添加到文件中:
```cmake
set_source_files_properties(${carotene_sources} COMPILE_FLAGS "--param ipa-cp-unit-growth=100000 --param inline-unit-growth=100000 --param large-stack-frame-growth=5000")
```
- `opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt`
将以下内容添加到文件中:
```cmake
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
``
#### 2.2 配置CMake编译选项
选择安装模块和安装路径,注意路径不要设置为系统路径,后面会手动拷贝到系统目录中:
```sh
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 \
-DBUILD_TESTS=OFF \
-DBUILD_opencv_sfm=OFF ..
-DCMAKE_CXX_STANDARD=11
-DCMAKE_CXX_STANDARD_REQUIRED=ON..
```
或者通过cmake-gui选择这些编译选项
#### 2.3 编译和安装
```sh
sudo make install -j8
@ -42,37 +51,45 @@ sudo make install -j8
### 3. 覆盖系统OpenCV库
#### 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/`
```sh
sudo cp -r /home/autolabor/ThirdParty/opencv-build/build/bin/* /usr/bin/
sudo cp -r /home/autolabor/ThirdParty/opencv-build/build/include/opencv4 /usr/include/
sudo cp -r /home/autolabor/ThirdParty/opencv-build/build/share/opencv4 /usr/share/
sudo cp /home/autolabor/ThirdParty/opencv-build/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
将`/build/lib/pkgconfig/opencv4.pc` 拷贝到 `/usr/lib/aarch64-linux-gnu/pkgconfig`中。
这样使用`pkg-config --modversion opencv4`就可以看到4.2.0的输出了。
拷贝`opencv4.pc`文件到`/usr/lib/aarch64-linux-gnu/pkgconfig/`中:
```sh
sudo cp /home/autolabor/ThirdParty/opencv-build/build/lib/pkgconfig/opencv4.pc /usr/lib/aarch64-linux-gnu/pkgconfig/
```
使用`pkg-config --modversion opencv4`检查是否配置成功正常能看到4.2.0的输出了。
#### 3.4 配置CMake文件
将`/build/lib/cmake/opencv4/*.cmake` 拷贝到 `/usr/lib/aarch64-linux-gnu/cmake/opencv4/`中。
修改`OpenCVConfig.cmake`文件,将`OpenCV_INSTALL_PATH`目录多添加一层`../`,即指向`/usr`。
修改`OpenCVModules-release.cmake`文件,将所有的`/lib/`替换为`/aarch64-linux-gnu/`。
- 拷贝Opencv的CMake文件到`/usr/lib/aarch64-linux-gnu/cmake/`中:
```sh
sudo cp -r /home/autolabor/ThirdParty/opencv-build/build/lib/cmake/opencv4 /usr/lib/aarch64-linux-gnu/cmake/
```
- 修改`OpenCVConfig.cmake`文件,将`OpenCV_INSTALL_PATH`目录多添加一层`../`,即指向`/usr`。
- 修改`OpenCVModules-release.cmake`文件,将所有的`/lib/`替换为`/aarch64-linux-gnu/`。
这样就完成了CMake的配置在调用`find_package(OpenCV)`时会调用这几个CMake文件。
#### 3.5 配置Python
将`/build/lib/python3.8/dist-package/cv2/python3.8`中的`*.so`拷贝到
`/usr/lib/python3.8/dist-package/cv2/python3.8`中。
同样将Python2.7的上述路径进行覆盖。
拷贝python3.8和python2.7调用的动态连接库:
```sh
sudo cp /home/autolabor/ThirdParty/opencv-build/build/lib/python3.8/dist-packages/cv2/python3.8/*.so /usr/lib/python3.8/dist-packages/cv2/python3.8/
sudo cp /home/autolabor/ThirdParty/opencv-build/build/lib/python2.7/dist-packages/cv2/python2.7/*.so /usr/lib/python2.7/dist-packages/cv2/python2.7/
```
此时就可以在Python中调用`import cv2`了。