整个编译过程可谓是瞎猫碰死耗子(bushi),折腾了我两天
最便捷的方式就是直接拿SIG做好封装的openCV库,但是在移植到4.1的标准系统中编译的时候还是会出现很多意料之外的问题。结果是解决了,但是其实有个别我也不是很清楚解决的原因,欢迎大佬批评指正。
前置条件:rk3568, OpenHarmony4.1标准系统,编译环境:Ubuntu20.04LTS
1. 下载OpenCV移植好的源码
下载链接:OpenHarmony-SIG/third_party_opencv
在此鸣谢大佬,本来感觉我都要自己封一个库了,想想就烦
2. 添加到标准系统源码的对应路径下
将opencv这个文件夹整个放到third_party目录下,修改文件夹名字为opencv(其实也可以是别的名字,只不过我自己想让他叫opencv,下面的各种配置都是按照这个命名)
修改vendor/hihope/config.json中的thirdparty子系统下组件(component)的信息,添加opencv组件
{
"subsystem": "thirdparty",
"components": [
{
"component": "libuv",
"features": [
"use_ffrt = true"
]
},
{
"component": "wpa_supplicant",
"features": [
"wpa_supplicant_driver_nl80211 = true"
]
},
{
"component": "opencv",
"features":[]
}
]
},
3. 由于这里我们是以添加组件的方式,因此不需要修改build/subsystem_config.json中的信息
4. 在源码根目录下进行编译,具体的编译方法参考官方文档
编译4.1相关链接:OpenAtom OpenHarmony
5.修bug
最头痛的部分。此处省略一万个草泥马。。
接下来展示我在编译过程中遇到的bug
Bug1
Exception: //third_party/opencv/3rdparty/ffmpeg/libavcodec:opencv_ffmpeg_avcodec depend part //third_party/opencv/3rdparty/ffmpeg/libavutil:libopencv_avutil, need set part deps opencv info to /home/hzk/Documents/OH4.1/OpenHarmony-v4.1-Release/OpenHarmony/build/bundle.json.
修改方法:build的bundle.json中deps和third_party修改如下
"deps": {
"components": [],
"third_party": [
"musl",
"markupsafe",
"jinja2",
"e2fsprogs",
"f2fs-tools",
"opencv"
]
},
"build": {
"sub_component": [
"//build/common:common_packages",
"//build/rust:default",
"//third_party/f2fs-tools:f2fs-tools_host_toolchain",
"//third_party/opencv/3rdparty/ffmpeg/libavutil:libopencv_avutil",
"//third_party/opencv/3rdparty/ffmpeg/libswresample:libopencv_swresample"
],
Bug2
OHOS ERROR] Exception: //third_party/opencv/napi:opencv_napi depend part //third_party/bounds_checking_function:libsec_static, need set part deps bounds_checking_function info to /home/hzk/Documents/OH4.1/OpenHarmony-v4.1-Release/OpenHarmony/third_party/opencv/bundle.json.
解决方法:在opencv/bundle.json的components中加入bounds_checking_function和libuv,然后在下面的third_party中去掉相对路径(应该是要这么做),就可以过编译了。大致结果长这样
"deps": {
"components": [
"ability_base",
"ability_runtime",
"access_token",
"bundle_framework",
"c_utils",
"certificate_manager",
"common_event_service",
"hisysevent",
"hilog",
"huks",
"ipc",
"napi",
"netmanager_base",
"safwk",
"samgr",
"data_share",
"hdf_core",
"hicollie",
"relational_store",
"bounds_checking_function",
"libuv"
],
"third_party": [
"bounds_checking_function",
"libuv"
]
},
6. 如何查看动态库是否编译成功?
前往路径out/rk3568/packages/phone/system/lib/ 查看libopecv相关的so文件即可
---
ENDING
其他如果也有遇到Bug的,欢迎评论区互相折磨~