diff --git a/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/BUILD.gn b/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/BUILD.gn index f40a29794041d7194bc06dd91cddfbf18ef8096e..2bc2ee12db996191b17d9754943ef8a8d649b486 100644 --- a/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/BUILD.gn +++ b/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/BUILD.gn @@ -14,53 +14,52 @@ import("//build/lite/config/component/lite_component.gni") executable("ImageRecognition_LocalAI_sample") { sources = [ - "src/main.cpp", - "src/wpa_work.c", + "//third_party/cJSON/cJSON.c", + "//third_party/cJSON/cJSON_Utils.c", "src/camera.cpp", - "src/local_net_udp.c", - "src/local_net_dlist.c", "src/local_net_communication.c", - "src/local_net_utils.c", + "src/local_net_dlist.c", "src/local_net_message.c", - "//third_party/cJSON/cJSON.c", - "//third_party/cJSON/cJSON_Utils.c", + "src/local_net_udp.c", + "src/local_net_utils.c", + "src/main.cpp", + "src/wpa_work.c", ] cflags = [ "-Wall" ] cflags_cc = cflags include_dirs = [ - "//base/startup/syspara_lite/interfaces/kits", - "//third_party/wpa_supplicant/wpa_supplicant-2.9/src/common", - "//third_party/EasyPR/include", - "//third_party/zxing-cpp/core/src", - "//third_party/zxing-cpp/cli/src", - "include" + "//base/startup/syspara_lite/interfaces/kits", + "//third_party/wpa_supplicant/wpa_supplicant-2.9/src/common", + "//third_party/cJSON", + "//third_party/EasyPR/include", + "//third_party/zxing-cpp/core/src", + "//third_party/zxing-cpp/cli/src", + "include", ] ldflags = [ "-lstdc++" ] ldflags += [ "-lpthread" ] ldflags += [ "-Wl,-rpath-link=$ohos_root_path/$root_out_dir" ] - ldflags += [ + ldflags += [ "-lwpa", "-lwpa_client", "-lsysparam", "-lpms_client", "-leasyPR", - "-lzxing_cpp" + "-lzxing_cpp", ] deps = [ "//foundation/multimedia/camera_lite/frameworks:camera_lite", - "//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite", "//foundation/multimedia/media_lite/frameworks/player_lite:player_lite", + "//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite", + "//third_party/EasyPR:easypr", "//third_party/bounds_checking_function:libsec_shared", "//third_party/wpa_supplicant/wpa_supplicant-2.9:wpa_supplicant", - "//third_party/EasyPR:easypr", "//third_party/zxing-cpp:zxing_cpp", ] output_name = "localAI_sample" } lite_component("ImageRecognition_LocalAI") { - features = [ - ":ImageRecognition_LocalAI_sample", - ] + features = [ ":ImageRecognition_LocalAI_sample" ] } diff --git a/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/src/main.cpp b/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/src/main.cpp index b7b98cf2b6e3ac584616b893571021e828c85486..33d178bc533b39b4303e4039666a6d5cb63d2cfb 100644 --- a/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/src/main.cpp +++ b/dev/team_x/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI/src/main.cpp @@ -13,14 +13,7 @@ * limitations under the License. */ - -#include "log.h" -#include "camera.h" -#include "wpa_work.h" -#include "local_net_udp.h" -#include "local_net_communication.h" -#include "cJSON.h" -#include "interface.h" +static constexpr int USE_PARKING_MODE = 0; #include #include @@ -32,9 +25,22 @@ #include #include +#if (USE_PARKING_MODE) +#include "wpa_work.h" +#include "local_net_udp.h" +#include "local_net_communication.h" +#include "cJSON.h" +#endif + +#include "camera.h" +#include "log.h" +#include "interface.h" + using namespace std; -static const char *g_easyPrModlePath = "/userdata/model"; +static const char *g_easyPrModlePath = "/userdata/model/"; + +#if (USE_PARKING_MODE) static bool g_runAiSwitch = false; @@ -193,5 +199,41 @@ int main(int argc, char **argv) MainLoop(); + PlateDeinit(); + return 0; } + +#else + +int main(void) +{ + char input; + + InitCamera(); + PlateInit(g_easyPrModlePath); + sleep(2); // sleep 2 senconds to wait camera init ok! + + while (cin >> input) { + switch (input) { + case '1': + RunAICamera(); + break; + case '2': { + Beep("/sdcard/start_lpr.mp4"); + char licensePlate[32] = {0}; + int ret = GetPlateString(IMG_PATH, licensePlate); + SAMPLE_INFO("ret -> %d, licensePlate->%s", ret, licensePlate); + break; + } + default: + break; + } + } + + PlateDeinit(); + + return 0; +} + +#endif \ No newline at end of file diff --git a/docs/GreyWolf_ImageRecognition_LocalAI/README.md b/docs/GreyWolf_ImageRecognition_LocalAI/README.md index 15f0e5c04be7911752a561220b1b1232f7ea5c4b..91e440c0b92cad4e3ee4f44ba8c8f6e654e04bd1 100644 --- a/docs/GreyWolf_ImageRecognition_LocalAI/README.md +++ b/docs/GreyWolf_ImageRecognition_LocalAI/README.md @@ -2,9 +2,9 @@ ## 简介 -本文介绍如何在OpenHarmony 3.1 Release 小型系统上[实现车牌识别](../../dev/team_x/GreyWolf_ImageRecognition_LocalAI)。本样例通过语音播放、相机拍照、opencv识别车牌、获取识别结果并通过串口显示。 +本文介绍如何在OpenHarmony 3.2 beta1 小型系统上[实现车牌识别](../../dev/team_x/GreyWolf_ImageRecognition_LocalAI)。本样例通过语音播放、相机拍照、opencv识别车牌、获取识别结果并通过串口显示。 -![](media/display.gif) +![display](media/display.gif) ## 快速上手 @@ -16,56 +16,55 @@ ### 准备开发环境 -#### 安装必备软件 +#### 安装必备软件 开发基础环境由windows 工作台和Linux 编译服务器组成。windows 工作台可以通过samba 服务或ssh 方式访问Linux编译服务器。其中windows 工作台用来烧录和代码编辑,Linux编译服务器用来编译OpenHarmony代码,为了简化步骤,Linux编译服务器推荐安装Ubuntu20.04。 -##### 安装和配置Python +##### 安装和配置Python - 打开Linux终端。 - - 输入如下命令,查看python版本号,需要使用python3.7以上版本,否则参考 [系统基础环境搭建](https://gitee.com/openharmony/docs/blob/OpenHarmony_1.0.1_release/zh-cn/device-dev/quick-start/搭建系统基础环境.md)。 - ``` + ```shell python3 --version ``` - 安装并升级Python包管理工具(pip3)。 - ``` + ```shell sudo apt-get install python3-setuptools python3-pip -y sudo pip3 install --upgrade pip ``` -##### 安装hb +##### 安装hb - 运行如下命令安装hb - ``` + ```shell python3 -m pip install --user ohos-build ``` - 将hb加入系统环境变量 - ``` + ```shell vim ~/.bashrc ``` 将以下命令拷贝到.bashrc文件的最后一行,保存并退出。 - ``` + ```shell export PATH=~/.local/bin:$PATH ``` 执行如下命令更新环境变量。 - ``` + ```shell source ~/.bashrc ``` - 测试hb安装结果 执行"hb -h",有打印以下信息即表示安装成功. - ``` + ```shell usage: hb OHOS build system positional arguments: @@ -82,12 +81,12 @@ 本样例hb版本为0.2.0,如果当前hb版本不是0.2.0,需要替换hb版本,步骤如下(该步骤必须在openharmony的工程根目录下执行): - ``` + ```shell pip3 uninstall ohos_build pip3 install build/lite ``` -#### 安装交叉编译环境 +#### 安装交叉编译环境 在Linux编译服务器上搭建好基础开发环境后,需要安装OpenHarmony 编译Hi3518平台特有的开发环境。 @@ -95,72 +94,72 @@ 查看shell是否为bash,在终端运行如下命令 -``` +```shell ls -l /bin/sh ``` 如果显示为“/bin/sh -> bash”则为正常,否则请按以下方式修改: -``` +```shell sudo rm -rf /bin/sh sudo ln -s /bin/bash /bin/sh ``` -##### 安装编译依赖基础软件 +##### 安装编译依赖基础软件 -``` +```shell sudo apt-get install build-essential && sudo apt-get install gcc && sudo apt-get install g++ && sudo apt-get install make && sudo apt-get install zlib* && sudo apt-get install libffi-dev ``` -##### 安装文件打包工具 +##### 安装文件打包工具 - 安装dosfstools - ``` + ```shell sudo apt-get install dosfstools ``` - 安装mtools - ``` + ```shell sudo apt-get install mtools ``` - 安装mtd-utils - ``` + ```shell sudo apt-get install mtd-utils ``` -##### 安装hc-gen +##### 安装hc-gen - 下载hc-gen工具:[下载地址](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fharmonyos%2Fcompiler%2Fhc-gen%2F0.65%2Flinux%2Fhc-gen-0.65-linux.tar)。 - 解压hc-gen安装包到Linux服务器~/hc-gen路径下。 - ``` + ```shell tar -xvf hc-gen-0.65-linux.tar -C ~/ ``` - 设置环境变量。 - ``` + ```shell vim ~/.bashrc ``` 将以下命令拷贝到.bashrc文件的最后一行,保存并退出。 - ``` + ```shell export PATH=~/hc-gen:$PATH ``` - 使环境变量生效。 - ``` + ```shell source ~/.bashrc ``` -##### 安装LLVM +##### 安装LLVM **openharmony3.1及之后的版本不需要手动安装LLVM,可跳过此步骤。** @@ -168,25 +167,25 @@ sudo apt-get install build-essential && sudo apt-get install gcc && sudo apt-get - 解压LLVM安装包至~/llvm路径下。 - ``` + ```shell tar -zxvf llvm.tar -C ~/ ``` - 设置环境变量。 - ``` + ```shell vim ~/.bashrc ``` 将以下命令拷贝到.bashrc文件的最后一行,保存并退出。 - ``` + ```shell export PATH=~/llvm/bin:$PATH ``` - 使环境变量生效。 - ``` + ```shell source ~/.bashrc ``` @@ -199,45 +198,45 @@ sudo apt-get install build-essential && sudo apt-get install gcc && sudo apt-get - 提前注册准备码云gitee账号。 - git工具下载安装 -``` +```shell sudo apt install git sudo apt install git-lfs ``` - 生成/添加SSH密钥:生成密钥 使用gitee账号绑定的邮箱生成密钥对 -``` +```shell ssh-keygen -t ed25519 -C "xxxxx@xxxxx.com" ``` - 查看生成的密钥 -``` +```shell cat ~/.ssh/id_ed25519.pub ``` - 复制生成后的 ssh key,返回gitee个人主页,通过主页 「个人设置」->「安全设置」->「SSH 公钥」 ,将生成的“SSH密钥”添加到仓库中。 - 配置git用户信息 -``` +```shell git config --global user.name "yourname" git config --global user.email "your-email-address" git config --global credential.helper store ``` -##### 准备repo +##### 准备repo -``` +```shell curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo ## 如果没有权限可以,可先将repo下载到当前目录在拷贝 chmod a+x /usr/local/bin/repo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests ``` -##### 准备系统源码 +##### 准备系统源码 -本样例是基于OpenHarmony3.2 Beta版本开发的,所以需要下载OpenHarmony3.2 Beta版。 +本样例是基于OpenHarmony3.2 Beta1版本开发的,所以需要下载OpenHarmony3.2 Beta1版。 -``` +```shell mkdir ~/OpenHarmony3.2 cd ~/OpenHarmony3.2 repo init -u git@gitee.com:openharmony/manifest.git -b OpenHarmony-3.2-Beta1 --no-repo-verify @@ -245,13 +244,13 @@ repo sync -c repo forall -c 'git lfs pull' ``` -##### 准备开发板适配代码 +##### 准备开发板适配代码 具体仓库地址: [knowledge_demo_travel](https://gitee.com/openharmony-sig/knowledge_demo_travel) 通过git命令下载并拷贝道:OpenHarmony对应目录 -``` +```shell cd ~ git clone https://gitee.com/openharmony-sig/knowledge_demo_travel.git --depth=1 cp -raf knowledge_demo_travel/dev/teamx/GreyWolf_ImageRecognition_LocalAI/ImageRecognition_LocalAI ~/OpenHarmony3.2/applications/sample/camera/ @@ -259,7 +258,7 @@ cp -raf knowledge_demo_travel/dev/teamx/GreyWolf_ImageRecognition_LocalAI/ImageR ##### 准备三方库zxing-cpp代码 -``` +```shell cd ~ git clone git@gitee.com:zhong-luping/ohos_zxing_cpp.git cp -raf ohos_zxing_cpp/zxing-cpp ~/OpenHarmony3.1/third_party/ @@ -267,7 +266,7 @@ cp -raf ohos_zxing_cpp/zxing-cpp ~/OpenHarmony3.1/third_party/ ##### 准备EasyPR代码 -``` +```shell cd ~ git clone git@gitee.com:zhong-luping/ohos_easy-pr.git cp -raf ohos_easy-pr/EasyPR ~/OpenHarmony3.2/third_party/ @@ -275,7 +274,7 @@ cp -raf ohos_easy-pr/EasyPR ~/OpenHarmony3.2/third_party/ ##### 准备OpenCV代码 -``` +```shell cd ~ git clone git@gitee.com:zhong-luping/ohos_opencv.git cp -raf ohos_opencv/opencv ~/OpenHarmony3.2/third_party/ @@ -294,7 +293,7 @@ cp -raf ohos_opencv/opencv ~/OpenHarmony3.2/third_party/ 在init字段中添加"start localAI_sample" -``` +```shell "name" : "init", "cmds" : [ "start apphilogcat", @@ -309,8 +308,8 @@ cp -raf ohos_opencv/opencv ~/OpenHarmony3.2/third_party/ 在server字段中添加服务 -``` - { +```shell + { "name" : "localAI_sample", "path" : ["/bin/localAI_sample"], "uid" : 10, @@ -327,7 +326,7 @@ cp -raf ohos_opencv/opencv ~/OpenHarmony3.2/third_party/ build/lite/components/applications.json文件添加应用: -``` +```shell { "component": "localAI", "description": "localAI samples.", @@ -352,7 +351,7 @@ build/lite/components/applications.json文件添加应用: vendor/hisilicon/hispark_taurus/config.json文件applications子系统中添加编译构建: -``` +```shell { "subsystem": "applications", "components": [ @@ -364,13 +363,11 @@ vendor/hisilicon/hispark_taurus/config.json文件applications子系统中添加 }, ``` - - ### 编译 进入到OpenHarmony系统源码根目录下,输入hb set并选择ipcamera_hispark_taurus -``` +```shell hb set // 如果是第一次编译,Input code path 命令行中键入"./" 指定OpenHarmony工程编译根目录后 回车。 hb build -f // 开始全量编译。(hb build 为增量编译) ``` @@ -389,11 +386,11 @@ hb build -f // 开始全量编译。(hb build 为增量编译) 最后重新上电即可烧录。 -![](media/hitoo_burn.png) +![burn](media/hitoo_burn.png) 烧录成功后,使用串口连接。输入如下启动参数。 -``` +```shell setenv bootcmd "mmc read 0x0 0x80000000 0x800 0x4800; go 0x80000000"; setenv bootargs "console=ttyAMA0,115200n8 root=emmc fstype=vfat rootaddr=10M rootsize=60M rw"; save @@ -412,11 +409,11 @@ reset 将摄像头对准车牌 -![](media/licensePlate.png) +![licensePlate](media/licensePlate.png) -在串口中输入1拍照、输入2将照片提交至百度云进行识别,最终返回识别结果。 +在串口中输入1拍照、输入2进行车牌识别识别,最终返回识别结果。 -![](media/getLicensePlate.png) +![getLicensePlate](media/getLicensePlate.png) ## 样例联动 @@ -430,4 +427,3 @@ reset - [L1上运行开源项目车牌识别及移植opencv库](../GreyWolf_EasyPR/readme.md) - [知识体系](https://gitee.com/openharmony-sig/knowledge) -