diff --git a/thirdparty/libsvm/HPKBUILD b/thirdparty/libsvm/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..90a3aa11a3d98962b27d8b9c08bf2231df5739c1 --- /dev/null +++ b/thirdparty/libsvm/HPKBUILD @@ -0,0 +1,65 @@ +# Contributor: wupingyuan +# Maintainer: wupingyuan +pkgname="libsvm" +pkgver="v331" +pkgrel=0 +pkgdesc="Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. It solves C-SVM classification, nu-SVM classification, one-class-SVM, epsilon-SVM regression, and nu-SVM regression. It also provides an automatic model selection tool for C-SVM classification. This document explains the use of libsvm." +url="https://github.com/cjlin1/libsvm" +archs=("armeabi-v7a" "arm64-v8a") +license=("BSD") +depends=() +makedepends=() +install= +source="https://github.com/cjlin1/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +autounpack=true +downloadpackage=true +buildtools="make" +builddir=$pkgname-${pkgver:1} +packagename=$builddir.tar.gz +cxx= + +prepare() { + cp -rf $builddir $builddir-$ARCH-build + if [ $ARCH == ${archs[0]} ] + then + cxx=${OHOS_SDK}/native/llvm/bin/arm-linux-ohos-clang++ + fi + if [ $ARCH == ${archs[1]} ] + then + cxx=${OHOS_SDK}/native/llvm/bin/aarch64-linux-ohos-clang++ + fi +} + +build() { + cd $builddir-$ARCH-build + make CXX=${cxx} all lib -j4 > `pwd`/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir-$ARCH-build + # 由于没有install命令需要手动拷贝到安装目录 + mkdir -p $LYCIUM_ROOT/usr/$pkgname-$ARCH-install/include/ + mkdir -p $LYCIUM_ROOT/usr/$pkgname-$ARCH-install/lib/ + cp svm.h $LYCIUM_ROOT/usr/$pkgname-$ARCH-install/include/ + cp libsvm.so.3 $LYCIUM_ROOT/usr/$pkgname-$ARCH-install/lib/ + ret=$? + cd $OLDPWD + unset cxx + return $ret +} + +check() { + echo "The test must be on an OpenHarmony device!" + # 在OpenHarmony开发板中执行用例 + # ./svm-scale test.data > test.scale + # ./svm-train test.scale test.model + # ./svm-predict test.scale test.model test.predict +} + +cleanbuild(){ + rm -rf ${PWD}/$builddir $builddir-armeabi-v7a-build $builddir-arm64-v8a-build #${PWD}/$packagename +} \ No newline at end of file diff --git a/thirdparty/libsvm/README.OpenSource b/thirdparty/libsvm/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..069297350b25ccc3cc646c9909fa211519917a3f --- /dev/null +++ b/thirdparty/libsvm/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "libsvm", + "License": "BSD", + "License File": "COPYRIGHT", + "Version Number": "v331", + "Owner": "wupingyuan@huawei.com", + "Upstream URL": "https://github.com/cjlin1/libsvm/archive/refs/tags/v331.tar.gz", + "Description": "Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. It solves C-SVM classification, nu-SVM classification, one-class-SVM, epsilon-SVM regression, and nu-SVM regression. It also provides an automatic model selection tool for C-SVM classification. This document explains the use of libsvm." + } +] diff --git a/thirdparty/libsvm/README_zh.md b/thirdparty/libsvm/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..ed0f3374e4350382cc1a64deac577461957e1b3a --- /dev/null +++ b/thirdparty/libsvm/README_zh.md @@ -0,0 +1,12 @@ +# libsvm三方库说明 +## 功能简介 +libsvm是一个支持向量机的库。 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 3.2.11.9 (API Version 9 Release) +- 三方库版本:v331 +- 当前适配的功能:支持向量机 +- [BSD](https://github.com/cjlin1/libsvm) + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/libsvm/SHA512SUM b/thirdparty/libsvm/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..8af706ac281c619a94e6379d82674f8aefc3f653 --- /dev/null +++ b/thirdparty/libsvm/SHA512SUM @@ -0,0 +1 @@ +78d3241fbf0286da077b8e612604feee13946b551888dcd8f47d23b4791f2a1daf516f3871e9a02d1b70cb58e12705603af8ef3c2ff0aac4211423d5053c7083 libsvm-331.tar.gz \ No newline at end of file diff --git a/thirdparty/libsvm/docs/hap_integrate.md b/thirdparty/libsvm/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..b4f010868094f9496020b524b82a290ada91bab9 --- /dev/null +++ b/thirdparty/libsvm/docs/hap_integrate.md @@ -0,0 +1,90 @@ +# libsvm集成到应用hap +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +## 开发环境 +- ubuntu20.04 +- [OpenHarmony3.2Release镜像](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fdayu200_standard_arm32.tar.gz) +- [ohos_sdk_public 3.2.11.9 (API Version 9 Release)](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fohos-sdk-windows_linux-public.tar.gz) +- [DevEco Studio 3.1 Beta2](https://gitee.com/link?target=https%3A%2F%2Fcontentcenter-vali-drcn.dbankcdn.cn%2Fpvt_2%2FDeveloperAlliance_package_901_9%2Ff3%2Fv3%2FuJyuq3syQ2ak4hE1QZmAug%2Fdevecostudio-windows-3.1.0.400.zip%3FHW-CC-KV%3DV1%26HW-CC-Date%3D20230408T013335Z%26HW-CC-Expire%3D315360000%26HW-CC-Sign%3D96262721EDC9B34E6F62E66884AB7AE2A94C2A7B8C28D6F7FC891F46EB211A70) +- [准备三方库构建环境](../../../tools/README.md#编译环境准备) +- [准备三方库测试环境](../../../tools/README.md#ci环境准备) +## 编译三方库 +- 下载本仓库 + ``` + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/thirdparty/libsvm #三方库libsvm的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` + +- 将libsvm拷贝至tools/main目录下 + ``` + cd tpc_c_cplusplus + cp thirdparty/libsvm tools/main -rf + ``` +- 在tools目录下编译三方库 + 编译环境的搭建参考[准备三方库构建环境](../../../tools/README.md#编译环境准备) + ``` + cd tools + ./build.sh libsvm + ``` +- 三方库头文件及生成的库 + 在tools目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + ``` + libsvm-arm64-v8a-install libsvm-armeabi-v7a-install + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 + ![thirdparty_install_dir](pic/libsvm_install_dir.jpg) +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + ``` + #将三方库加入工程中 + add_library(svm SHARED IMPORTED) + set_target_properties(svm + PROPERTIES IMPORTED_LOCATION + ${CMAKE_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libsvm.so) + target_link_libraries(entry PUBLIC libace_napi.z.so svm) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libsvm-${OHOS_ARCH}-install/include) + ``` + ![libsvm_usage](pic/libsvm_usage.jpg) +## 测试三方库 +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../tools/README.md#ci环境准备) + +- 将编译生成的svm-train、svm-scale、svm-predict可执行文件及音频测试文件test.data准备好 + +- 将准备好的文件推送到开发板,在windows命令行进行如下操作 + + ``` + hdc_std shell mount -o remount,rw / #修改系统权限为可读写 + hdc_std file send svm-train /data #将可执行文件推入开发板data目录 + hdc_std file send svm-scale /data + hdc_std file send svm-predict /data + hdc_std file send libc++_shared.so /system/lib64 + hdc_std file send libsvm.so /system/lib64 + hdc_std file send test.data /data #将测试文件推入开发板data目录 + hdc_std shell #进入开 发板 + chmod 777 svm-train #添加权限 + chmod 777 svm-scale #添加权限 + chmod 777 svm-predict #添加权限 + ./svm-scale /data/test.data > /data/test.scale # 执行测试用例 + ./svm-train /data/test.scale /data/test.model + ./svm-predict /data/test.scale /data/test.model /data/test.predict + ``` + + ![libsvm_test](pic/libsvm_test.jpg) + +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) diff --git a/thirdparty/libsvm/docs/pic/libsvm_install_dir.jpg b/thirdparty/libsvm/docs/pic/libsvm_install_dir.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4732bee0c33d8709a9d7cd782f1cd2cfaa658bb6 Binary files /dev/null and b/thirdparty/libsvm/docs/pic/libsvm_install_dir.jpg differ diff --git a/thirdparty/libsvm/docs/pic/libsvm_test.jpg b/thirdparty/libsvm/docs/pic/libsvm_test.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7814ebbaeba85e675e42f577225e50d6cd0cb140 Binary files /dev/null and b/thirdparty/libsvm/docs/pic/libsvm_test.jpg differ diff --git a/thirdparty/libsvm/docs/pic/libsvm_usage.jpg b/thirdparty/libsvm/docs/pic/libsvm_usage.jpg new file mode 100644 index 0000000000000000000000000000000000000000..382ac8daa928509992261a49175c4e2cf1926f20 Binary files /dev/null and b/thirdparty/libsvm/docs/pic/libsvm_usage.jpg differ