提交 7b75d2f5 编写于 作者: C caiyan.cai 提交者: yilu.myl

fix STC ERROR

Signed-off-by: Ncaiyan.cai <caiyan.cai@alibaba-inc.com>
上级 b900b8b7
<br/>
<div align="center">
<img src="https://img.alicdn.com/tfs/TB1e1U7vyAnBKNjSZFvXXaTKXXa-973-200.png" height="60">
</div>
<br/>
<div align="center">
[![Join the chat at https://gitter.im/aliosthings/Lobby](https://img.shields.io/gitter/room/aliosthings/Lobby.svg?style=flat-square)](https://gitter.im/aliosthings/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
</div>
<br/>
**AliOS Things**发布于[2017年杭州云栖大会](https://yunqi.aliyun.com), 是 AliOS 家族旗下的、面向IoT领域的、高可伸缩的物联网操作系统,于2017年10月20号宣布在[github](https://github.com/alibaba/AliOS-Things)上开源,当前最新的版本是 **AliOS Things 3.3**
## 架构总览
**AliOS Things** 支持多种CPU架构,包括:ARM,C-Sky,MIPS,RISCV,rl78,rx600,xtensa等。
**AliOS Things** 适配了分层架构和组件架构。包括以下部分:
- BSP: 板级支持包
- HAL: 硬件适配层,包括WiFi,蓝牙,I2C, SPI, UART,Flash 等
- Kernel: 包括Rhino RTOS 内核,VFS,KV Storage,CLI,C++ 等
- Network: 包括LwIP 轻量级TCP/IP协议栈,uMesh 自组网协议栈,BLE 低功耗蓝牙协议栈,LoRaWAN 协议栈,AT Commands Module 等
- Security: 包括TLS(mbedTLS and cutomized iTLS),ID2,SST(Trusted Storage),Crypto,TEE(Trusted Execution Environment) 等
- AOS API: AliOS Things 提供给应用软件和组件的API
- VFS驱动框架:设备驱动提供给组件和应用的服务接口
- Component: 阿里巴巴增值和常用的物联网组件,包括LinkSDK,OTA(安全差分升级),ulog(日志服务),uData(传感器框架),uLocation(定位框架),WiFi配网 等
- Application: 丰富的示例代码
所有的模块都作为组件的形式存在,通过yaml进行配置,应用程序可以很方便的选择需要的组件。
## AliOS Things 3.3新功能介绍
- 统一的VFS接入方式,更标准的应用开发模式
- 更小的系统,yaml构建方式更直观
- 更全面的JavaScript轻应用接口支持
- 全面完善的组件、解决方案和系统文档。格式更规范与开发者友好
- 升级了LinkSDK,新增设备引导服务、设备诊断、日志上报功能;移除CoAP、Http2、Wi-Fi配网及设备绑定的支持
- 新增蓝牙配网、Wi-Fi Camera、OLED等组件,解决方案能直接调用
## AliOS Things 3.3支持硬件
**AliOS Things 3.3**版本支持官方已适配如下硬件
- HaaS100
- HaaS EDU K1
## 文档
### 快速上手
[HaaS100 快速开始](./HaaS100_Quick_Start.md)
[HaaS EDU K1 快速开始](./HaaS_EDU_K1_Quick_Start.md)
### 文档中心
请到HaaS官方网站 [文档中心](https://haas.iot.aliyun.com/)查看。
### 贡献代码
请参考:[Contributing Guideline](https://github.com/alibaba/AliOS-Things/wiki/contributing)
### 物联网平台
AliOS Things 能帮助你更加快速地接入[阿里云物联网平台](https://iot.console.aliyun.com/quick_start)
## 社区
* [技术交流群(钉钉)](https://img.alicdn.com/imgextra/i3/O1CN017fYxQq1qXL0gLsnGg_!!6000000005505-2-tps-1658-682.png)
* [HaaS技术社区](https://blog.csdn.net/HaaSTech)
## License
AliOS Things 开源源码遵循 [Apache 2.0 license](LICENSE) 开源协议。
......@@ -51,6 +51,7 @@ source_file:
> helloworld_demo组件的application_start中添加代码
```sh
/*init network service*/
event_service_init(NULL);
netmgr_service_init(NULL);
```
......@@ -70,12 +71,12 @@ source_file:
1. 创建Bucket时地域选择“上海”
2. 读写权限选择“公共读”
```
## aiconfig.h中配置OSS信息
## ucloud_ai/package.yaml中配置OSS信息
```sh
OSS_ACCESS_KEY "<Your-Access-Key>"
OSS_ACCESS_SECRET "<Your-Access-Secret>"
OSS_ENDPOINT "oss-cn-shanghai.aliyuncs.com"
OSS_BUCKET "Your-OSS-Bucket"
OSS_ACCESS_KEY: "Your-Access-Key"
OSS_ACCESS_SECRET: "Your-Access-Secret"
OSS_ENDPOINT: "Your-OSS-Endpoint"
OSS_BUCKET: "Your-OSS-Bucket"
KEY以及SECRET获取链接: https://usercenter.console.aliyun.com/#/accesskey
ENDPOINT使用默认即可,BUCKET请使用你创建好的Bucket名称
......@@ -85,8 +86,9 @@ ENDPOINT使用默认即可,BUCKET请使用你创建好的Bucket名称
> helloworld_demo组件的package.yaml中添加
```sh
depends:
- ai_agent: dev_aos # helloworld_demo中引入ai_agent组件
- netmgr: dev_aos # helloworld_demo中引入netmgr组件
- ai_agent: dev_aos # helloworld_demo中引入ai_agent组件
- netmgr: dev_aos # helloworld_demo中引入netmgr组件
- littlefs: dev_aos # helloworld_demo中引入littlefs组件
```
## 编译
......@@ -106,152 +108,241 @@ aos burn -f hardware/chip/haas1000/release/write_flash_tool/ota_bin/littlefs.bin
### CLI命令行输入:
```sh
aiagent -m 0 # 人脸比对
aiagent -e ucloud-ai -m 0 # 人脸比对
```
> CLI关键日志:
```sh
TODO
Facebody comparing result:
confidence: 84.6
location at x: 159, y: 76, w: 143, h: 194
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 1 # 人物动漫化
aiagent -e ucloud-ai -m 1 # 人物动漫化
```
> CLI关键日志:
```sh
TODO
Generate human anime style result:
url: http://vibktprfx-prod-prod-aic-gd-cn-shanghai.oss-cn-shanghai.aliyuncs.com/person-image-cartoonizer/4F10FBB8-19DC-476B-A51D-458CD180A24F_07f2_20210331-142711.jpg?Expires=1617202631&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=YCLva1stK27Cn657nMeYhgFt7h4%3D
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 2 # 表情识别
aiagent -e ucloud-ai -m 2 # 表情识别
```
> CLI关键日志:
```sh
TODO
Recognize expression result:
type: anger, probability: 1.0
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 3 # 目标检测
aiagent -e ucloud-ai -m 3 # 目标检测
```
> CLI关键日志:
```sh
TODO
Detect object result:
type: potted plant, Score: 0.4, x: 35, y: 274, w: 185, h: 443
Detect object result:
type: potted plant, Score: 0.5, x: 663, y: 121, w: 847, h: 457
Detect object result:
type: monitor, Score: 0.6, x: 250, y: 43, w: 670, h: 439
Detect object result:
type: keyboard, Score: 0.5, x: 239, y: 435, w: 489, h: 485
Detect object result:
type: keyboard, Score: 0.3, x: 241, y: 428, w: 639, h: 506
Detect object result:
type: mouse, Score: 0.2, x: 660, y: 479, w: 750, h: 528
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 4 # 主体检测
aiagent -e ucloud-ai -m 4 # 主体检测
```
> CLI关键日志:
```sh
TODO
Detect main body result:
main body location x: 1, y: 31, w: 461, h: 528
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 5 # 通用分割
aiagent -e ucloud-ai -m 5 # 通用分割
```
> CLI关键日志:
```sh
TODO
Segment common image result:
url: http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_humansegmenter/2021-3-31/invi_humansegmenter_016172056326493133388_avpTpm.jpg?Expires=1617207432&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=WREOAoBUIvpLSyygGxKPfi82HfI%3D
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 6 # 面部分割
aiagent -e ucloud-ai -m 6 # 面部分割
```
> CLI关键日志:
```sh
TODO
Segment face result:
image url: http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_HeadSegmenter/2021-3-31/invi_HeadSegmenter_016172056422754285967296_yRhj6C.png?Expires=1617207442&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=wR7GUxqrrwRF9u3mCJ%2BNDhAPCzk%3D
location at x: 153, y: 66, w: 160, h: 209
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 7 # 身份证证明识别
aiagent -e ucloud-ai -m 7 # 身份证证明识别
```
> CLI关键日志:
```sh
TODO
Recognize identity card face side result:
address: 江苏省南京市浦口区天天小区1栋11号
nationality: 汉
card location: x0: 1126563840, y0: 1126563840
card location: x1: 0, y1: 0
card location: x2: 0, y2: 0
card location: x3: 0, y3: 0
face location: x0: 1126563840, y0: 1126563840
face location: x1: 0, y1: 0
face location: x2: 0, y2: 0
face location: x3: 0, y3: 0
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 8 # 身份证反面识别
aiagent -e ucloud-ai -m 8 # 身份证反面识别
```
> CLI关键日志:
```sh
TODO
Recognize identity card back side result:
start date: 20131010
issue: 杭州市公安局余杭分局
end date: 20231010
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 9 # 银行卡识别
aiagent -e ucloud-ai -m 9 # 银行卡识别
```
> CLI关键日志:
```sh
TODO
bankName: 中国工商银行
cardNumber: 6212262315007683105
validDate: 07/26
Recognize bank card result:
bank name: 中国工商银行
card number: 6212262315007683105
valid date: 07/26
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 10 # 文本识别
aiagent -e ucloud-ai -m 10 # 文本识别
```
> CLI关键日志:
```sh
TODO
Recognize character result:
text: 《爆炸新闻》
probability: 1.0
text area: left: 141, top: 442, weight: 89, height: 20
Recognize character result:
text: 19
probability: 1.0
text area: left: 115, top: 173, weight: 100, height: 109
Recognize character result:
text: 豆瓣评分7.1
probability: 0.9
text area: left: 168, top: 447, weight: 98, height: 18
Recognize character result:
text: 2019||美国|加拿大|剧情|传记
probability: 0.5
text area: left: 181, top: 450, weight: 241, height: 17
Recognize character result:
text: 杰伊·罗奇 导演
probability: 0.9
text area: left: 216, top: 454, weight: 112, height: 18
Recognize character result:
text: 2021年2月星期五
probability: 1.0
text area: left: 231, top: 187, weight: 150, height: 18
Recognize character result:
text: 农历正月初八
probability: 1.0
text area: left: 261, top: 193, weight: 104, height: 18
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 11 # 垃圾分类
aiagent -e ucloud-ai -m 11 # 垃圾分类
```
> CLI关键日志:
```sh
TODO
Recognize rubbish result:
rubbish: 塑料饮料瓶
rubbish score: 1.0
category: 可回收垃圾
category score: 1.0
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 12 # 水果检测
aiagent -e ucloud-ai -m 12 # 水果检测
```
> CLI关键日志:
```sh
TODO
Recognize fruits result:
fruit name: 橙子
fruit score: 0.8
fruit location: x: 214, y: 44, w: 509, h: 438
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 13 # 图像人体擦除
aiagent -e ucloud-ai -m 13 # 图像人体擦除
```
> CLI关键日志:
```sh
TODO
Erase person result:
url: http://algo-app-isr-lab-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/remove-person/2021-03-31_15%3A34%3A17.959810_person_org.jpg?Expires=1617206658&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=jFwwnSYOw2fXev1%2Fm5az4JBa%2B5Q%3D
aiagent comp test success!
```
### CLI命令行输入:
```sh
aiagent -m 14 # 风格迁移
aiagent -e ucloud-ai -m 14 # 风格迁移
```
> CLI关键日志:
```sh
TODO
Extend image style result:
out image url: http://viapi-cn-shanghai-dha-filter.oss-cn-shanghai.aliyuncs.com/upload/result_/2021-3-31/invi__016172056608421021961_1mdK2W.jpg?Expires=1617207460&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=3t8Q%2BwTAo6Lib9utaoMrWUJX6Iw%3D
aiagent comp test success!
```
# 注意事项
......@@ -260,3 +351,18 @@ NA
# FAQ
NA
如果遇到:
> error code: InvalidAction.NotFound
请确认Endpoint是否设置正确
> error code: InvalidApi.NotPurchase
请确认是否在vision.aliyun.com开通相应功能
> tlefs_vfs.c:677:error: lfs_vfs_open /data/ucloud_ai_image/object.jpg failed, ret - -2
请确认是否有拷贝图片到hardware/chip/haas1000/prebuild/data/ucloud_ai_image目录。
如果有,可能是文件系统存储空间不够,此时请执行:
1. 在ucloud_ai/package.yaml中屏蔽prebuild_script: cp_resources.py;
2. 删除ucloud_ai_image中其他文件,仅保留测试case使用的图片文件;
3. 再重新编译烧录。
\ No newline at end of file
......@@ -30,7 +30,7 @@ typedef struct _aiagent_engine_t {
void (*ai_engine_uninit) (struct _aiagent_engine_t *eng);
/*run ai engine model*/
void (*ai_engine_model_infer) (struct _aiagent_engine_t *eng);
int (*ai_engine_model_infer) (struct _aiagent_engine_t *eng);
/*free ai engine*/
void (*ai_engine_free) (struct _aiagent_engine_t *eng);
......
......@@ -5,16 +5,7 @@
#ifndef _AI_CONFIG_H_
#define _AI_CONFIG_H_
/*开发者请将你的OSS Access Key、Secret、Endpoint以及Bucket名称在这里进行替换*/
#define OSS_ACCESS_KEY "<Your-Access-Key>"
#define OSS_ACCESS_SECRET "<Your-Access-Secret>"
#define OSS_ENDPOINT "oss-cn-shanghai.aliyuncs.com"
#define OSS_BUCKET "<Your-OSS-Bucket>"
// Choose AI Capability
#define AI_MODEL AI_MODEL_COMPARING_FACEBODY
// My face oss path
#define MYFACE_PATH "http://oss-ai-dev.oss-cn-shanghai.aliyuncs.com/your-face.jpg"
#endif // _AI_CONFIG_H_
......@@ -47,7 +47,7 @@ build_config:
source_file:
- src/*.c
- src/engine/*.c
- src/example/aiagent_example.c
# - src/example/aiagent_example.c
## 第五部分:配置信息
def_config: # 组件的可配置项
......
......@@ -48,6 +48,7 @@ int32_t aiagent_service_uninit(void)
*/
int32_t aiagent_service_model_infer(char *src1, char *src2, ai_engine_cb_t cb)
{
int32_t ret;
aiagent_engine_t *eng = aiagent_get_engine();
if (!eng) {
LOGE(TAG, "aiagent get engine name fail\n");
......@@ -57,10 +58,10 @@ int32_t aiagent_service_model_infer(char *src1, char *src2, ai_engine_cb_t cb)
eng->callback = cb;
eng->src1 = src1;
eng->src2 = src2;
eng->ai_engine_model_infer(eng);
ret = eng->ai_engine_model_infer(eng);
LOG("aiagent_service_model_infer done\n");
return 0;
return ret;
}
/*
......
......@@ -34,6 +34,12 @@ int32_t ucloud_ai_engine_init(aiagent_engine_t *eng)
if (!eng)
return -1;
ret = ucloud_ai_init();
if (ret < 0) {
LOGE(TAG, "ucloud_ai_connect failed, ret: %d\n", ret);
return -1;
}
ucloud_ai_set_key_secret(OSS_ACCESS_KEY, OSS_ACCESS_SECRET);
ucloud_ai_set_oss_endpoint(OSS_ENDPOINT);
ucloud_ai_set_oss_bucket(OSS_BUCKET);
......@@ -44,7 +50,7 @@ int32_t ucloud_ai_engine_uninit(aiagent_engine_t *eng)
if (!eng)
return -1;
return 0;
return ucloud_ai_uninit();
}
int ucloud_ai_engine_model_infer(aiagent_engine_t *eng)
......@@ -55,65 +61,66 @@ int ucloud_ai_engine_model_infer(aiagent_engine_t *eng)
ucloud_ai_cb_t cb = (ucloud_ai_cb_t)eng->callback;
switch (eng->model) {
#ifdef CONFIG_ALICLOUD_FACEBODY_ENABLE
case AI_MODEL_COMPARING_FACEBODY:
case UCLOUD_AI_MODEL_COMPARING_FACEBODY:
ucloud_ai_facebody_comparing_face(eng->src1, eng->src2, cb);
break;
case AI_MODEL_GENERATE_HUMAN_ANIME_STYLE:
case UCLOUD_AI_MODEL_GENERATE_HUMAN_ANIME_STYLE:
ucloud_ai_facebody_generate_human_anime_style(eng->src1, cb);
break;
case AI_MODEL_RECOGNIZE_EXPRESSION:
case UCLOUD_AI_MODEL_RECOGNIZE_EXPRESSION:
ucloud_ai_facebody_recognize_expression(eng->src1, cb);
break;
#endif
#ifdef CONFIG_ALICLOUD_OBJECTDET_ENABLE
case AI_MODEL_DETECT_OBJECT:
case UCLOUD_AI_MODEL_DETECT_OBJECT:
ucloud_ai_objectdet_detect_object(eng->src1, cb);
break;
case AI_MODEL_DETECT_MAIN_BODY:
case UCLOUD_AI_MODEL_DETECT_MAIN_BODY:
ucloud_ai_objectdet_detect_main_body(eng->src1, cb);
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGESEG_ENABLE
case AI_MODEL_SEGMENT_COMMON_IMAGE:
case UCLOUD_AI_MODEL_SEGMENT_COMMON_IMAGE:
ucloud_ai_imageseg_segment_common_image(eng->src1, cb);
break;
case AI_MODEL_SEGMENT_FACE:
case UCLOUD_AI_MODEL_SEGMENT_FACE:
ucloud_ai_imageseg_segment_face(eng->src1, cb);
break;
#endif
#ifdef CONFIG_ALICLOUD_OCR_ENABLE
case AI_MODEL_RECOGNIZE_IDENTITY_CARD_FACE_SIDE:
case UCLOUD_AI_MODEL_RECOGNIZE_IDENTITY_CARD_FACE_SIDE:
ucloud_ai_ocr_recognize_identity_card_face_side(eng->src1, cb);
break;
case AI_MODEL_RECOGNIZE_IDENTITY_CARD_BACK_SIDE:
case UCLOUD_AI_MODEL_RECOGNIZE_IDENTITY_CARD_BACK_SIDE:
ucloud_ai_ocr_recognize_identity_card_back_side(eng->src1, cb);
break;
case AI_MODEL_RECOGNIZE_BANK_CARD:
case UCLOUD_AI_MODEL_RECOGNIZE_BANK_CARD:
ucloud_ai_ocr_recognize_bank_card(eng->src1, cb);
break;
case AI_MODEL_RECOGNIZE_CHARACTER:
case UCLOUD_AI_MODEL_RECOGNIZE_CHARACTER:
ucloud_ai_ocr_recognize_character(eng->src1, cb);
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGERECOG_ENABLE
case AI_MODEL_CLASSIFYING_RUBBISH:
case UCLOUD_AI_MODEL_CLASSIFYING_RUBBISH:
ucloud_ai_imagerecog_classifying_rubbish(eng->src1, cb);
break;
case AI_MODEL_DETECT_FRUITS:
case UCLOUD_AI_MODEL_DETECT_FRUITS:
ucloud_ai_imagerecog_detect_fruits(eng->src1, cb);
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGEENHAN_ENABLE
case AI_MODEL_ERASE_PERSON:
case UCLOUD_AI_MODEL_ERASE_PERSON:
ucloud_ai_imageenhan_erase_person(eng->src1, IMAGEENHAN_ERASE_PERSON_USERMASK_URL, cb);
break;
case AI_MODEL_EXTEND_IMAGE_STYLE:
case UCLOUD_AI_MODEL_EXTEND_IMAGE_STYLE:
ucloud_ai_imageenhan_extend_image_style(eng->src1, IMAGEENHAN_EXTEND_IMAGE_STYLE_URL, cb);
break;
#endif
default:
break;
}
return 0;
}
static aiagent_engine_t *ucloud_ai_engine_create(int engineid)
......
......@@ -10,17 +10,24 @@
#endif
#define TAG "aiagent_example"
#define LOG printf
#ifdef CONFIG_ALICLOUD_FACEBODY_ENABLE
static int facebody_compare_callback(ai_result_t *result)
{
float confidence;
int x, y, w, h;
if (!result)
return -1;
confidence = result->facebody.face.confidence;
x = result->facebody.face.location.x;
y = result->facebody.face.location.y;
w = result->facebody.face.location.w;
h = result->facebody.face.location.h;
LOG("Facebody comparing result:\n");
LOG("confidence: %.1f\n", confidence);
LOG("location at x: %d, y: %d, w: %d, h: %d\n", x, y, w, h);
return 0;
}
......@@ -28,7 +35,7 @@ static int facebody_compare_callback(ai_result_t *result)
static int recognize_expression_callback(ai_result_t *result)
{
int len;
char *expression, *p_expression;
char *expression = NULL;
float face_probability;
if (!result)
......@@ -37,19 +44,11 @@ static int recognize_expression_callback(ai_result_t *result)
expression = result->facebody.expression.expression;
face_probability = result->facebody.expression.probability;
if (!expression)
if (!expression && strlen(expression) > 0)
return -1;
p_expression = strdup(expression);
if (!p_expression) {
LOGE(TAG, "p_expression strdup fail\n");
return -1;
}
LOG("Recognize expression result:\n");
LOG("type: %s, probability: %.1f\n", p_expression, face_probability);
free(p_expression);
p_expression = NULL;
LOG("type: %s, probability: %.1f\n", expression, face_probability);
return 0;
}
......@@ -62,10 +61,12 @@ static int generate_human_anime_styple_callback(ai_result_t *result)
if (!result)
return -1;
url = result->facebody.anime.url;
LOG("Generate human anime style result:\n");
LOG("url: %s\n", url);
url = result->facebody.anime.url;
if (!url && strlen(url) > 0)
return -1;
LOG("url: %s\n", url);
return ret;
}
#endif
......@@ -74,7 +75,6 @@ static int generate_human_anime_styple_callback(ai_result_t *result)
static int detect_object_callback(ai_result_t *result)
{
int len = 0;
char *p_type = NULL;
int x, y, w, h;
char *type = NULL;
float score;
......@@ -82,6 +82,7 @@ static int detect_object_callback(ai_result_t *result)
if (!result)
return -1;
LOG("Detect object result:\n");
type = result->objectdet.object.type;
score = result->objectdet.object.score;
x = result->objectdet.object.box.x;
......@@ -93,16 +94,8 @@ static int detect_object_callback(ai_result_t *result)
LOGE(TAG, "type is null\n");
return -1;
}
p_type = strdup(type);
if (!p_type) {
LOGE(TAG, "p_type strdup fail\n");
return -1;
}
LOG("Detect object result:\n");
LOG("type: %s, Score: %.1f, x: %d, y: %d, w: %d, h: %d\n", p_type, score, x, y, w, h);
free(p_type);
p_type = NULL;
LOG("type: %s, Score: %.1f, x: %d, y: %d, w: %d, h: %d\n", type, score, x, y, w, h);
return 0;
}
......@@ -130,12 +123,17 @@ static int detect_main_body_callback(ai_result_t *result)
static int segment_common_image_callback(ai_result_t *result)
{
int ret;
char *url = NULL;
int x, y, w, h;
if (!result)
return -1;
LOG("Segment common image result:\n");
LOG("url: %s\n", result->imageseg.common.url);
url = result->imageseg.common.url;
if (!url && strlen(url) > 0)
return -1;
LOG("url: %s\n", url);
return 0;
}
......@@ -145,22 +143,23 @@ static int segment_face_callback(ai_result_t *result)
int ret;
int image_len = 0;
int x, y, w, h;
int index;
char *url = NULL;
char path[32] = {0};
if (!result)
return -1;
index = result->imageseg.face.index;
LOG("Segment face result:\n");
url = result->imageseg.face.url;
x = result->imageseg.face.location.x;
y = result->imageseg.face.location.y;
w = result->imageseg.face.location.w;
h = result->imageseg.face.location.h;
LOG("Segment face result:\n");
LOG("face %d image url: %s locating at x: %d, y: %d, w: %d, h: %d\n", index, url, x, y, w, h);
if (!url && strlen(url) > 0)
return -1;
LOG("image url: %s\n", url);
LOG("location at x: %d, y: %d, w: %d, h: %d\n", x, y, w, h);
return 0;
}
......@@ -339,6 +338,8 @@ static int imagerecog_classifying_rubbish_callback(ai_result_t *result)
LOG("category: %s\n", category);
LOG("category score: %.1f\n", category_score);
}
return 0;
}
static int imagerecog_detect_fruits_callback(ai_result_t *result)
......@@ -364,6 +365,8 @@ static int imagerecog_detect_fruits_callback(ai_result_t *result)
LOG("fruit score: %.1f\n", score);
LOG("fruit location: x: %d, y: %d, w: %d, h: %d\n", x, y, w, h);
}
return 0;
}
#endif
......@@ -376,7 +379,7 @@ static int imageenhan_erase_person_callback(ai_result_t *result)
if (!result)
return -1;
LOG("Recognize fruits result:\n");
LOG("Erase person result:\n");
url = result->imageenhan.person.url;
LOG("url: %s\n", url);
......@@ -390,15 +393,22 @@ static int imageenhan_extend_image_style_callback(ai_result_t *result)
int out_image_len = 0;
char *major_url = NULL;
char *out_image_url = NULL;
char *p_major_url = NULL;
char *p_out_image_url = NULL;
if (!result)
return -1;
LOG("Extend image style result:\n");
major_url = result->imageenhan.style.majorUrl;
out_image_url = result->imageenhan.style.outImageUrl;
LOG("major url: %s\n", major_url);
LOG("out image url: %s\n", out_image_url);
LOG("Extend image style result:\n");
if (major_url && strlen(major_url) > 0) {
LOG("major url: %s\n", major_url);
}
if (out_image_url && strlen(out_image_url) > 0) {
LOG("out image url: %s\n", out_image_url);
}
return 0;
}
......@@ -413,7 +423,7 @@ static void aiagent_comp_example(int argc, char **argv)
char *image2 = NULL;
ai_engine_cb_t cb;
if (argc < 3) {
if (argc < 4) {
LOG("Please test with command: aiagent_example -m [0~14]\n");
return;
}
......@@ -429,7 +439,7 @@ static void aiagent_comp_example(int argc, char **argv)
}
if (!strncmp(argv[3], "-m", 2)) {
model_index = atoi(argv[3]);
model_index = atoi(argv[4]);
if (model_index < 0 && model_index > 14) {
LOGE(TAG, "range of model value is 0 ~ 14, please try again\n");
return;
......@@ -450,82 +460,88 @@ static void aiagent_comp_example(int argc, char **argv)
#ifdef CONFIG_ALICLOUD_FACEBODY_ENABLE
case AI_MODEL_COMPARING_FACEBODY:
cb = facebody_compare_callback;
image1 = "/data/image/face1.png";
image2 = "/data/image/face2.png";
image1 = FACE1_IMAGE;
image2 = FACE2_IMAGE;
break;
case AI_MODEL_GENERATE_HUMAN_ANIME_STYLE:
cb = generate_human_anime_styple_callback;
image1 = ANIME_IMAGE;
image2 = NULL;
break;
case AI_MODEL_RECOGNIZE_EXPRESSION:
cb = recognize_expression_callback;
image1 = "/data/image/expression.jpg";
image1 = EXPRESSION_IMAGE;
image2 = NULL;
break;
break;
#endif
#ifdef CONFIG_ALICLOUD_OBJECTDET_ENABLE
case AI_MODEL_DETECT_OBJECT:
cb = detect_object_callback;
image1 = "/data/image/object.jpg";
image1 = OBJECT_IMAGE;
image2 = NULL;
break;
case AI_MODEL_DETECT_MAIN_BODY:
cb = detect_main_body_callback;
image1 = "/data/image/mainbody.jpg";
image1 = MAINBODY_IMAGE;
image2 = NULL;
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGESEG_ENABLE
case AI_MODEL_SEGMENT_COMMON_IMAGE:
cb = segment_common_image_callback;
image1 = "/data/image/mainbody.jpg";
image1 = MAINBODY_IMAGE;
image2 = NULL;
break;
case AI_MODEL_SEGMENT_FACE:
cb = segment_face_callback;
image1 = "/data/image/face1.jpg";
image1 = FACE1_IMAGE;
image2 = NULL;
break;
#endif
#ifdef CONFIG_ALICLOUD_OCR_ENABLE
case AI_MODEL_RECOGNIZE_IDENTITY_CARD_FACE_SIDE:
cb = recognize_identity_card_face_side_callback;
image1 = "/data/image/card_face.jpg";
image1 = CARD_FACE_IMAGE;
image2 = NULL;
break;
case AI_MODEL_RECOGNIZE_IDENTITY_CARD_BACK_SIDE:
cb = recognize_identity_card_back_side_callback;
image1 = "/data/image/card_back.jpg";
image1 = CARD_BACK_IMAGE;
image2 = NULL;
break;
case AI_MODEL_RECOGNIZE_BANK_CARD:
cb = recognize_bank_card_callback;
image1 = "/data/image/bank_card.jpg";
image1 = BANK_CARD_IMAGE;
image2 = NULL;
break;
case AI_MODEL_RECOGNIZE_CHARACTER:
cb = recognize_character_callback;
image1 = "/data/image/character.jpg";
image1 = CHARACTER_IMAGE;
image2 = NULL;
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGERECOG_ENABLE
case AI_MODEL_CLASSIFYING_RUBBISH:
cb = imagerecog_classifying_rubbish_callback;
image1 = "/data/image/rubbish.jpg";
image1 = RUBBISH_IMAGE;
image2 = NULL;
break;
case AI_MODEL_DETECT_FRUITS:
cb = imagerecog_detect_fruits_callback;
image1 = "/data/image/fruits.jpg";
image1 = FRUITS_IMAGE;
image2 = NULL;
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGEENHAN_ENABLE
case AI_MODEL_ERASE_PERSON:
cb = imageenhan_erase_person_callback;
image1 = "/data/image/person_org.jpg";
image1 = PERSON_ORG_IMAGE;
image2 = NULL;
break;
case AI_MODEL_EXTEND_IMAGE_STYLE:
cb = imageenhan_extend_image_style_callback;
image1 = "/data/image/extend_style.jpg";
image1 = STYLE_IMAGE;
image2 = NULL;
break;
#endif
......
......@@ -36,7 +36,7 @@
#define FBIOGET_VSCREENINFO 0x4600
#define FBIOPUT_VSCREENINFO 0x4601
#define FBIOGET_FSCREENINFO 0x4602
#define FBIOGET_FRRAMEBUFFER 0x4603
#define FBIOGET_FRRAMEBUFFER 0x4603
#define FBIOGETCMAP 0x4604
#define FBIOPUTCMAP 0x4605
......
/*
* Copyright (C) 2015-2020 Alibaba Group Holding Limited
*/
/**
* fb_var_to_videomode - convert fb_var_screeninfo to fb_videomode
* @mode: pointer to struct fb_videomode
* @var: pointer to struct fb_var_screeninfo
*/
void fb_var_to_videomode(fb_videomode_t *mode,
const fb_var_screeninfo_t *var)
{
uint32_t pixclock, hfreq, htotal, vtotal;
mode->name = NULL;
mode->xres = var->xres;
mode->yres = var->yres;
mode->pixclock = var->pixclock;
mode->hsync_len = var->hsync_len;
mode->vsync_len = var->vsync_len;
mode->left_margin = var->left_margin;
mode->right_margin = var->right_margin;
mode->upper_margin = var->upper_margin;
mode->lower_margin = var->lower_margin;
mode->sync = var->sync;
mode->vmode = var->vmode & FB_VMODE_MASK;
mode->flag = FB_MODE_IS_FROM_VAR;
mode->refresh = 0;
if (!var->pixclock)
return;
pixclock = PICOS2KHZ(var->pixclock) * 1000;
htotal = var->xres + var->right_margin + var->hsync_len +
var->left_margin;
vtotal = var->yres + var->lower_margin + var->vsync_len +
var->upper_margin;
if (var->vmode & FB_VMODE_INTERLACED)
vtotal /= 2;
if (var->vmode & FB_VMODE_DOUBLE)
vtotal *= 2;
if (!htotal || !vtotal)
return;
hfreq = pixclock / htotal;
mode->refresh = hfreq / vtotal;
}
......@@ -301,12 +301,15 @@ void ili9341_draw_frame(ili9341_dev_t ili9341_dev, uint8_t *frame)
{
uint16_t *rgb565_frame = (uint16_t *)frame;
uint32_t bufferSize = ILI9341_HEIGHT * ILI9341_WIDTH * sizeof(uint16_t);
set_addr_window(ili9341_dev, 0, 0, ILI9341_WIDTH - 1, ILI9341_HEIGHT - 1);
unsigned char *burst_buffer = (unsigned char *)malloc(bufferSize);
for (uint32_t i = 0; i < bufferSize; i++) {
burst_buffer[i] =
(bufferSize % 2) ? rgb565_frame[i] : rgb565_frame[i] >> 8;
set_addr_window(ili9341_dev, 0, 0, ILI9341_WIDTH - 1, ILI9341_HEIGHT - 1);
for (uint32_t i = 0; i < bufferSize / 2; i++) {
burst_buffer[2 * i] = rgb565_frame[i] >> 8;
burst_buffer[2 * i + 1] = rgb565_frame[i];
}
ili9341_dc_write_bytes(ili9341_dev, DAT, burst_buffer, bufferSize);
free(burst_buffer);
}
......
......@@ -86,10 +86,10 @@ static int ili9341_blank(int blank, fb_info_t *info)
static int ili9341_pan_display(fb_var_screeninfo_t *var, fb_info_t *info)
{
int ret = 0;
printf("ili9341 pan display function:0x%x\n", *(info->screen_buffer));
printf("ili9341 pan display function:0xp\n", info->screen_buffer);
ili9341_draw_frame(dev_ili9341, info->screen_buffer);
printf("ili9341_draw_frame done\n");
return 0;
}
......@@ -113,8 +113,9 @@ static ili9341_ioctl(fb_info_t *info, unsigned int cmd, unsigned long arg)
break;
case FBIOPUT_PREFB_ADDR:
printf("fbioput buffer setting\n");
info->screen_base = (uint8_t *)arg;
if (info->screen_base == NULL)
info->screen_buffer = (uint8_t *)arg;
printf("ili9341 ili9341_ioctl function:0xp\n", info->screen_buffer);
if (info->screen_buffer == NULL)
return -ENOMEM;
break;
......
......@@ -41,19 +41,24 @@ ucamera组件是摄像头图像数据处理中间框架,支持不同类型摄
@ref ucamera_aos_api
# 使用示例
示例代码参考example/ucamera_example.c,以运行ucloud_ai_demo为例,具体步骤如下:
示例代码参考example/ucamera_example.c,以运行helloworld_demo为例,具体步骤如下:
## 添加示例代码
> ucamera组件的package.yaml中添加
```C
source_file:
- "src/*.c"
- "src/device/wifi/*.c"
- src/example/ucamera_example.c # add ucamera_example.c
```
> helloworld_demo组件的application_start中添加代码
```sh
/*init network service*/
event_service_init(NULL);
netmgr_service_init(NULL);
```
## app中添加ucamera组件
> ucloud_ai_demo组件的package.yaml中添加
> helloworld_demo组件的package.yaml中添加
```C
depends:
- ucamera: dev_aos # ucloud_ai_demo中引入ucamera组件
......@@ -61,12 +66,17 @@ depends:
## 编译
```sh
cd solutions/ucloud_ai_demo && aos make
cd solutions/helloworld_demo && aos make
```
## 烧录固件
> 参考具体板子的快速开始文档。
> helloworld_demo bin烧录:
```sh
aos burn
```
## ucamera示例测试
> 开发板网络连接命令(XXXX为网络SSID,设置不加密):
```sh
......
......@@ -94,8 +94,11 @@ frame_buffer_t *wifi_camera_get_frame(ucamera_device_t *dev)
do {
ret = httpclient_recv(&wifi_camera_client, &wifi_camera_client_data);
if (ret < 0)
if (ret < 0) {
dev->stream_buf = NULL;
dev->stream_len = 0;
break;
}
dev->stream_buf = wifi_camera_client_data.response_buf;
dev->stream_len = wifi_camera_client_data.response_content_len;
} while (ret == HTTP_EAGAIN);
......
......@@ -74,9 +74,16 @@ source_file:
- "example/ucloud_ai_example.c" # add ucloud_ai_example.c
```
> ugraphics组件的package.yaml中添加编译配置:
```sh
build_config:
prebuild_script: cp_resources.py
```
> helloworld_demo组件的application_start中添加代码
```sh
/*init network service*/
event_service_init(NULL);
netmgr_service_init(NULL);
```
......@@ -96,7 +103,8 @@ source_file:
1. 创建Bucket时地域选择“上海”
2. 读写权限选择“公共读”
```
## ucloud_ai/package.yaml中配置OSS信息
## 配置OSS信息
> components/ucloud_ai/package.yaml中替换你的OSS信息
```sh
OSS_ACCESS_KEY: "Your-Access-Key"
OSS_ACCESS_SECRET: "Your-Access-Secret"
......@@ -109,22 +117,41 @@ ENDPOINT使用默认即可,BUCKET请使用你创建好的Bucket名称
```
## 添加ucloud_ai组件
> helloworld_demo组件的package.yaml中添加
> helloworld_demo组件的package.yaml中添加如下组件:
```sh
depends:
- ucloud_ai: dev_aos # helloworld_demo中引入ucloud_ai组件
- ucloud_ai: dev_aos # helloworld_demo中引入ucloud_ai组件
- netmgr: dev_aos # helloworld_demo中引入netmgr组件
- littlefs: dev_aos # helloworld_demo中引入littlefs组件
```
## 编译
```sh
cd solutions/helloworld_demo && aos make
```
## 资源文件打包
> 编译时ucloud_ai组件中cp_resources.py会对资源文件进行拷贝,系统自动打包到littlefs文件系统中。编译完成后请确认目录hardware/chip/haas1000/prebuild/data/下有ucloud_ai_image目录。
>hardware/chip/haas1000/prebuild/data/目录下如有其他不使用的文件,建议删除后再进行编译,避免littlefs不够用导致无法访问的问题。
> 在cli/package.yaml中设置打开CLI_IOBOX_ENABLE,便可在板子上通过ls命令查看资源文件是否成功烧录:
```sh
def_config:
CLI_IOBOX_ENABLE: 1
```
```sh
ls /data/ucloud_ai_image
```
## 烧录固件
> 参考具体板子的快速开始文档。
本组件例子中使用到到图片存放在代码中hardware/chip/haas1000/prebuild/data/image目录,除烧录helloworld demo image外,需额外使用如下命令烧录littlefs文件系统:
> helloworld_demo bin烧录:
```sh
aos burn
```
> littlefs文件系统烧录:
```sh
aos burn -f hardware/chip/haas1000/release/write_flash_tool/ota_bin/littlefs.bin#0xB32000
```
......@@ -138,7 +165,12 @@ ucloud_ai -m 0 # 人脸比对
> CLI关键日志:
```sh
TODO
confidence:84.5607
x:159
y:76
w:143
h194
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -148,7 +180,8 @@ ucloud_ai -m 1 # 人物动漫化
> CLI关键日志:
```sh
TODO
image url:http://vibktprfx-prod-prod-aic-gd-cn-shanghai.oss-cn-shanghai.aliyuncs.com/person-image-cartoonizer/5BE7565D-59CE-43EE-8169-09ED2821CE21_b301_20210331-093707.jpg?Expires=1617185228&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=8zhYdqxKgz9eDz970l1BXmpPAiQ%3D
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -158,7 +191,12 @@ ucloud_ai -m 2 # 表情识别
> CLI关键日志:
```sh
TODO
face probablility:0.997393
x:872835160
y:873405208
w:4
h:872835304
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -168,7 +206,46 @@ ucloud_ai -m 3 # 目标检测
> CLI关键日志:
```sh
TODO
object num:6
object height:533
object width:948
object score:0.437
object type:potted plant
object boxes.x:35
object boxes.y:274
object boxes.w:185
object boxes.h:443
object score:0.487
object type:potted plant
object boxes.x:663
object boxes.y:121
object boxes.w:847
object boxes.h:457
object score:0.583
object type:monitor
object boxes.x:250
object boxes.y:43
object boxes.w:670
object boxes.h:439
object score:0.482
object type:keyboard
object boxes.x:239
object boxes.y:435
object boxes.w:489
object boxes.h:485
object score:0.261
object type:keyboard
object boxes.x:241
object boxes.y:428
object boxes.w:639
object boxes.h:506
object score:0.217
object type:mouse
object boxes.x:660
object boxes.y:479
object boxes.w:750
object boxes.h:528
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -178,7 +255,11 @@ ucloud_ai -m 4 # 主体检测
> CLI关键日志:
```sh
TODO
object x:56
object y:177
object width:661
object height:209
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -188,7 +269,12 @@ ucloud_ai -m 5 # 通用分割
> CLI关键日志:
```sh
TODO
0image url: http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_HeadSegmenter/2021-3-31/invi_HeadSegmenter_016171837626454285967296_L925gE.png?Expires=1617185562&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=bvMITW5gJQPlHBiP3Aa%2BO6fCdvQ%3D
0width: 160
0height: 209
0x: 153
0y: 66
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -198,7 +284,8 @@ ucloud_ai -m 6 # 面部分割
> CLI关键日志:
```sh
TODO
image url: http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_humansegmenter/2021-3-31/invi_humansegmenter_016171860047301086642_0V057V.jpg?Expires=1617187804&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=TiqmpoQqCon9KHPXEF8W6sf2vuY%3D
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -208,7 +295,33 @@ ucloud_ai -m 7 # 身份证证明识别
> CLI关键日志:
```sh
TODO
Address: 江苏省南京市浦口区天天小区1栋11号
BirthDate:
gender:
nationality: 汉
iDNumber:
faceRectangle.x: 663.147
faceRectangle.y: 249.947
faceRectangle.width: 115.432
faceRectangle.height: 96.2586
faceRectangle.angle: -87.3476
0cardAreas.x: 166
0cardAreas.y: 97
0faceRectVertices.x: 708.554
0faceRectVertices.y: 309.828
1cardAreas.x: 775
1cardAreas.y: 97
1faceRectVertices.x: 612.398
1faceRectVertices.y: 305.374
2cardAreas.x: 775
2cardAreas.y: 460
2faceRectVertices.x: 617.74
2faceRectVertices.y: 190.065
3cardAreas.x: 166
3cardAreas.y: 460
3faceRectVertices.x: 713.895
3faceRectVertices.y: 194.52
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -218,7 +331,10 @@ ucloud_ai -m 8 # 身份证反面识别
> CLI关键日志:
```sh
TODO
startDate: 20131010
issue: 杭州市公安局余杭分局
endDate: 20231010
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -228,7 +344,10 @@ ucloud_ai -m 9 # 银行卡识别
> CLI关键日志:
```sh
TODO
bankName: 中国工商银行
cardNumber: 6212262315007683105
validDate: 07/26
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -238,7 +357,57 @@ ucloud_ai -m 10 # 文本识别
> CLI关键日志:
```sh
TODO
results size: 7
0text: 《爆炸新闻》
0probability: 0.987366
0text left: 442
0text angle: -9
0text top: 141
0text height: 20
0text: width:89
1text: 19
1probability: 0.993373
1text left: 173
1text angle: -10
1text top: 115
1text height: 109
1text: width:100
2text: 豆瓣评分7.1
2probability: 0.896118
2text left: 447
2text angle: -9
2text top: 168
2text height: 18
2text: width:98
3text: 2019||美国|加拿大|剧情|传记
3probability: 0.494584
3text left: 450
3text angle: -9
3text top: 181
3text height: 17
3text: width:241
4text: 杰伊·罗奇 导演
4probability: 0.894469
4text left: 454
4text angle: -9
4text top: 216
4text height: 18
4text: width:112
5text: 2021年2月星期五
5probability: 0.991614
5text left: 187
5text angle: -9
5text top: 231
5text height: 18
5text: width:150
6text: 农历正月初八
6probability: 0.984329
6text left: 193
6text angle: -9
6text top: 261
6text height: 18
6text: width:104
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -248,7 +417,12 @@ ucloud_ai -m 11 # 垃圾分类
> CLI关键日志:
```sh
TODO
sensitive: 0
0rubbish: 塑料饮料瓶
0category: 可回收垃圾
0categoryScore: 1
0rubbishScore: 1
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -258,7 +432,13 @@ ucloud_ai -m 12 # 水果检测
> CLI关键日志:
```sh
TODO
0score: 0.822785
0name: 橙子
box.xmin: 214.05966186523438
box.ymin: 44.830513000488281
box.xmax: 723.5120849609375
box.ymax: 482.88070678710938
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -268,7 +448,8 @@ ucloud_ai -m 13 # 图像人体擦除
> CLI关键日志:
```sh
TODO
imageUrl: http://algo-app-isr-lab-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/remove-person/2021-03-31_10%3A20%3A46.011134_person_org.jpg?Expires=1617187846&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=OwLEg5pWNVDwXrvAbGsUU7q5Dbs%3D
ucloud_ai comp test success!
```
### CLI命令行输入:
......@@ -278,14 +459,32 @@ ucloud_ai -m 14 # 风格迁移
> CLI关键日志:
```sh
TODO
outMajorURL:
outImageURL: http://viapi-cn-shanghai-dha-filter.oss-cn-shanghai.aliyuncs.com/upload/result_/2021-3-31/invi__016171860565631021659_XIqH26.jpg?Expires=1617187856&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=tqJqHHoPSvga6LyET31TZsvOXFs%3D
ucloud_ai comp test success!
```
# 注意事项
NA
使用过程中如果想要验证自己的图片是否可以正常识别可通过http://vision.aliyun.com进入能力中心中对应的体验页面进行验证。
# FAQ
如果遇到:
error code: InvalidAction.NotFound
> error code: InvalidAction.NotFound
请确认Endpoint是否设置正确
> error code: InvalidApi.NotPurchase
请确认是否在vision.aliyun.com开通相应功能
> tlefs_vfs.c:677:error: lfs_vfs_open /data/ucloud_ai_image/object.jpg failed, ret - -2
请确认是否有拷贝图片到hardware/chip/haas1000/prebuild/data/ucloud_ai_image目录。
```sh
1. 在cli/package.yaml中设置CLI_IOBOX_ENABLE: 1
2. ls /data/ucloud_ai_image查看
```
如果有,可能是文件系统存储空间不够,此时请执行:
1. 在ucloud_ai/package.yaml中屏蔽prebuild_script: cp_resources.py;
2. 删除ucloud_ai_image中其他文件,仅保留测试case使用的图片文件;
3. 再重新编译烧录。
......@@ -5,12 +5,16 @@ import sys
import getpass
import shutil
comp_path = sys.path[0]
print("comp_path:")
print(comp_path)
# original folder
comp_path="../../../../components/ucloud_ai/src/example/image"
data_path="../../../../hardware/chip/haas1000/prebuild/data"
org_image_path = comp_path + "/src/example/image"
# new folder
image_path=data_path+"/ucloud_ai_image"
data_path = comp_path + "/../../hardware/chip/haas1000/prebuild/data"
image_path = data_path + "/ucloud_ai_image"
# delete prebuild/data resources
if os.path.exists(image_path):
......@@ -18,7 +22,7 @@ if os.path.exists(image_path):
shutil.rmtree(image_path)
# copy resources
shutil.copytree(comp_path, image_path)
shutil.copytree(org_image_path, image_path)
# result
print("run external script success")
......@@ -19,15 +19,13 @@
extern "C" {
#endif
typedef struct _AIModelResultStruct {
union {
FacebodyResultStruct facebody;
ImageSegResultStruct imageseg;
ImageEnhanResultStruct imageenhan;
ImageRecogResultStruct imagerecog;
ObjectDetResultStruct objectdet;
OcrResultStruct ocr;
};
typedef union _AIModelResultStruct {
FacebodyResultStruct facebody;
ImageSegResultStruct imageseg;
ImageEnhanResultStruct imageenhan;
ImageRecogResultStruct imagerecog;
ObjectDetResultStruct objectdet;
OcrResultStruct ocr;
} AIModelResultStruct;
......
......@@ -29,12 +29,10 @@ typedef struct _GenerateHumanAnimeStyleStruct {
} GenerateHumanAnimeStyleStruct;
typedef struct _FacebodyResultStruct {
union {
ComparingFaceStruct face;
RecognizeExpressionStruct expression;
GenerateHumanAnimeStyleStruct anime;
};
typedef union _FacebodyResultStruct {
ComparingFaceStruct face;
RecognizeExpressionStruct expression;
GenerateHumanAnimeStyleStruct anime;
} FacebodyResultStruct;
int compareFace(char *urlA, char *urlB, AIModelCBFunc cb);
......
......@@ -26,11 +26,9 @@ typedef struct _ExtendImageStyleStruct {
int outImageLen;
} ExtendImageStyleStruct;
typedef struct _ImageEnhanResultStruct {
union {
ErasePersonStruct person;
ExtendImageStyleStruct style;
};
typedef union _ImageEnhanResultStruct {
ErasePersonStruct person;
ExtendImageStyleStruct style;
} ImageEnhanResultStruct;
int erasePerson(char *imageUrl, char *userMaskUrl, AIModelCBFunc cb);
......
......@@ -24,11 +24,9 @@ typedef struct _DetectFruitsStruct {
RectStruct box;
} DetectFruitsStruct;
typedef struct _ImageRecogResultStruct {
union {
ClassifyingRubbishStruct rubbish;
DetectFruitsStruct fruits;
};
typedef union _ImageRecogResultStruct {
ClassifyingRubbishStruct rubbish;
DetectFruitsStruct fruits;
} ImageRecogResultStruct;
int classifyingRubbish(char *url, AIModelCBFunc cb);
......
......@@ -21,15 +21,12 @@ typedef struct _SegmentFaceStruct {
char *url;
char *image;
int imageLen;
int index;
RectStruct location;
} SegmentFaceStruct;
typedef struct _ImageSegResultStruct {
union {
SegmentCommonStruct common;
SegmentFaceStruct face;
};
typedef union _ImageSegResultStruct {
SegmentCommonStruct common;
SegmentFaceStruct face;
} ImageSegResultStruct;
int segmentCommonImage(char *url, AIModelCBFunc cb);
......
......@@ -21,11 +21,9 @@ typedef struct _DetectMainBodyStruct {
RectStruct location;
} DetectMainBodyStruct;
typedef struct _ObjectDetResultStruct {
union {
DetectObjectStruct object;
DetectMainBodyStruct mainbody;
};
typedef union _ObjectDetResultStruct {
DetectObjectStruct object;
DetectMainBodyStruct mainbody;
} ObjectDetResultStruct;
int detectObject(char *url, AIModelCBFunc cb);
......
......@@ -11,8 +11,8 @@
extern "C" {
#endif
typedef struct _RecogIdentityCardStruct {
union {
typedef union _RecogIdentityCardStruct {
struct {
char *address;
char *birthDate;
char *gender;
......@@ -24,7 +24,7 @@ typedef struct _RecogIdentityCardStruct {
float faceY[4];
RectStruct location;
} face;
union {
struct {
char *startDate;
char *issue;
char *endDate;
......
......@@ -11,16 +11,14 @@
extern "C" {
#endif
typedef AIModelCBFunc ucloud_ai_cb_t;
typedef AIModelResultStruct ucloud_ai_result_t;
#define FACE1_IMAGE "/data/ucloud_ai_image/face1.png"
#define FACE2_IMAGE "/data/ucloud_ai_image/face2.png"
#define ANIME_IMAGE "/data/ucloud_ai_image/anime.png"
#define ANIME_IMAGE "/data/ucloud_ai_image/expression.jpg"
#define EXPRESSION_IMAGE "/data/ucloud_ai_image/expression.jpg"
#define OBJECT_IMAGE "/data/ucloud_ai_image/object.jpg"
#define MAINBODY_IMAGE "/data/ucloud_ai_image/mainbody.jpg"
#define MAINBODY_IMAGE "/data/ucloud_ai_image/face1.png"
#define CARD_FACE_IMAGE "/data/ucloud_ai_image/card_face.jpg"
#define CARD_BACK_IMAGE "/data/ucloud_ai_image/card_back.jpg"
#define BANK_CARD_IMAGE "/data/ucloud_ai_image/bank_card.jpg"
......@@ -28,12 +26,15 @@ typedef AIModelResultStruct ucloud_ai_result_t;
#define RUBBISH_IMAGE "/data/ucloud_ai_image/rubbish.jpg"
#define FRUITS_IMAGE "/data/ucloud_ai_image/fruits.jpg"
#define PERSON_ORG_IMAGE "/data/ucloud_ai_image/person_org.jpg"
#define STYLE_IMAGE "/data/ucloud_ai_image/extend_style.jpg"
#define STYLE_IMAGE "/data/ucloud_ai_image/person_org.jpg"
// imageenhan style url
#define IMAGEENHAN_ERASE_PERSON_USERMASK_URL "http://public-vigen-video.oss-cn-shanghai.aliyuncs.com/xianhui.lxh/tmp/remove_person/inpainting_test_images/img19_mask.png"
#define IMAGEENHAN_ERASE_PERSON_USERMASK_URL "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageenhan/ErasePerson/ErasePerson6.jpg"
#define IMAGEENHAN_EXTEND_IMAGE_STYLE_URL "http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/ExtendImageStyle/styleUrl.jpeg"
typedef AIModelCBFunc ucloud_ai_cb_t;
typedef AIModelResultStruct ucloud_ai_result_t;
typedef enum _ucloud_ai_model_t {
UCLOUD_AI_MODEL_COMPARING_FACEBODY, // refer to https://vision.aliyun.com/experience/detail?spm=a211p3.14471187.J_7524944390.59.bc2e797dbbIyZQ&tagName=facebody&children=CompareFace
UCLOUD_AI_MODEL_GENERATE_HUMAN_ANIME_STYLE, // refer to https://vision.aliyun.com/experience/detail?spm=a211p3.14471187.J_7524944390.15.54ca797dDKkjDk&tagName=facebody&children=GenerateHumanAnimeStyle
......@@ -85,12 +86,46 @@ void ucloud_ai_set_oss_endpoint(char *endpoint);
/**
* Upload file to oss bucket.
*
* @param[in] endpoint oss endpoint.
* @param[in] path local file path.
*
* @return oss url result.
* @return oss url result.
*/
uint8_t *ucloud_ai_upload_file(char *path);
/**
* Initialize ucloud ai.
*
* @return 0 on success, negative error on failure.
*/
int32_t ucloud_ai_init(void);
/**
* Uninitialize ucloud ai.
*
* @return 0 on success, negative error on failure.
*/
int32_t ucloud_ai_uninit(void);
/**
* Connect to url server.
*
* @param[in] url url address.
*
* @return 0 on success, negative error on failure.
*/
int32_t ucloud_ai_connect(char *url);
/**
* Disconnect to url server.
*
*/
void ucloud_ai_disconnect(void);
/**
* Get stream by url address.
*
*/
int32_t ucloud_ai_get_stream(char *url, char **stream);
/**
* @}
*/
......
......@@ -42,7 +42,7 @@ depends:
build_config:
include:
- include
prebuild_script: cp_resources.py
# prebuild_script: cp_resources.py
# source_file: # <可选项> 指定参与编译的源代码文件,支持通配符,采用相对路径
# - src/*.c # 例:组件 src 目录下所有的扩展名为 c 的源代码文件
......@@ -61,7 +61,7 @@ source_file:
- src/model/ocr.cc ? <CONFIG_ALICLOUD_OCR_ENABLE>
- src/ucloud_ai_common.c
- src/model/common.cc
- src/example/ucloud_ai_example.c
# - src/example/ucloud_ai_example.c
## 第五部分:配置信息
def_config: # 组件的可配置项
......
......@@ -10,410 +10,6 @@
#define TAG "uclud_ai_example"
#ifdef CONFIG_ALICLOUD_FACEBODY_ENABLE
static int facebody_compare_callback(ucloud_ai_result_t *result)
{
float confidence;
if (!result)
return -1;
LOG("Facebody comparing result:\n");
LOG("confidence: %.1f\n", confidence);
return 0;
}
static int recognize_expression_callback(ucloud_ai_result_t *result)
{
int len;
char *expression, *p_expression;
float face_probability;
if (!result)
return -1;
expression = result->facebody.expression.expression;
face_probability = result->facebody.expression.probability;
if (!expression)
return -1;
p_expression = strdup(expression);
if (!p_expression) {
LOGE(TAG, "p_expression strdup fail\n");
return -1;
}
LOG("Recognize expression result:\n");
LOG("type: %s, probability: %.1f\n", p_expression, face_probability);
free(p_expression);
p_expression = NULL;
return 0;
}
static int generate_human_anime_styple_callback(ucloud_ai_result_t *result)
{
int ret;
char *url = NULL;
if (!result)
return -1;
url = result->facebody.anime.url;
LOG("Generate human anime style result:\n");
LOG("url: %s\n", url);
return ret;
}
#endif
#ifdef CONFIG_ALICLOUD_OBJECTDET_ENABLE
static int detect_object_callback(ucloud_ai_result_t *result)
{
int len = 0;
char *p_type = NULL;
int x, y, w, h;
char *type = NULL;
float score;
if (!result)
return -1;
type = result->objectdet.object.type;
score = result->objectdet.object.score;
x = result->objectdet.object.box.x;
y = result->objectdet.object.box.y;
w = result->objectdet.object.box.w;
h = result->objectdet.object.box.h;
if (!type) {
LOGE(TAG, "type is null\n");
return -1;
}
p_type = strdup(type);
if (!p_type) {
LOGE(TAG, "p_type strdup fail\n");
return -1;
}
LOG("Detect object result:\n");
LOG("type: %s, Score: %.1f, x: %d, y: %d, w: %d, h: %d\n", p_type, score, x, y, w, h);
free(p_type);
p_type = NULL;
return 0;
}
static int detect_main_body_callback(ucloud_ai_result_t *result)
{
int x, y, w, h;
if (!result)
return -1;
x = result->objectdet.mainbody.location.x;
y = result->objectdet.mainbody.location.y;
w = result->objectdet.mainbody.location.w;
h = result->objectdet.mainbody.location.h;
LOG("Detect main body result:\n");
LOG("main body location x: %d, y: %d, w: %d, h: %d\n", x, y, w, h);
return 0;
}
#endif
#ifdef CONFIG_ALICLOUD_IMAGESEG_ENABLE
static int segment_common_image_callback(ucloud_ai_result_t *result)
{
int ret;
if (!result)
return -1;
LOG("Segment common image result:\n");
LOG("url: %s\n", result->imageseg.common.url);
return 0;
}
static int segment_face_callback(ucloud_ai_result_t *result)
{
int ret;
int image_len = 0;
int x, y, w, h;
int index;
char *url = NULL;
char path[32] = {0};
if (!result)
return -1;
index = result->imageseg.face.index;
url = result->imageseg.face.url;
x = result->imageseg.face.location.x;
y = result->imageseg.face.location.y;
w = result->imageseg.face.location.w;
h = result->imageseg.face.location.h;
LOG("Segment face result:\n");
LOG("face %d image url: %s locating at x: %d, y: %d, w: %d, h: %d\n", index, url, x, y, w, h);
return 0;
}
#endif
#ifdef CONFIG_ALICLOUD_OCR_ENABLE
static int recognize_identity_card_face_side_callback(ucloud_ai_result_t *result)
{
char *address = NULL;
char *birthdate = NULL;
char *gender = NULL;
char *nationality = NULL;
char *id_num = NULL;
int card_x[4], card_y[4], face_x[4], face_y[4];
if (!result)
return -1;
LOG("Recognize identity card face side result:\n");
/*address string*/
address = result->ocr.identity.face.address;
if (address && strlen(address) > 0) {
LOG("address: %s\n", address);
}
/*birthdate string*/
birthdate = result->ocr.identity.face.birthDate;
if (birthdate && strlen(birthdate) > 0) {
LOG("birthdate: %s\n", birthdate);
}
/*gender string*/
gender = result->ocr.identity.face.gender;
if (gender && strlen(gender) > 0) {
LOG("gender: %s\n", gender);
}
/*nationality string*/
nationality = result->ocr.identity.face.nationality;
if (nationality && strlen(nationality) > 0) {
LOG("nationality: %s\n", nationality);
}
/*id number string*/
id_num = result->ocr.identity.face.iDNumber;
if (id_num && strlen(id_num) > 0) {
LOG("id number: %s\n", id_num);
}
/*card box line*/
memcpy(card_x, result->ocr.identity.face.cardX, 4);
memcpy(card_y, result->ocr.identity.face.cardY, 4);
if (card_x && card_y) {
LOG("card location: x0: %d, y0: %d\n", card_x[0], card_x[0]);
LOG("card location: x1: %d, y1: %d\n", card_x[1], card_x[1]);
LOG("card location: x2: %d, y2: %d\n", card_x[2], card_x[2]);
LOG("card location: x3: %d, y3: %d\n", card_x[3], card_x[3]);
}
/*face box line*/
memcpy(face_x, result->ocr.identity.face.faceX, 4);
memcpy(face_y, result->ocr.identity.face.faceY, 4);
if (face_x && face_y) {
LOG("face location: x0: %d, y0: %d\n", card_x[0], card_x[0]);
LOG("face location: x1: %d, y1: %d\n", card_x[1], card_x[1]);
LOG("face location: x2: %d, y2: %d\n", card_x[2], card_x[2]);
LOG("face location: x3: %d, y3: %d\n", card_x[3], card_x[3]);
}
return 0;
}
static int recognize_identity_card_back_side_callback(ucloud_ai_result_t *result)
{
char *start_date = NULL;
char *issue = NULL;
char *end_date = NULL;
if (!result)
return -1;
LOG("Recognize identity card back side result:\n");
/*start date of identity card's back side*/
start_date = result->ocr.identity.back.startDate;
if (start_date && strlen(start_date) > 0) {
LOG("start date: %s\n", start_date);
}
/*issue of identity card's back side*/
issue = result->ocr.identity.back.issue;
if (issue && strlen(issue) > 0) {
LOG("issue: %s\n", issue);
}
/*end date of identity card's back side*/
end_date = result->ocr.identity.back.endDate;
if (end_date && strlen(end_date) > 0) {
LOG("end date: %s\n", end_date);
}
return 0;
}
static int recognize_bank_card_callback(ucloud_ai_result_t *result)
{
char *bank_name = NULL;
char *card_number = NULL;
char *valid_date = NULL;
if (!result)
return -1;
LOG("Recognize bank card result:\n");
/*bank name of bank card*/
bank_name = result->ocr.bank.bankName;
if (bank_name && strlen(bank_name) > 0) {
LOG("bank name: %s\n", bank_name);
}
/*card number of bank card*/
card_number = result->ocr.bank.cardNumber;
if (card_number && strlen(card_number) > 0) {
LOG("card number: %s\n", card_number);
}
/*valid date of bank card*/
valid_date = result->ocr.bank.validDate;
if (valid_date && strlen(valid_date) > 0) {
LOG("valid date: %s\n", valid_date);
}
return 0;
}
static int recognize_character_callback(ucloud_ai_result_t *result)
{
float probability;
char *text = NULL;
int left, top;
int width, height;
if (!result)
return -1;
LOG("Recognize character result:\n");
text = result->ocr.character.text;
left = result->ocr.character.left;
top = result->ocr.character.top;
width = result->ocr.character.width;
height = result->ocr.character.height;
probability = result->ocr.character.probability;
if (text) {
LOG("text: %s\n", text);
LOG("probability: %.1f\n", probability);
LOG("text area: left: %d, top: %d, weight: %d, height: %d\n", top, left, width, height);
}
return 0;
}
#endif
#ifdef CONFIG_ALICLOUD_IMAGERECOG_ENABLE
static int imagerecog_classifying_rubbish_callback(ucloud_ai_result_t *result)
{
char *rubbish = NULL;
char *category = NULL;
float rubbish_score;
float category_score;
if (!result)
return -1;
LOG("Recognize rubbish result:\n");
/*rubbish name*/
rubbish = result->imagerecog.rubbish.rubbish;
rubbish_score = result->imagerecog.rubbish.rubbishScore;
if (rubbish && strlen(rubbish) > 0) {
LOG("rubbish: %s\n", rubbish);
LOG("rubbish score: %.1f\n", rubbish_score);
}
/*rubbish category*/
category = result->imagerecog.rubbish.category;
category_score = result->imagerecog.rubbish.categoryScore;
if (category && strlen(category) > 0) {
LOG("category: %s\n", category);
LOG("category score: %.1f\n", category_score);
}
}
static int imagerecog_detect_fruits_callback(ucloud_ai_result_t *result)
{
char score_str[8];
char *name = NULL;
int tmp_y, x, y, w, h;
float score;
if (!result)
return -1;
LOG("Recognize fruits result:\n");
/*fruits name and score*/
name = result->imagerecog.fruits.name;
score = result->imagerecog.fruits.score;
x = result->imagerecog.fruits.box.x;
y = result->imagerecog.fruits.box.y;
w = result->imagerecog.fruits.box.w;
h = result->imagerecog.fruits.box.h;
if (name && strlen(name) > 0) {
LOG("fruit name: %s\n", name);
LOG("fruit score: %.1f\n", score);
LOG("fruit location: x: %d, y: %d, w: %d, h: %d\n", x, y, w, h);
}
}
#endif
#ifdef CONFIG_ALICLOUD_IMAGEENHAN_ENABLE
static int imageenhan_erase_person_callback(ucloud_ai_result_t *result)
{
int ret;
char *url = NULL;
if (!result)
return -1;
LOG("Recognize fruits result:\n");
url = result->imageenhan.person.url;
LOG("url: %s\n", url);
return 0;
}
static int imageenhan_extend_image_style_callback(ucloud_ai_result_t *result)
{
int ret;
int major_image_len = 0;
int out_image_len = 0;
char *major_url = NULL;
char *out_image_url = NULL;
if (!result)
return -1;
LOG("Extend image style result:\n");
major_url = result->imageenhan.style.majorUrl;
out_image_url = result->imageenhan.style.outImageUrl;
LOG("major url: %s\n", major_url);
LOG("out image url: %s\n", out_image_url);
return 0;
}
#endif // UCLOUD_AI_IMAGERECOG_CONFIG
static void ucloud_ai_comp_example(int argc, char **argv)
{
......@@ -422,17 +18,17 @@ static void ucloud_ai_comp_example(int argc, char **argv)
char *image = NULL;
if (argc < 3) {
LOG("Please test with command: ucloud_ai_example -m [0~14]\n");
printf("Please test with command: ucloud_ai_example -m [0~14]\n");
return;
}
if (strncmp(argv[1], "-m", 2) == 0) {
if (argv[2] < 0 && argv[2] > 14) {
LOG("range of model value is 0 ~ 14, please try again\n");
printf("range of model value is 0 ~ 14, please try again\n");
return;
}
} else {
LOG("unkown command\n");
printf("unkown command\n");
return;
}
model_index = atoi(argv[2]);
......@@ -446,73 +42,73 @@ static void ucloud_ai_comp_example(int argc, char **argv)
#ifdef CONFIG_ALICLOUD_FACEBODY_ENABLE
case UCLOUD_AI_MODEL_COMPARING_FACEBODY:
printf("Comparing facebody:\n");
ucloud_ai_facebody_comparing_face(FACE1_IMAGE, FACE2_IMAGE, facebody_compare_callback);
ucloud_ai_facebody_comparing_face(FACE1_IMAGE, FACE2_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_GENERATE_HUMAN_ANIME_STYLE:
printf("Generate human anime style:\n");
ucloud_ai_facebody_generate_human_anime_style(ANIME_IMAGE, generate_human_anime_styple_callback);
ucloud_ai_facebody_generate_human_anime_style(ANIME_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_RECOGNIZE_EXPRESSION:
printf("Recognize expression:\n");
ucloud_ai_facebody_recognize_expression(EXPRESSION_IMAGE, recognize_expression_callback);
ucloud_ai_facebody_recognize_expression(EXPRESSION_IMAGE, NULL);
break;
#endif
#ifdef CONFIG_ALICLOUD_OBJECTDET_ENABLE
case UCLOUD_AI_MODEL_DETECT_OBJECT:
printf("Detect object:\n");
ucloud_ai_objectdet_detect_object(OBJECT_IMAGE, detect_object_callback);
ucloud_ai_objectdet_detect_object(OBJECT_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_DETECT_MAIN_BODY:
printf("Detect main body:\n");
ucloud_ai_objectdet_detect_main_body(MAINBODY_IMAGE, detect_main_body_callback);
ucloud_ai_objectdet_detect_main_body(MAINBODY_IMAGE, NULL);
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGESEG_ENABLE
case UCLOUD_AI_MODEL_SEGMENT_COMMON_IMAGE:
printf("Segment common image:\n");
ucloud_ai_imageseg_segment_common_image(FACE1_IMAGE, segment_common_image_callback);
ucloud_ai_imageseg_segment_common_image(MAINBODY_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_SEGMENT_FACE:
printf("Segment face:\n");
ucloud_ai_imageseg_segment_face(MAINBODY_IMAGE, segment_face_callback);
ucloud_ai_imageseg_segment_face(FACE1_IMAGE, NULL);
break;
#endif
#ifdef CONFIG_ALICLOUD_OCR_ENABLE
case UCLOUD_AI_MODEL_RECOGNIZE_IDENTITY_CARD_FACE_SIDE:
printf("Recognize identity card face side:\n");
ucloud_ai_ocr_recognize_identity_card_face_side(CARD_FACE_IMAGE, recognize_identity_card_face_side_callback);
ucloud_ai_ocr_recognize_identity_card_face_side(CARD_FACE_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_RECOGNIZE_IDENTITY_CARD_BACK_SIDE:
printf("Recognize identity card back side:\n");
ucloud_ai_ocr_recognize_identity_card_back_side(CARD_BACK_IMAGE, recognize_identity_card_back_side_callback);
ucloud_ai_ocr_recognize_identity_card_back_side(CARD_BACK_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_RECOGNIZE_BANK_CARD:
printf("Recognize bank card:\n");
ucloud_ai_ocr_recognize_bank_card(BANK_CARD_IMAGE, recognize_bank_card_callback);
ucloud_ai_ocr_recognize_bank_card(BANK_CARD_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_RECOGNIZE_CHARACTER:
printf("Recognize character:\n");
ucloud_ai_ocr_recognize_character(CHARACTER_IMAGE, recognize_character_callback);
ucloud_ai_ocr_recognize_character(CHARACTER_IMAGE, NULL);
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGERECOG_ENABLE
case UCLOUD_AI_MODEL_CLASSIFYING_RUBBISH:
printf("Classifying rubbish:\n");
ucloud_ai_imagerecog_classifying_rubbish(RUBBISH_IMAGE, imagerecog_classifying_rubbish_callback);
ucloud_ai_imagerecog_classifying_rubbish(RUBBISH_IMAGE, NULL);
break;
case UCLOUD_AI_MODEL_DETECT_FRUITS:
printf("Detect fruits:\n");
ucloud_ai_imagerecog_detect_fruits(FRUITS_IMAGE, imagerecog_detect_fruits_callback);
ucloud_ai_imagerecog_detect_fruits(FRUITS_IMAGE, NULL);
break;
#endif
#ifdef CONFIG_ALICLOUD_IMAGEENHAN_ENABLE
case UCLOUD_AI_MODEL_ERASE_PERSON:
printf("Erase person:\n");
ucloud_ai_imageenhan_erase_person(PERSON_ORG_IMAGE, IMAGEENHAN_ERASE_PERSON_USERMASK_URL, imageenhan_erase_person_callback);
ucloud_ai_imageenhan_erase_person(PERSON_ORG_IMAGE, IMAGEENHAN_ERASE_PERSON_USERMASK_URL, NULL);
break;
case UCLOUD_AI_MODEL_EXTEND_IMAGE_STYLE:
printf("Extend image style:\n");
ucloud_ai_imageenhan_extend_image_style(STYLE_IMAGE, IMAGEENHAN_EXTEND_IMAGE_STYLE_URL, imageenhan_extend_image_style_callback);
ucloud_ai_imageenhan_extend_image_style(STYLE_IMAGE, IMAGEENHAN_EXTEND_IMAGE_STYLE_URL, NULL);
break;
#endif
default:
......
......@@ -4,6 +4,7 @@
#include "CurlHttpClient.h"
#include "alibabacloud/core/Url.h"
#include "alibabacloud/core/HttpRequest.h"
#include "ucloud_ai_common.h"
extern "C" {
using namespace std;
......@@ -12,6 +13,30 @@ using namespace AlibabaCloud;
static string accessKey;
static string accessSecret;
#define USE_HTTPCLIENT
#ifdef USE_HTTPCLIENT
int getResponseBodyByUrl(const char *url, const char **buffer)
{
int ret;
int recv_len;
ret = ucloud_ai_connect((char *)url);
if (ret < 0) {
printf("ucloud_ai_connect failed, ret: %d\n", ret);
return -1;
}
recv_len = ucloud_ai_get_stream((char *)url, buffer);
ucloud_ai_disconnect();
if (!recv_len) {
LOGE(TAG, "recv_len is %d\n", recv_len);
return -1;
}
return recv_len;
}
#else
int getResponseBodyByUrl(const char *url, const char **buffer)
{
CurlHttpClient client;
......@@ -28,7 +53,7 @@ int getResponseBodyByUrl(const char *url, const char **buffer)
*buffer = out.result().body();
return out.result().bodySize();
}
#endif
void setAccesskeyAndSecret(char *key, char *secret)
{
accessKey = key;
......
......@@ -52,6 +52,7 @@ int compareFace(char *urlA, char *urlB, AIModelCBFunc cb)
ret = cb((void *)&result);
}
ShutdownSdk();
cout << "facebody comparing done" << endl << endl;
return ret;
}
......@@ -80,7 +81,7 @@ int recognizeExpression(char *url, AIModelCBFunc cb)
cout << "error code: " << outcome.error().errorCode() << endl;
cout << "requestId: " << outcome.result().requestId() << endl << endl;
// cout << "expression:" << outcome.result().getData().elements[0].expression << endl;
cout << "expression:" << outcome.result().getData().elements[0].expression << endl;
cout << "face probablility:" << outcome.result().getData().elements[0].faceProbability << endl;
cout << "x:" << outcome.result().getData().elements[0].faceRectangle.left << endl;
cout << "y:" << outcome.result().getData().elements[0].faceRectangle.top << endl;
......@@ -91,6 +92,7 @@ int recognizeExpression(char *url, AIModelCBFunc cb)
expression = outcome.result().getData().elements[0].expression;
if (!expression.empty()) {
result.expression.expression = expression.c_str();
cout << "expression:" << outcome.result().getData().elements[0].expression << endl;
result.expression.probability = outcome.result().getData().elements[0].faceProbability;
result.expression.location.x = 20; // outcome.result().getData().elements[0].faceRectangle.left;
result.expression.location.y = 20; // outcome.result().getData().elements[0].faceRectangle.top;
......@@ -115,6 +117,8 @@ int generateHumanAnimeStyle(char *url, AIModelCBFunc cb)
Model::GenerateHumanAnimeStyleRequest request;
string tmpImageURL;
FacebodyResultStruct result;
string outImageUrl;
int len;
int ret = 0;
tmpImageURL = url;
......@@ -128,9 +132,13 @@ int generateHumanAnimeStyle(char *url, AIModelCBFunc cb)
cout << "requestId: " << outcome.result().requestId() << endl << endl;
cout << "image url:" << outcome.result().getData().imageURL << endl;
result.anime.url = outcome.result().getData().imageURL.c_str();
result.anime.imageLen = getResponseBodyByUrl(result.anime.url, &result.anime.image);
if (!result.anime.image && cb) {
outImageUrl = outcome.result().getData().imageURL;
if (outImageUrl.size() > 0) {
result.anime.url = outImageUrl.c_str();
result.anime.imageLen = getResponseBodyByUrl(result.anime.url, &result.anime.image);
}
if (result.anime.image && cb) {
ret = cb((void *)&result);
}
ShutdownSdk();
......
......@@ -16,11 +16,12 @@ int erasePerson(char *imageUrl, char *userMaskUrl, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_IMAGEENHAN_ENDPOINT);
ImageenhanClient client(key, secret, configuration);
Model::ErasePersonRequest request;
string imageURL, userMaskURL;
ImageEnhanResultStruct result;
string url;
int ret = 0;
imageURL = imageUrl;
......@@ -36,12 +37,16 @@ int erasePerson(char *imageUrl, char *userMaskUrl, AIModelCBFunc cb)
cout << "requestId: " << outcome.result().requestId() << endl << endl;
cout << "imageUrl: " << outcome.result().getData().imageUrl << endl;
result.person.url = outcome.result().getData().imageUrl.c_str();
result.person.imageLen = getResponseBodyByUrl(result.person.url, &result.person.image);
if (!result.person.image && cb) {
ret = cb((void *)&result);
}
url = outcome.result().getData().imageUrl;
if (url.size() > 0) {
result.person.url = url.c_str();
result.person.imageLen = getResponseBodyByUrl(result.person.url, &result.person.image);
if (result.person.image && cb) {
ret = cb((void *)&result);
}
}
ShutdownSdk();
return ret;
}
......@@ -53,7 +58,7 @@ int extendImageStyle(char *majorUrl, char *styleUrl, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_IMAGEENHAN_ENDPOINT);
ImageenhanClient client(key, secret, configuration);
Model::ExtendImageStyleRequest request;
string inMajorURL, outMajorURL;
......@@ -83,6 +88,7 @@ int extendImageStyle(char *majorUrl, char *styleUrl, AIModelCBFunc cb)
result.style.majorImageLen = getResponseBodyByUrl(outMajorURL.c_str(), &result.style.majorImage);
ret = cb((void *)&result);
} else if (outImageURL.size() > 0 && cb) {
result.style.majorUrl = NULL;
result.style.outImageUrl = (char *)outImageURL.c_str();
result.style.outImageLen = getResponseBodyByUrl(outImageURL.c_str(), &result.style.outImage);
ret = cb((void *)&result);
......
......@@ -16,11 +16,12 @@ int classifyingRubbish(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_IMAGERECOG_ENDPOINT);
ImagerecogClient client(key, secret, configuration);
Model::ClassifyingRubbishRequest request;
string imageURL;
ImageRecogResultStruct result;
string rubbish, category;
int ret = 0, i;
imageURL = url;
......@@ -39,8 +40,10 @@ int classifyingRubbish(char *url, AIModelCBFunc cb)
cout << i << "category: " << outcome.result().getData().elements[i].category << endl;
cout << i << "categoryScore: " << outcome.result().getData().elements[i].categoryScore << endl;
cout << i << "rubbishScore: " << outcome.result().getData().elements[i].rubbishScore << endl;
result.rubbish.rubbish = outcome.result().getData().elements[i].rubbish.c_str();
result.rubbish.category = outcome.result().getData().elements[i].category.c_str();
rubbish = outcome.result().getData().elements[i].rubbish;
category = outcome.result().getData().elements[i].category;
result.rubbish.rubbish = rubbish.c_str();
result.rubbish.category = category.c_str();
result.rubbish.categoryScore = outcome.result().getData().elements[i].categoryScore;
result.rubbish.rubbishScore = outcome.result().getData().elements[i].rubbishScore;
......@@ -60,11 +63,12 @@ int detectFruits(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_IMAGERECOG_ENDPOINT);
ImagerecogClient client(key, secret, configuration);
Model::DetectFruitsRequest request;
ImageRecogResultStruct result;
string imageURL;
string name;
int ret = 0, i;
imageURL = url;
......@@ -81,7 +85,8 @@ int detectFruits(char *url, AIModelCBFunc cb)
cout << i << "score: " << outcome.result().getData().elements[i].score << endl;
cout << i << "name: " << outcome.result().getData().elements[i].name << endl;
result.fruits.score = outcome.result().getData().elements[i].score;
result.fruits.name = outcome.result().getData().elements[i].name.c_str();
name = outcome.result().getData().elements[i].name;
result.fruits.name = name.c_str();
cout << "box.xmin: " << outcome.result().getData().elements[i].box[0] << endl;
cout << "box.ymin: " << outcome.result().getData().elements[i].box[1] << endl;
......
......@@ -16,11 +16,12 @@ int segmentCommonImage(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_IMAGESEG_ENDPOINT);
ImagesegClient client(key, secret, configuration);
Model::SegmentCommonImageRequest request;
string inImageURL;
ImageSegResultStruct result;
string outImageUrl;
int ret = 0;
inImageURL = url;
......@@ -35,10 +36,13 @@ int segmentCommonImage(char *url, AIModelCBFunc cb)
cout << "requestId: " << outcome.result().requestId() << endl << endl;
cout << "image url: " << outcome.result().getData().imageURL << endl;
result.common.url = (char *)outcome.result().getData().imageURL.c_str();
result.common.imageLen = getResponseBodyByUrl(outcome.result().getData().imageURL.c_str(), &result.common.image);
if (!result.common.image && cb) {
ret = cb((void *)&result);
outImageUrl = outcome.result().getData().imageURL;
if (outImageUrl.size() > 0) {
result.common.url = (char *)outImageUrl.c_str();
result.common.imageLen = getResponseBodyByUrl(outcome.result().getData().imageURL.c_str(), &result.common.image);
if (result.common.image && cb) {
ret = cb((void *)&result);
}
}
ShutdownSdk();
return ret;
......@@ -51,11 +55,12 @@ int segmentFace(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_IMAGESEG_ENDPOINT);
ImagesegClient client(key, secret, configuration);
Model::SegmentFaceRequest request;
string inImageURL;
ImageSegResultStruct result;
string outImageUrl;
int ret = 0, i = 0;
inImageURL = url;
......@@ -78,14 +83,17 @@ int segmentFace(char *url, AIModelCBFunc cb)
cout << i << "x: " << outcome.result().getData().elements[i].x << endl;
cout << i << "y: " << outcome.result().getData().elements[i].y << endl;
result.face.url = outcome.result().getData().elements[i].imageURL .c_str();
result.face.imageLen = getResponseBodyByUrl(result.face.url, &result.face.image);
if (!result.face.image && cb) {
result.face.location.x = outcome.result().getData().elements[i].x;
result.face.location.y = outcome.result().getData().elements[i].y;
result.face.location.w = outcome.result().getData().elements[i].width;
result.face.location.h = outcome.result().getData().elements[i].height;
ret = cb((void *)&result);
outImageUrl = outcome.result().getData().elements[i].imageURL;
if (outImageUrl.size() > 0) {
result.face.url = outImageUrl.c_str();
result.face.imageLen = getResponseBodyByUrl(result.face.url, &result.face.image);
if (result.face.image && cb) {
result.face.location.x = outcome.result().getData().elements[i].x;
result.face.location.y = outcome.result().getData().elements[i].y;
result.face.location.w = outcome.result().getData().elements[i].width;
result.face.location.h = outcome.result().getData().elements[i].height;
ret = cb((void *)&result);
}
}
}
ShutdownSdk();
......
......@@ -16,11 +16,12 @@ int detectObject(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_OBJECTDET_ENDPOINT);
ObjectdetClient client(key, secret, configuration);
Model::DetectObjectRequest request;
string tmpImageURL;
ObjectDetResultStruct result;
string type;
int ret = 0;
int objectNum, i;
......@@ -46,8 +47,9 @@ int detectObject(char *url, AIModelCBFunc cb)
cout << "object boxes.w:" << outcome.result().getData().elements[i].boxes[2] << endl;
cout << "object boxes.h:" << outcome.result().getData().elements[i].boxes[3] << endl;
type = outcome.result().getData().elements[i].type;
result.object.type = type.c_str();
result.object.score = outcome.result().getData().elements[i].score;
result.object.type = outcome.result().getData().elements[i].type.c_str();
result.object.box.x = outcome.result().getData().elements[i].boxes[0];
result.object.box.y = outcome.result().getData().elements[i].boxes[1];
result.object.box.w = outcome.result().getData().elements[i].boxes[2];
......@@ -67,7 +69,7 @@ int detectMainBody(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_OBJECTDET_ENDPOINT);
ObjectdetClient client(key, secret, configuration);
Model::DetectMainBodyRequest request;
string tmpImageURL;
......
......@@ -16,11 +16,12 @@ int recognizeIdentityCardFaceSide(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_OCR_ENDPOINT);
OcrClient client(key, secret, configuration);
Model::RecognizeIdentityCardRequest request;
string imageURL;
OcrResultStruct result;
string address, birthDate, gender, nationality, iDNumber;
int ret = 0, i;
imageURL = url;
......@@ -59,11 +60,16 @@ int recognizeIdentityCardFaceSide(char *url, AIModelCBFunc cb)
result.identity.face.faceX[i] = outcome.result().getData().frontResult.faceRectVertices[i].x;
result.identity.face.faceY[i] = outcome.result().getData().frontResult.faceRectVertices[i].y;
}
result.identity.face.address = outcome.result().getData().frontResult.address.c_str();
result.identity.face.birthDate = outcome.result().getData().frontResult.birthDate.c_str();
result.identity.face.gender = outcome.result().getData().frontResult.gender.c_str();
result.identity.face.nationality = outcome.result().getData().frontResult.nationality.c_str();
result.identity.face.iDNumber = outcome.result().getData().frontResult.iDNumber.c_str();
address = outcome.result().getData().frontResult.address;
birthDate = outcome.result().getData().frontResult.birthDate;
gender = outcome.result().getData().frontResult.gender;
nationality = outcome.result().getData().frontResult.nationality;
iDNumber = outcome.result().getData().frontResult.iDNumber;
result.identity.face.address = address.c_str();
result.identity.face.birthDate = birthDate.c_str();
result.identity.face.gender = gender.c_str();
result.identity.face.nationality = nationality.c_str();
result.identity.face.iDNumber = iDNumber.c_str();
if (cb) {
ret = cb((void *)&result);
......@@ -80,10 +86,11 @@ int recognizeIdentityCardBackSide(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_OCR_ENDPOINT);
OcrClient client(key, secret, configuration);
Model::RecognizeIdentityCardRequest request;
OcrResultStruct result;
string startDate, issue, endDate;
string imageURL;
int ret = 0;
......@@ -100,9 +107,12 @@ int recognizeIdentityCardBackSide(char *url, AIModelCBFunc cb)
cout << "startDate: " << outcome.result().getData().backResult.startDate << endl;
cout << "issue: " << outcome.result().getData().backResult.issue << endl;
cout << "endDate: " << outcome.result().getData().backResult.endDate << endl;
result.identity.back.startDate = outcome.result().getData().backResult.startDate.c_str();
result.identity.back.issue = outcome.result().getData().backResult.issue.c_str();
result.identity.back.endDate = outcome.result().getData().backResult.endDate.c_str();
startDate = outcome.result().getData().backResult.startDate;
issue = outcome.result().getData().backResult.issue;
endDate = outcome.result().getData().backResult.endDate;
result.identity.back.startDate = startDate.c_str();
result.identity.back.issue = issue.c_str();
result.identity.back.endDate = endDate.c_str();
if (cb) {
ret = cb((void *)&result);
......@@ -118,10 +128,11 @@ int recognizeBankCard(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_OCR_ENDPOINT);
OcrClient client(key, secret, configuration);
Model::RecognizeBankCardRequest request;
OcrResultStruct result;
string bankName, cardNumber, validDate;
string imageURL;
int ret = 0;
......@@ -138,9 +149,12 @@ int recognizeBankCard(char *url, AIModelCBFunc cb)
cout << "cardNumber: " << outcome.result().getData().cardNumber << endl;
cout << "validDate: " << outcome.result().getData().validDate << endl;
result.bank.bankName = outcome.result().getData().bankName.c_str();
result.bank.cardNumber = outcome.result().getData().cardNumber.c_str();
result.bank.validDate = outcome.result().getData().validDate.c_str();
bankName = outcome.result().getData().bankName;
cardNumber = outcome.result().getData().cardNumber;
validDate = outcome.result().getData().validDate;
result.bank.bankName = bankName.c_str();
result.bank.cardNumber = cardNumber.c_str();
result.bank.validDate = validDate.c_str();
if (cb) {
ret = cb((void *)&result);
......@@ -156,10 +170,11 @@ int recognizeCharacter(char *url, AIModelCBFunc cb)
string secret = getAccessSecret();
ClientConfiguration configuration;
configuration.setRegionId(CLOUD_AI_REGION_ID);
configuration.setEndpoint(CLOUD_AI_FACEBODY_ENDPOINT);
configuration.setEndpoint(CLOUD_AI_OCR_ENDPOINT);
OcrClient client(key, secret, configuration);
Model::RecognizeCharacterRequest request;
OcrResultStruct result;
string text;
string imageURL;
int ret = 0, i;
......@@ -184,7 +199,8 @@ int recognizeCharacter(char *url, AIModelCBFunc cb)
cout << i << "text top: " << outcome.result().getData().results[i].textRectangles.top << endl;
cout << i << "text height: " << outcome.result().getData().results[i].textRectangles.height << endl;
cout << i << "text: width:" << outcome.result().getData().results[i].textRectangles.width << endl;
result.character.text = outcome.result().getData().results[i].text.c_str();
text = outcome.result().getData().results[i].text;
result.character.text = text.c_str();
result.character.probability = outcome.result().getData().results[i].probability;
result.character.left = outcome.result().getData().results[i].textRectangles.left;
result.character.angle = outcome.result().getData().results[i].textRectangles.angle;
......
......@@ -41,7 +41,6 @@ void ucloud_ai_set_oss_endpoint(char *endpoint)
strcpy(g_oss_endpoint, endpoint);
len = strlen(endpoint);
g_oss_endpoint[len] = '\0';
printf("g_oss_endpoint: %s\n", g_oss_endpoint);
}
}
......@@ -51,9 +50,6 @@ uint8_t *ucloud_ai_upload_file(char *path)
char *access_key = getAccessKey();
char *access_secret = getAccessSecret();
printf("access_key: %s, access_secret: %s\n", access_key, access_secret);
printf("g_oss_bucket: %s\n", g_oss_bucket);
printf("g_oss_endpoint: %s\n", g_oss_endpoint);
/*update capture.jpg to oss*/
tmp_upload_url = oss_upload_local_file(access_key, \
(char *)access_secret, g_oss_endpoint, g_oss_bucket, path);
......@@ -69,3 +65,62 @@ void ucloud_ai_set_key_secret(char *key, char *secret)
{
setAccesskeyAndSecret(key, secret);
}
int32_t ucloud_ai_init(void)
{
int32_t ret;
char *customer_header = "Accept: */*\r\n";
ret = httpclient_prepare(&ai_client_data, HEAD_SIZE, BODY_SZIE);
if (ret != HTTP_SUCCESS)
return -1;
ai_client.is_http = true;
httpclient_set_custom_header(&ai_client, customer_header);
return ret;
}
int32_t ucloud_ai_uninit(void)
{
return httpclient_unprepare(&ai_client_data);
}
int32_t ucloud_ai_connect(char *url)
{
int32_t ret;
ret = httpclient_conn(&ai_client, (const char *)url);
if (HTTP_SUCCESS != ret) {
LOGE(TAG, "http connect failed");
return -1;
}
return ret;
}
void ucloud_ai_disconnect(void)
{
httpclient_clse(&ai_client);
}
int32_t ucloud_ai_get_stream(char *url, char **stream)
{
int ret;
int recv_len = 0;
httpclient_reset(&ai_client_data);
ret = httpclient_send(&ai_client, (const char *)url, HTTP_GET, &ai_client_data);
if (HTTP_SUCCESS != ret) {
LOGE(TAG, "http send request failed");
return -1;
}
do {
ret = httpclient_recv(&ai_client, &ai_client_data);
if (ret < 0)
break;
*stream = ai_client_data.response_buf;
recv_len = ai_client_data.response_content_len;
} while (ret == HTTP_EAGAIN);
return recv_len;
}
......@@ -19,8 +19,14 @@ void ucloud_ai_facebody_comparing_face(char *path, char *myface, ucloud_ai_cb_t
if (!p_upload_url)
return;
/*my face picture*/
p_myface_url = myface;
if (myface) {
/*my face picture*/
p_myface_url = ucloud_ai_upload_file(myface);
if (!p_myface_url)
return;
} else {
p_myface_url = MYFACE_PATH;
}
/*do facebody detection*/
compareFace(p_upload_url, p_myface_url, cb);
......
......@@ -19,7 +19,7 @@ void ucloud_ai_imageseg_segment_face(char *path, ucloud_ai_cb_t cb)
return;
/*do face segment*/
segmentCommonImage(p_upload_url, cb);
segmentFace(p_upload_url, cb);
free(p_upload_url);
}
......@@ -35,6 +35,6 @@ void ucloud_ai_imageseg_segment_common_image(char *path, ucloud_ai_cb_t cb)
return;
/*do common image segement*/
segmentFace(p_upload_url, cb);
segmentCommonImage(p_upload_url, cb);
free(p_upload_url);
}
......@@ -215,24 +215,15 @@ int32_t udisplay_init(void)
close(fd);
return -1;
}
#else
/* malloc framebuffer and set to drivers */
fbaddr = (uint8_t *)malloc(fb_size);
if (fbaddr == NULL) {
close(fd);
LOGE("udisplay", "[%s]fbadd is NULL\r\n", __func__);
return -1;
}
udisplay_set_prefb_addr(fbaddr);
LOGE("udisplay", "[%s]mmap addr : %p\r\n", __func__, fbaddr);
ctx->framebuffer = fbaddr;
ctx->framebuffer_size = fb_size;
#endif
LOGE("udisplay", "[%s]mmap addr : %p\r\n", __func__, fbaddr);
ctx->swap = ((fb_var.xres_virtual * fb_var.yres_virtual) /
(fb_var.xres * fb_var.yres) == 2) ?
true : false;
ctx->fb_id = 0;
ctx->framebuffer = fbaddr;
ctx->framebuffer_size = fb_size;
memcpy(&ctx->var, &fb_var, sizeof(fb_var_screeninfo_t));
......@@ -309,6 +300,7 @@ int32_t udisplay_show_rect(uint8_t *buf, uint32_t x, uint32_t y, uint32_t w, \
return -1;
}
} else {
#ifdef ENABLE_MICRO_KERNEL
if ((x == 0) && (y == 0)) {
memcpy(get_display_buffer_addr(ctx->fb_id), buf, \
ctx->var.xres * \
......@@ -317,6 +309,14 @@ int32_t udisplay_show_rect(uint8_t *buf, uint32_t x, uint32_t y, uint32_t w, \
} else {
display_draw_rect(x, y, w, h, buf);
}
#else
ret = udisplay_set_prefb_addr(buf);
if (ret < 0) {
LOGE("udisplay", "[%s]set prefb addr fail\n", __func__);
aos_mutex_unlock(&ctx->mutex);
return -1;
}
#endif
}
ret = udisplay_pan_display(ctx->fb_id);
......
......@@ -38,9 +38,9 @@ ugraphics组件是基于SDL2封装的接口,支持JPEG/PNG图像解码绘制
# 常用配置
```sh
def_config: # 组件的可配置项
AOS_COMP_JPEG: 1
CONFIG_UGRAPHICS_FORMAT: 1
CONFIG_UGRAPHICS_ROTATE: 1
AOS_COMP_JPEG: 0
CONFIG_UGRAPHICS_FORMAT: 0
CONFIG_UGRAPHICS_ROTATE: 0
```
> 配置是否支持JPEG解码、图像格式转换、图像旋转,默认是关闭的
......@@ -54,7 +54,13 @@ def_config: # 组件的可配置项
> ugraphics组件的package.yaml中添加example
```sh
source_file:
- "example/ugraphics_example.c" # add ugraphics_example.c
- "src/example/ugraphics_example.c" # add ugraphics_example.c
```
> ugraphics组件的package.yaml中添加编译配置:
```sh
build_config:
prebuild_script: cp_resources.py
```
## 添加ugraphics组件
......@@ -68,12 +74,36 @@ depends:
```sh
cd solutions/helloworld_demo && aos make
```
## 资源文件打包
> 编译时ugraphics组件中cp_resources.py会对资源文件进行拷贝,系统自动打包到littlefs文件系统中。编译完成后请确认目录hardware/chip/haas1000/prebuild/data/下有ugraphics_image目录。
>hardware/chip/haas1000/prebuild/data/目录下如有其他不使用的文件,建议删除后再进行编译,避免littlefs不够用导致无法访问的问题。
## 烧录固件
> 参考具体板子的快速开始文档。
> helloworld_demo bin烧录:
```sh
aos burn
```
> littlefs文件系统烧录:
```sh
aos burn -f hardware/chip/haas1000/release/write_flash_tool/ota_bin/littlefs.bin#0xB32000
```
## ugraphics示例测试
### CLI命令行输入:
```sh
ugraphics init # 资源初始化
```
> CLI关键日志:
```sh
ugraphics init ok!
```
### CLI命令行输入:
```sh
ugraphics draw rect # 绘制矩形框
......@@ -86,7 +116,7 @@ ugraphics draw rectangle ok!
### CLI命令行输入:
```sh
ugraphics draw jpg # 绘制图片
ugraphics draw jpg # 绘制jpeg图片
```
> CLI关键日志:
......@@ -96,7 +126,7 @@ ugraphics draw jpg image ok!
### CLI命令行输入:
```sh
ugraphics draw png # 绘制图片
ugraphics draw png # 绘制png图片
```
> CLI关键日志:
......@@ -126,7 +156,7 @@ ugraphics draw string ok!
### CLI命令行输入:
```sh
ugraphics fill rect # 绘制字符串
ugraphics fill rect # 填充矩形框
```
> CLI关键日志:
......@@ -136,7 +166,7 @@ ugraphics fill rectangle ok!
### CLI命令行输入:
```sh
ugraphics clear # 绘制字符串
ugraphics clear # 清屏
```
> CLI关键日志:
......@@ -144,8 +174,18 @@ ugraphics clear # 绘制字符串
ugraphics clear screen ok!
```
### CLI命令行输入:
```sh
ugraphics quit # 释放资源
```
> CLI关键日志:
```sh
ugraphics quit ok!
```
# 注意事项
在使用绘制字符串或图片时,因为需要加载字体或图片,字库simfang.ttf或图片默认存放在/data/font/目录,因此需要在depends中确保littlefs组件已经加入。烧录程序时除烧录demo image外,还需要通过以下命令烧录文件系统。
在使用绘制字符串或图片时,因为需要加载字体或图片,字库Alibaba-PuHuiTi-Heavy.ttf或图片默认存放在/data/font/目录,因此需要在depends中确保littlefs组件已经加入。烧录程序时除烧录demo image外,还需要通过以下命令烧录文件系统。
```sh
aos burn -f hardware/chip/haas1000/release/write_flash_tool/ota_bin/littlefs.bin#0xB32000
```
......
......@@ -5,14 +5,18 @@ import sys
import getpass
import shutil
comp_path = sys.path[0]
print("comp_path:")
print(comp_path)
# original folder
org_image_path="../../../../components/ugraphics/src/example/image"
org_font_path="../../../../components/ugraphics/src/resources/font"
data_path="../../../../hardware/chip/haas1000/prebuild/data"
org_image_path = comp_path + "/src/example/image"
org_font_path = comp_path + "/src/resources/font"
# new folder
image_path=data_path+"/ugraphics_image"
font_path=data_path+"/font"
data_path = comp_path + "/../../hardware/chip/haas1000/prebuild/data"
image_path = data_path + "/ugraphics_image"
font_path = data_path + "/font"
# delete prebuild/data resources
if os.path.exists(image_path):
......
......@@ -55,7 +55,7 @@
*
* @return 0 on success, negative error on failure.
*/
int ugraphics_init(int width, int height);
int32_t ugraphics_init(int32_t width, int32_t height);
/**
* load ttf font file.
......@@ -65,7 +65,7 @@ int ugraphics_init(int width, int height);
*
* @return 0 on success, negative error on failure.
*/
int ugraphics_load_font(const char *filename, int size);
int32_t ugraphics_load_font(const char *filename, int32_t size);
/**
* load ttf font file.
......@@ -74,7 +74,7 @@ int ugraphics_load_font(const char *filename, int size);
* Refer to SDL_ttf.h: TTF_STYLE_NORMAL/TTF_STYLE_BOLD...
*
*/
void ugraphics_set_font_style(int style);
void ugraphics_set_font_style(int32_t style);
/**
* Release graphics all resources.
......@@ -92,15 +92,16 @@ void ugraphics_flip(void);
* Clear graphics on window.
*
*/
void ugraphics_clear(void);
int32_t ugraphics_clear(void);
/**
* Set graphics default color.
*
* @param[in] color grapchic color.
*
* @return 0 on success, negative error on failure.
*/
void ugraphics_set_color(unsigned int color);
int32_t ugraphics_set_color(uint32_t color);
/**
* Draw empty rectangle to the window.
......@@ -109,8 +110,10 @@ void ugraphics_set_color(unsigned int color);
* @param[in] y grapchic y location on window.
* @param[in] w grapchic width on window.
* @param[in] h grapchic height on window.
*
* @return 0 on success, negative error on failure.
*/
void ugraphics_draw_rect(int x, int y, int w, int h);
int32_t ugraphics_draw_rect(int32_t x, int32_t y, int32_t w, int32_t h);
/**
* Fill full rectangle to the window.
......@@ -119,8 +122,10 @@ void ugraphics_draw_rect(int x, int y, int w, int h);
* @param[in] y grapchic y location on window.
* @param[in] w grapchic width on window.
* @param[in] h grapchic height on window.
*
* @return 0 on success, negative error on failure.
*/
void ugraphics_fill_rect(int x, int y, int w, int h);
int32_t ugraphics_fill_rect(int32_t x, int32_t y, int32_t w, int32_t h);
/**
* Draw line on window.
......@@ -129,8 +134,10 @@ void ugraphics_fill_rect(int x, int y, int w, int h);
* @param[in] y1 line y1 start position.
* @param[in] x2 line x2 end position.
* @param[in] y2 line y2 end position.
*
* @return 0 on success, negative error on failure.
*/
void ugraphics_draw_line(int x1, int y1, int x2, int y2);
int32_t ugraphics_draw_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
/**
* Draw string on window.
......@@ -141,7 +148,7 @@ void ugraphics_draw_line(int x1, int y1, int x2, int y2);
*
* @return 0 on success, negative error on failure.
*/
void ugraphics_draw_string(char *string, int x, int y);
int32_t ugraphics_draw_string(char *string, int32_t x, int32_t y);
/**
* Count string width.
......@@ -150,7 +157,7 @@ void ugraphics_draw_string(char *string, int x, int y);
*
* @return 0 on success, negative error on failure.
*/
int ugraphics_string_width(char *string);
int32_t ugraphics_string_width(char *string);
/**
* Save image graphic buffer to a image file.
......@@ -160,7 +167,7 @@ int ugraphics_string_width(char *string);
*
* @return 0 on success, negative error on failure.
*/
int ugraphics_save_image(char *buffer, int32_t len, const char *path);
int32_t ugraphics_save_image(char *buffer, int32_t len, const char *path);
/**
* Release graphics all resources.
......@@ -171,7 +178,7 @@ int ugraphics_save_image(char *buffer, int32_t len, const char *path);
*
* @return 0 on success, negative error on failure.
*/
int ugraphics_draw_image(const char *file, int x, int y);
int32_t ugraphics_draw_image(const char *file, int32_t x, int32_t y);
/**
* @}
......
......@@ -42,7 +42,7 @@ depends:
build_config:
include:
- include
prebuild_script: cp_resources.py
# prebuild_script: cp_resources.py
# source_file: # <可选项> 指定参与编译的源代码文件,支持通配符,采用相对路径
# - src/*.c # 例:组件 src 目录下所有的扩展名为 c 的源代码文件
......@@ -51,7 +51,7 @@ source_file:
- src/jpegdec/jpegdec.c ? <AOS_COMP_JPEG>
- src/jpegdec/to_rgb565.c ? <CONFIG_UGRAPHICS_FORMAT>
- src/jpegdec/rotate.c ? <CONFIG_UGRAPHICS_ROTATE>
- src/example/ugraphics_example.c
# - src/example/ugraphics_example.c
## 第五部分:配置信息
def_config: # 组件的可配置项
......
......@@ -4,38 +4,41 @@
#include <stdint.h>
#include <stdio.h>
#include "wifi_camera.h"
#include "ugraphics.h"
#ifdef AOS_COMP_CLI
#include "aos/cli.h"
#endif
#define WIDTH 320
#define HEIGHT 240
#define WIDTH SCREEN_W
#define HEIGHT SCREEN_H
static void ugraphics_comp_example(int argc, char **argv)
{
int ret;
if (argc < 3)
if (argc < 2)
printf("wrong parameter number\n");
/*Initialize ugraphics window*/
ret = ugraphics_init(WIDTH, HEIGHT);
if (ret < 0) {
printf("ugraphics init fail, ret: %d\n", ret);
return;
}
if (!strncmp(argv[1], "draw", 4)) {
if (!strncmp(argv[1], "init", 4)) {
/*Initialize ugraphics window*/
ret = ugraphics_init(WIDTH, HEIGHT);
if (ret < 0) {
printf("ugraphics init fail, ret: %d\n", ret);
return;
}
} else if (!strncmp(argv[1], "draw", 4)) {
/*Clear buffer on screen*/
ugraphics_clear();
if (!strncmp(argv[2], "rect", 4)) {
/*Draw empty rectangle*/
ugraphics_draw_rect(0, 0, WIDTH / 2, HEIGHT / 2);
printf("ugraphics draw rectangle ok!\n");
} else if (!strncmp(argv[2], "line", 4)) {
/*Draw line*/
ugraphics_draw_line(0, WIDTH / 4, WIDTH, HEIGHT / 4);
ugraphics_draw_line(0, HEIGHT / 4, WIDTH, HEIGHT / 4);
printf("ugraphics draw line ok!\n");
} else if (!strncmp(argv[2], "jpg", 3)) {
/*Draw image*/
......@@ -47,40 +50,47 @@ static void ugraphics_comp_example(int argc, char **argv)
printf("ugraphics draw png ok!\n");
} else if (!strncmp(argv[2], "string", 6)) {
/*Load default ttf font*/
ret = ugraphics_load_font("/data/ugraphics_image/font/simfang.ttf", 18);
ret = ugraphics_load_font("/data/ugraphics_image/font/Alibaba-PuHuiTi-Heavy.ttf", 18);
if (ret < 0) {
printf("ugraphics load font fail, ret: %d\n", ret);
return;
}
/*Set window default color*/
ugraphics_set_color(COLOR_RED);
/*Set color*/
ugraphics_set_color(COLOR_BLACK);
/*Set font style*/
ugraphics_set_font_style(UGRAPHICS_FONT_STYLE);
/*Draw string*/
ugraphics_draw_string("Welcome to AliOS Things!", WIDTH / 4, HEIGHT / 2);
ugraphics_draw_string("Welcome to AliOS Things!", WIDTH / 8, HEIGHT / 2);
printf("ugraphics draw string ok!\n");
}
/*Show graphics on screen*/
ugraphics_flip();
} else if (!strncmp(argv[1], "fill", 4)) {
if (!strncmp(argv[2], "rect", 4)) {
/*Clear buffer on screen*/
ugraphics_clear();
/*Fill full rectangle*/
ugraphics_fill_rect(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2);
printf("ugraphics fill rectangle ok!\n");
} else {
printf("unkown command\n");
}
/*Show graphics on screen*/
ugraphics_flip();
} else if (!strncmp(argv[2], "clear", 5)) {
/*Clear buffer on screen*/
ugraphics_clear();
printf("ugraphics clear screen ok!\n");
} else if (!strncmp(argv[2], "quit", 4)) {
/*Quit ugraphics component*/
ugraphics_quit();
}
/*Show graphics on screen*/
ugraphics_flip();
/*Quit ugraphics component*/
ugraphics_quit();
return;
}
......
......@@ -13,17 +13,17 @@ struct { char *string; SDL_Texture *texture; } text[MAX_TEXT];
struct { char *file; SDL_Texture *texture; } image[MAX_IMAGE];
// Internal function prototypes
static void graphics_generate_text(char *string);
static int32_t graphics_generate_text(char *string);
static void graphics_wipe_text(void);
static void graphics_draw_texture(SDL_Texture *texture, int x, int y);
static int32_t graphics_draw_texture(SDL_Texture *texture, int32_t x, int32_t y);
#endif
#define TAG "ugraphics"
int text_count = 0;
int image_count = 0;
int32_t text_count = 0;
int32_t image_count = 0;
int ugraphics_init(int width, int height)
int32_t ugraphics_init(int32_t width, int32_t height)
{
#ifdef AOS_COMP_SDL2
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
......@@ -46,9 +46,14 @@ int ugraphics_init(int width, int height)
#endif
}
int ugraphics_load_font(const char *filename, int size)
int32_t ugraphics_load_font(const char *filename, int32_t size)
{
#ifdef AOS_COMP_SDL2
if (font) {
LOG("font has been opened\n");
return 0;
}
if (TTF_Init() == -1) {
LOGE(TAG, "TTF_Init: %s\n", TTF_GetError());
return -1;
......@@ -63,7 +68,7 @@ int ugraphics_load_font(const char *filename, int size)
#endif
}
void ugraphics_set_font_style(int style)
void ugraphics_set_font_style(int32_t style)
{
#ifdef AOS_COMP_SDL2
if (font)
......@@ -77,7 +82,7 @@ void ugraphics_set_font_style(int style)
void graphics_wipe_text(void)
{
#ifdef AOS_COMP_SDL2
for (int i = 0; i < text_count; i++) {
for (int32_t i = 0; i < text_count; i++) {
if (text[i].string != NULL)
free(text[i].string);
SDL_DestroyTexture(text[i].texture);
......@@ -113,22 +118,22 @@ void ugraphics_flip(void)
#endif
}
void ugraphics_clear(void)
int32_t ugraphics_clear(void)
{
#ifdef AOS_COMP_SDL2
SDL_RenderClear(renderer);
return SDL_RenderClear(renderer);
#endif
}
void ugraphics_set_color(unsigned int color)
int32_t ugraphics_set_color(uint32_t color)
{
#ifdef AOS_COMP_SDL2
SDL_SetRenderDrawColor(renderer, color >> 24,
return SDL_SetRenderDrawColor(renderer, color >> 24,
color >> 16, color >> 8, color);
#endif
}
static void graphics_generate_text(char *string)
static int32_t graphics_generate_text(char *string)
{
#ifdef AOS_COMP_SDL2
SDL_Color color;
......@@ -136,90 +141,107 @@ static void graphics_generate_text(char *string)
SDL_Surface *surface = TTF_RenderUTF8_Blended(font, string, color);
if (!surface) {
LOGE(TAG, "TTF_RenderUTF8_Blended: %s\n", TTF_GetError());
return;
return -1;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
if (!texture) {
LOGE(TAG, "SDL_CreateTextureFromSurface: %s\n", SDL_GetError());
return;
return -1;
}
text[text_count].string = strdup(string);
// text[text_count].string = string;
text[text_count].texture = texture;
text_count++;
return 0;
#endif
}
void graphics_wipe_image(void)
{
#ifdef AOS_COMP_SDL2
for (int i = 0; i < image_count; i++)
for (int32_t i = 0; i < image_count; i++)
SDL_DestroyTexture(image[i].texture);
image_count = 0;
#endif
}
void ugraphics_draw_rect(int x, int y, int w, int h)
int32_t ugraphics_draw_rect(int32_t x, int32_t y, int32_t w, int32_t h)
{
#ifdef AOS_COMP_SDL2
SDL_Rect rect = { x, y, w, h };
SDL_RenderDrawRect(renderer, &rect);
return SDL_RenderDrawRect(renderer, &rect);
#endif
}
void ugraphics_fill_rect(int x, int y, int w, int h)
int32_t ugraphics_fill_rect(int32_t x, int32_t y, int32_t w, int32_t h)
{
#ifdef AOS_COMP_SDL2
SDL_Rect rect = { x, y, w, h };
SDL_RenderFillRect(renderer, &rect);
return SDL_RenderFillRect(renderer, &rect);
#endif
}
void ugraphics_draw_line(int x1, int y1, int x2, int y2)
int32_t ugraphics_draw_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
#ifdef AOS_COMP_SDL2
SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
return SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
#endif
}
#ifdef AOS_COMP_SDL2
static void graphics_draw_texture(SDL_Texture *texture, int x, int y)
static int32_t graphics_draw_texture(SDL_Texture *texture, int32_t x, int32_t y)
{
int32_t ret;
SDL_Rect drect = { x, y, 0, 0 };
SDL_QueryTexture(texture, NULL, NULL, &drect.w, &drect.h);
ret = SDL_QueryTexture(texture, NULL, NULL, &drect.w, &drect.h);
if (ret < 0)
return -1;
printf("drect.w: %d, drect.h: %d\n", drect.w, drect.h);
SDL_RenderCopy(renderer, texture, NULL, &drect);
ret = SDL_RenderCopy(renderer, texture, NULL, &drect);
if (ret < 0)
return -1;
return 0;
}
#endif
void ugraphics_draw_string(char *string, int x, int y)
int32_t ugraphics_draw_string(char *string, int32_t x, int32_t y)
{
int32_t ret;
#ifdef AOS_COMP_SDL2
if (strcmp(string, "") == 0)
return;
for (int i = 0; i < text_count; i++) {
return -1;
for (int32_t i = 0; i < text_count; i++) {
if (strcmp(string, text[i].string) != 0)
continue;
graphics_draw_texture(text[i].texture, x, y);
return;
ret = graphics_draw_texture(text[i].texture, x, y);
if (ret < 0)
return -1;
}
/*If a texture for the string doesn't exist create it*/
graphics_generate_text(string);
graphics_draw_texture(text[text_count - 1].texture, x, y);
ret = graphics_generate_text(string);
if (ret < 0)
return -1;
ret = graphics_draw_texture(text[text_count - 1].texture, x, y);
if (ret < 0)
return -1;
#endif
return 0;
}
int ugraphics_string_width(char *string)
int32_t ugraphics_string_width(char *string)
{
#ifdef AOS_COMP_SDL2
if (strcmp(string, "") == 0)
return 0;
for (int i = 0; i < text_count; i++) {
for (int32_t i = 0; i < text_count; i++) {
if (strcmp(string, text[i].string) != 0)
continue;
int width;
int32_t width;
SDL_QueryTexture(text[i].texture, NULL, NULL, &width, NULL);
return width;
}
......@@ -227,7 +249,7 @@ int ugraphics_string_width(char *string)
return 0;
}
static void graphics_generate_image(char *file)
static int32_t graphics_generate_image(char *file)
{
#ifdef AOS_COMP_SDL2
SDL_Texture *image_texture = IMG_LoadTexture(renderer, file);
......@@ -240,29 +262,37 @@ static void graphics_generate_image(char *file)
image[image_count].texture = image_texture;
image_count++;
#endif
return 0;
}
int ugraphics_draw_image(const char *file, int x, int y)
int32_t ugraphics_draw_image(const char *file, int32_t x, int32_t y)
{
int32_t ret;
#ifdef AOS_COMP_SDL2
SDL_Rect drect = { x, y, 0, 0 };
if (strcmp(file, "") == 0) {
LOG("[%s]file is null\n");
return;
return -1;
}
for (int i = 0; i < image_count; i++) {
for (int32_t i = 0; i < image_count; i++) {
if (strcmp(file, image[i].file) != 0)
continue;
graphics_draw_texture(image[i].texture, x, y);
return 0;
}
graphics_generate_image(file);
graphics_draw_texture(image[image_count - 1].texture, x, y);
ret = graphics_generate_image(file);
if (ret < 0)
return -1;
ret = graphics_draw_texture(image[image_count - 1].texture, x, y);
if (ret < 0)
return -1;
#endif
return 0;
}
int ugraphics_save_image(char *buffer, int32_t len, const char *path)
int32_t ugraphics_save_image(char *buffer, int32_t len, const char *path)
{
if (!buffer) {
LOGE(TAG, "buffer is null\n");
......
/* Provide support for both ANSI and non-ANSI environments. */
/* Some ANSI environments are "broken" in the sense that __STDC__ cannot be
relied upon to have it's intended meaning. Therefore we must use our own
concoction: _HAVE_STDC. Always use _HAVE_STDC instead of __STDC__ in newlib
sources!
To get a strict ANSI C environment, define macro __STRICT_ANSI__. This will
"comment out" the non-ANSI parts of the ANSI header files (non-ANSI header
files aren't affected). */
#ifndef _ANSIDECL_H_
#define _ANSIDECL_H_
//#include <newlib.h>
//#include <sys/config.h>
/* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */
#ifndef __GNUC_PREREQ
# if defined __GNUC__ && defined __GNUC_MINOR__
# define __GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
# else
# define __GNUC_PREREQ(maj, min) 0
# endif
#endif /* __GNUC_PREREQ */
/* Version with trailing underscores for BSD compatibility. */
#define __GNUC_PREREQ__(ma, mi) __GNUC_PREREQ(ma, mi)
/* First try to figure out whether we really are in an ANSI C environment. */
/* FIXME: This probably needs some work. Perhaps sys/config.h can be
prevailed upon to give us a clue. */
#ifdef __STDC__
#define _HAVE_STDC
#endif
/* ISO C++. */
#ifdef __cplusplus
#if !(defined(_BEGIN_STD_C) && defined(_END_STD_C))
#ifdef _HAVE_STD_CXX
#define _BEGIN_STD_C namespace std { extern "C" {
#define _END_STD_C } }
#else
#define _BEGIN_STD_C extern "C" {
#define _END_STD_C }
#endif
#if __GNUC_PREREQ (3, 3)
#define _NOTHROW __attribute__ ((__nothrow__))
#else
#define _NOTHROW throw()
#endif
#endif
#else
#define _BEGIN_STD_C
#define _END_STD_C
#define _NOTHROW
#endif
#ifdef _HAVE_STDC
#define _PTR void *
#define _AND ,
#define _NOARGS void
#define _CONST const
#define _VOLATILE volatile
#define _SIGNED signed
#define _DOTS , ...
#define _VOID void
#ifdef __CYGWIN__
#define _EXFUN_NOTHROW(name, proto) __cdecl name proto _NOTHROW
#define _EXFUN(name, proto) __cdecl name proto
#define _EXPARM(name, proto) (* __cdecl name) proto
#define _EXFNPTR(name, proto) (__cdecl * name) proto
#else
#define _EXFUN_NOTHROW(name, proto) name proto _NOTHROW
#define _EXFUN(name, proto) name proto
#define _EXPARM(name, proto) (* name) proto
#define _EXFNPTR(name, proto) (* name) proto
#endif
#define _DEFUN(name, arglist, args) name(args)
#define _DEFUN_VOID(name) name(_NOARGS)
#define _CAST_VOID (void)
#ifndef _LONG_DOUBLE
#define _LONG_DOUBLE long double
#endif
#ifndef _PARAMS
#define _PARAMS(paramlist) paramlist
#endif
#else
#define _PTR char *
#define _AND ;
#define _NOARGS
#define _CONST
#define _VOLATILE
#define _SIGNED
#define _DOTS
#define _VOID void
#define _EXFUN(name, proto) name()
#define _EXFUN_NOTHROW(name, proto) name()
#define _DEFUN(name, arglist, args) name arglist args;
#define _DEFUN_VOID(name) name()
#define _CAST_VOID
#define _LONG_DOUBLE double
#ifndef _PARAMS
#define _PARAMS(paramlist) ()
#endif
#endif
/* Support gcc's __attribute__ facility. */
#ifdef __GNUC__
#define _ATTRIBUTE(attrs) __attribute__ (attrs)
#else
#define _ATTRIBUTE(attrs)
#endif
/* The traditional meaning of 'extern inline' for GCC is not
to emit the function body unless the address is explicitly
taken. However this behaviour is changing to match the C99
standard, which uses 'extern inline' to indicate that the
function body *must* be emitted. Likewise, a function declared
without either 'extern' or 'static' defaults to extern linkage
(C99 6.2.2p5), and the compiler may choose whether to use the
inline version or call the extern linkage version (6.7.4p6).
If we are using GCC, but do not have the new behaviour, we need
to use extern inline; if we are using a new GCC with the
C99-compatible behaviour, or a non-GCC compiler (which we will
have to hope is C99, since there is no other way to achieve the
effect of omitting the function if it isn't referenced) we use
'static inline', which c99 defines to mean more-or-less the same
as the Gnu C 'extern inline'. */
#if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__)
/* We're using GCC, but without the new C99-compatible behaviour. */
#define _ELIDABLE_INLINE extern __inline__ _ATTRIBUTE ((__always_inline__))
#else
/* We're using GCC in C99 mode, or an unknown compiler which
we just have to hope obeys the C99 semantics of inline. */
#define _ELIDABLE_INLINE static __inline__
#endif
#if __GNUC_PREREQ (3, 1)
#define _NOINLINE __attribute__ ((__noinline__))
#define _NOINLINE_STATIC _NOINLINE static
#else
/* On non-GNU compilers and GCC prior to version 3.1 the compiler can't be
trusted not to inline if it is static. */
#define _NOINLINE
#define _NOINLINE_STATIC
#endif
#endif /* _ANSIDECL_H_ */
#ifndef _ASSERT_H_
#define _ASSERT_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef assert
#undef assert
#endif
#define STRINGIFY_VALUE(s) STRINGIFY(s)
#define STRINGIFY(s) #s
void __assert(const char* fmt);
#define assert(boolcondition) { if(!(boolcondition)) __assert( \
"ASSERTION FAILED in file : " \
__FILE__ \
" at line" \
STRINGIFY_VALUE(__LINE__)); }
#ifdef __cplusplus
} // extern C
#endif
#endif /* _ASSERT_H_ */
#ifndef CTYPE_H
#define CTYPE_H
/*
* NOTE! This ctype does not handle EOF like the standard C
* library is required to.
*/
#define _U 0x01 /* upper */
#define _L 0x02 /* lower */
#define _D 0x04 /* digit */
#define _C 0x08 /* cntrl */
#define _P 0x10 /* punct */
#define _S 0x20 /* white space (space/lf/tab) */
#define _X 0x40 /* hex digit */
#define _SP 0x80 /* hard space (0x20) */
extern const unsigned char _ctype[];
#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
#define isdigit(c) ((__ismask(c)&(_D)) != 0)
#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
#define islower(c) ((__ismask(c)&(_L)) != 0)
#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
#define ispunct(c) ((__ismask(c)&(_P)) != 0)
#define isspace(c) ((__ismask(c)&(_S)) != 0)
#define isupper(c) ((__ismask(c)&(_U)) != 0)
#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
#define isascii(c) (((unsigned char)(c))<=0x7f)
#define toascii(c) (((unsigned char)(c))&0x7f)
static inline unsigned char __tolower(unsigned char c)
{
if (isupper(c))
c -= 'A'-'a';
return c;
}
static inline unsigned char __toupper(unsigned char c)
{
if (islower(c))
c -= 'a'-'A';
return c;
}
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
#endif /* CTYPE_H */
#ifndef _GENERIC_ERRNO_H
#define _GENERIC_ERRNO_H
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#endif
/*
* minilibc stdio
*
* Copyright (C): 2012 Hangzhou C-SKY Microsystem Co.,LTD.
* Author: Junshan Hu (junshan_hu@c-sky.com)
* Contrbutior: Chunqiang Li
* Date: 2012-5-4
*/
#ifndef _MINILIBC_STDIO_H_
#define _MINILIBC_STDIO_H__
#include <stdarg.h>
#define BUFSIZE 2048
struct __stdio_file {
int fd;
int flags;
unsigned int bs; /* read: bytes in buffer */
unsigned int bm; /* position in buffer */
// unsigned int buflen; /* length of buf */
// char *buf;
struct __stdio_file *next; /* for fflush */
unsigned char ungetbuf;
char ungotten;
unsigned int lock;
};
#define ERRORINDICATOR 1
#define EOFINDICATOR 2
#define BUFINPUT 4
#define BUFLINEWISE 8
#define NOBUF 16
#define STATICBUF 32
#define FDPIPE 64
#define CANREAD 128
#define CANWRITE 256
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*fmt_out_fn)(char * strbuf, int len);
typedef int (*fmt_in_fn)(void);
extern fmt_out_fn g_current_outputs;
extern fmt_in_fn g_current_inputs;
#define print_current_out_set(fn) do{g_current_outputs = fn;}while(0)
#define print_current_in_set(fn) do{g_current_inputs = fn;}while(0)
static inline int is_normal_outputs(void)
{
if(g_current_inputs)
return 0;
return 1;
}
/* ..scanf */
struct arg_scanf {
void *data;
int (*getch)(void*);
int (*putch)(int,void*);
};
int __v_scanf(struct arg_scanf* fn, const char *format, va_list arg_ptr);
struct arg_printf {
void *data;
int (*put)(void*,size_t,void*);
};
int yoc__v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr);
int __isinf(double d);
int __isnan(double d);
int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2);
int __lltostr(char *s, int size, unsigned long long i, int base, char UpCase);
int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase);
#ifdef __cplusplus
}
#endif
#endif /* _MINILIBC_STDIO_H_ */
/*
* Copyright (C) 2017-2019 Alibaba Group Holding Limited
*/
/**************************************************************************//**
* @file soc.h
* @brief CSI Core Peripheral Access Layer Header File for
* CSKYSOC Device Series
* @version V1.0
* @date 06. Mar 2019
* @vendor csky
* @chip pangu
******************************************************************************/
#ifndef _SOC_H_
#define _SOC_H_
#ifdef __CK804__
#ifndef SYSTEM_CLOCK
#define SYSTEM_CLOCK (48000000) // 48Mhz fpga
#define IHS_VALUE (48000000)
#endif
#ifndef LSP_DEFAULT_FREQ
#define LSP_DEFAULT_FREQ (48000000) // 48Mhz fpga
#define EHS_VALUE (12000000)
#endif
#ifndef DSP_CLOCK
#define DSP_CLOCK (250000000) // 250Mhz
#endif
#ifndef RTC_CLOCK
#define RTC_CLOCK (32768) // 32.768Mhz
#endif
/* ---------------------- YunVoice_V2 804ef Specific Interrupt Numbers --------------------- */
typedef enum IRQn {
ERROR_INTC_IRQn = 0, /* error Interrupt */
WDT_IRQn = 1, /* wdt Interrupt */
PLL_IRQn = 2, /* pll lose lock Interrupt */
PLL_FRAC_IRQn = 3, /* pll lose lock Interrupt */
WCOM_IRQn = 4, /* cpu0 wcom Interrupt */
RCOM_IRQn = 5, /* cpu0 rcom Interrupt */
PMU_IRQn = 6, /* PMU Interrupt */
MCA_IRQn = 7, /* MCA Interrupt */
DMAC0_IRQn = 8, /* DMA0 Interrupt */
DMAC1_IRQn = 9, /* DMA1 Interrupt */
CORET_IRQn = 10, /* CTIM0 Interrupt */
RTC_IRQn = 11, /* RTC Interrupt */
SDIO1_IRQn = 12, /* SDMMC Interrupt */
USB_IRQn = 13, /* USB Interrupt */
QSPI_IRQn = 14, /* QSPI Interrupt */
SDIO0_IRQn = 15, /* SDIO Interrupt */
CODEC_WHISPER_IRQn = 16, /* codec whisper Interrupt */
CODEC_INTC_IRQn = 17, /* code Interrupt */
GSK_INTC_IRQn = 18, /* gsk Interrupt */
LPTIMER_INT0_IRQn = 19, /* timer0 Interrupt */
LPTIMER_INT1_IRQn = 20, /* timer0 Interrupt */
TIMER0_INT0_IRQn = 21, /* timer1 Interrupt */
TIMER0_INT1_IRQn = 22, /* timer1 Interrupt */
TIMER1_INT0_IRQn = 23, /* timer2 Interrupt */
TIMER1_INT1_IRQn = 24, /* timer2 Interrupt */
TIMER2_INT0_IRQn = 25, /* timer3 Interrupt */
TIMER2_INT1_IRQn = 26, /* timer3 Interrupt */
USI0_IRQn = 27, /* USI0 Interrupt */
USI1_IRQn = 28, /* USI1 Interrupt */
USI2_IRQn = 29, /* USI2 Interrupt */
USI3_IRQn = 30, /* USI3 Interrupt */
I2S0_IRQn = 31, /* I2S0 Interrupt */
I2S1_IRQn = 32, /* I2S1 Interrupt */
I2S2_IRQn = 33, /* I2S2 Interrupt */
I2S3_IRQn = 34, /* I2S3 Interrupt */
SPDIF0_IRQn = 35, /* spdif0 Interrupt */
UART0_HS_IRQn = 36, /* I2S0 Interrupt */
UART1_HS_IRQn = 37, /* I2S1 Interrupt */
UART2_IRQn = 38, /* I2S2 Interrupt */
UART3_IRQn = 39, /* I2S3 Interrupt */
TDM_IRQn = 40, /* tdm Interrupt */
PDM_IRQn = 41, /* pdm Interrupt */
GPIO0_IRQn = 42, /* gpio0 Interrupt */
PLL_LL_IRQn = 43, /* pll lose lock Interrupt */
PLL_LL_FRAC_IRQn = 44, /* pll lose lock FRAC Interrupt */
PWM0_IRQn = 45, /* pwm0 Interrupt */
RSA_IRQn = 46, /* rsa Interrupt */
SHA_IRQn = 47, /* sha Interrupt */
AES_IRQn = 48, /* aes Interrupt */
TRNG_IRQn = 49, /* trng Interrupt */
GPIO1_IRQn = 50, /* gpio1 Interrupt */
PWM1_IRQn = 51, /* pwm1 Interrupt */
} IRQn_Type;
/*cpu0*/
#define CONFIG_DMA_CHANNEL_NUM 8
#define CONFIG_PER_DMAC0_CHANNEL_NUM 0
#define CONFIG_PER_DMAC1_CHANNEL_NUM 8
#define CONFIG_AES_NUM 1
#define CONFIG_RSA_NUM 1
#define CONFIG_SHA_NUM 1
#define CONFIG_TRNG_NUM 1
#define CONFIG_RTC_NUM 1
#define CONFIG_WDT_NUM 1
#define CONFIG_QSPI_NUM 1
#define CONFIG_SPIFLASH_NUM 1
#define CONFIG_MAILBOX_NUM 3
#define CONFIG_MAILBOX_CHANNEL_NUM 2
#define CONFIG_EFUSEC_NUM 1
#define CONFIG_SDIO_NUM 2
#define CSKY_TIPC_MOUDULE_NUM 16
#define CONFIG_CODEC_NUM 1
#else /* ck805 */
#define CONFIG_QSPI_NUM 1
#define CONFIG_SPIFLASH_NUM 1
#ifndef SYSTEM_CLOCK
#define SYSTEM_CLOCK (18000000) // 18Mhz fpga
#define IHS_VALUE (18000000)
#endif
#ifndef LSP_DEFAULT_FREQ
#define LSP_DEFAULT_FREQ (18000000) // 18Mhz fpga
#define EHS_VALUE (12000000)
#endif
#ifndef DSP_CLOCK
#define DSP_CLOCK (250000000) // 250Mhz
#endif
#ifndef RTC_CLOCK
#define RTC_CLOCK (32768) // 32.768Khz
#endif
/* ---------------------- YunVoice_V2 805 Specific Interrupt Numbers --------------------- */
typedef enum IRQn {
ERROR_INTC_IRQn = 0, /* error Interrupt */
WDT_IRQn = 1, /* wdt Interrupt */
PLL_IRQn = 2, /* pll lose lock Interrupt */
PLL_FRAC_IRQn = 3, /* pll lose lock Interrupt */
WCOM_IRQn = 4, /* cpu0 wcom Interrupt */
RCOM_IRQn = 5, /* cpu0 rcom Interrupt */
PMU_IRQn = 6, /* PMU Interrupt */
MCA_IRQn = 7, /* MCA Interrupt */
DMAC0_IRQn = 8, /* DMA0 Interrupt */
DMAC1_IRQn = 9, /* DMA1 Interrupt */
CORET_IRQn = 10, /* CTIM0 Interrupt */
RTC_IRQn = 11, /* RTC Interrupt */
SDIO1_IRQn = 12, /* SDMMC Interrupt */
USB_IRQn = 13, /* USB Interrupt */
QSPI_IRQn = 14, /* QSPI Interrupt */
SDIO0_IRQn = 15, /* SDIO Interrupt */
CODEC_WHISPER_IRQn = 16, /* codec whisper Interrupt */
CODEC_INTC_IRQn = 17, /* code Interrupt */
GSK_INTC_IRQn = 18, /* gsk Interrupt */
LPTIMER_INT0_IRQn = 19, /* timer0 Interrupt */
LPTIMER_INT1_IRQn = 20, /* timer0 Interrupt */
TIMER0_INT0_IRQn = 21, /* timer1 Interrupt */
TIMER0_INT1_IRQn = 22, /* timer1 Interrupt */
TIMER1_INT0_IRQn = 23, /* timer2 Interrupt */
TIMER1_INT1_IRQn = 24, /* timer2 Interrupt */
TIMER2_INT0_IRQn = 25, /* timer3 Interrupt */
TIMER2_INT1_IRQn = 26, /* timer3 Interrupt */
USI0_IRQn = 27, /* USI0 Interrupt */
USI1_IRQn = 28, /* USI1 Interrupt */
USI2_IRQn = 29, /* USI2 Interrupt */
USI3_IRQn = 30, /* USI3 Interrupt */
I2S0_IRQn = 31, /* I2S0 Interrupt */
I2S1_IRQn = 32, /* I2S1 Interrupt */
I2S2_IRQn = 33, /* I2S2 Interrupt */
I2S3_IRQn = 34, /* I2S3 Interrupt */
SPDIF0_IRQn = 35, /* spdif0 Interrupt */
UART0_HS_IRQn = 36, /* uart0 Interrupt */
UART1_HS_IRQn = 37, /* uart1 Interrupt */
UART2_IRQn = 38, /* uart2 Interrupt */
UART3_IRQn = 39, /* uart3 Interrupt */
TDM_IRQn = 40, /* tdm Interrupt */
PDM_IRQn = 41, /* pdm Interrupt */
GPIO0_IRQn = 42, /* gpio0 Interrupt */
PLL_LL_IRQn = 43, /* pll lose lock Interrupt */
PLL_LL_FRAC_IRQn = 44, /* pll lose lock FRAC Interrupt */
PWM0_IRQn = 45, /* pwm0 Interrupt */
RSA_IRQn = 46, /* rsa Interrupt */
SHA_IRQn = 47, /* sha Interrupt */
AES_IRQn = 48, /* aes Interrupt */
TRNG_IRQn = 49, /* trng Interrupt */
GPIO1_IRQn = 50, /* gpio1 Interrupt */
PWM1_IRQn = 51, /* pwm1 Interrupt */
} IRQn_Type;
#define CONFIG_DMA_CHANNEL_NUM 4
#define CONFIG_PER_DMAC0_CHANNEL_NUM 4
#define CONFIG_PER_DMAC1_CHANNEL_NUM 0
#define CONFIG_RTC_NUM 1
#define CONFIG_WDT_NUM 1
#define CONFIG_MAILBOX_NUM 3
#define CONFIG_MAILBOX_CHANNEL_NUM 2
#define CONFIG_CODEC_NUM 1
#define CONFIG_SDIO_NUM 2
#endif
/* ================================================================================ */
/* ================ Processor and Core Peripheral Section ================ */
/* ================================================================================ */
/* -------- Configuration of the CK805 Processor and Core Peripherals ------- */
#define __CK805_REV 0x0000U /* Core revision r0p0 */
#define __MGU_PRESENT 0 /* MGU present or not */
#define __NVIC_PRIO_BITS 2 /* Number of Bits used for Priority Levels */
#include "csi_core.h" /* Processor and core peripherals */
#include "stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
//DMA0
DWENUM_DMA_I2S0_TX, //0
DWENUM_DMA_I2S0_RX,
DWENUM_DMA_I2S1_TX,
DWENUM_DMA_I2S1_RX,
DWENUM_DMA_USI0_TX,
DWENUM_DMA_USI0_RX, //5
DWENUM_DMA_USI1_TX,
DWENUM_DMA_USI1_RX,
DWENUM_DMA_UART0_TX,
DWENUM_DMA_UART0_RX,
DWENUM_DMA_UART1_TX, //10
DWENUM_DMA_UART1_RX, //11
//DMA1
//fixed
DWENUM_DMA_CODEC_ADC_0, //12
DWENUM_DMA_CODEC_ADC_1,
DWENUM_DMA_CODEC_ADC_4,
DWENUM_DMA_CODEC_ADC_5, //15
DWENUM_DMA_UART2_TX,
DWENUM_DMA_UART2_RX,
DWENUM_DMA_USI2_TX,
DWENUM_DMA_USI2_RX, //19
//variable
DWENUM_DMA_I2S2_TX, //20
DWENUM_DMA_I2S2_RX,
DWENUM_DMA_CODEC_ADC_6,
DWENUM_DMA_CODEC_ADC_7,
DWENUM_DMA_CODEC_DAC,
DWENUM_DMA_RESERVED_1, //25
DWENUM_DMA_I2S3_TX,
DWENUM_DMA_I2S3_RX,
DWENUM_DMA1_USI3_TX,
DWENUM_DMA1_USI3_RX,
DWENUM_DMA_UART3_TX, //30
DWENUM_DMA_UART3_RX,
DWENUM_DMA_RESERVED_2, //32
DWENUM_DMA_RESERVED_3,
DWENUM_DMA_SPDIF_TX,
DWENUM_DMA_SPDIF_RX, //35
DWENUM_DMA_RESERVED_4,
DWENUM_DMA_RESERVED_5, //37
DWENUM_DMA_TDM_0,
DWENUM_DMA_TDM_1,
DWENUM_DMA_TDM_2, //40
DWENUM_DMA_TDM_3,
DWENUM_DMA_TDM_4, //42
DWENUM_DMA_TDM_5,
DWENUM_DMA_TDM_6,
DWENUM_DMA_TDM_7, //45
DWENUM_DMA_PDM_0,
DWENUM_DMA_PDM_1, //47
DWENUM_DMA_PDM_2,
DWENUM_DMA_PDM_3,
DWENUM_DMA_CODEC_ADC_2, //50
DWENUM_DMA_CODEC_ADC_3, //51
DWENUM_DMA_MEMORY,
} dwenum_dma_device_e;
typedef enum {
ADDR_SPACE_ERROR = -1,
ADDR_SPACE_EFLASH = 0,
ADDR_SPACE_SRAM = 1,
ADDR_SPACE_PERIPHERAL = 2,
ADDR_SPACE_TCIP = 3
} addr_space_e;
/* ------------------------- Wakeup Number Definition ------------------------ */
typedef enum Wakeupn {
GPIO0_Wakeupn = 0, /* GPIO0 wakeup */
AONTIM_Wakeupn = 1, /* AONTIM wakeup */
RTC_Wakeupn = 2, /* RTC wakeup */
CODEC_WT_Wakeun = 3 /* codec whisper wakeup */
}
Wakeupn_Type;
#define CONFIG_TIMER_NUM 8
#define CONFIG_USI_NUM 4
#define CONFIG_USART_NUM 4
#define CONFIG_PWM_NUM 2
#define CONFIG_PER_PWM_CHANNEL_NUM 12
#define CONFIG_I2S_NUM 4
#define CONFIG_GPIO_PIN_NUM 64
#define CONFIG_GPIO_NUM 2
#define CONFIG_PMU_NUM 1
/* ================================================================================ */
/* ================ Peripheral memory map ================ */
/* ================================================================================ */
#define CSKY_QSPIMEM_BASE (0x08000000UL)
#define CSKY_CK804_TCM0_BASE (0xFFE0000UL)
#define CSKY_CK804_TCM1_BASE (0xFFE8000UL)
#define CSKY_CK804_TCM2_BASE (0xFFF0000UL)
#define CSKY_CK804_TCM3_BASE (0xFFF8000UL)
#define CSKY_CK804_TCM4_BASE (0x10000000UL)
#define CSKY_CK804_TCM5_BASE (0x10008000UL)
#define CSKY_CK804_TCM6_BASE (0x10010000UL)
#define CSKY_CK804_TCM7_BASE (0x10018000UL)
#define CSKY_CK804_TCM_SIZE (0x8000UL)
#define CSKY_FMC_BASE (0x18000000UL)
#define CSKY_FMC_SIZE (0x800000UL)
#define CSKY_SRAM_BASE (CSKY_CK804_TCM2_BASE)
/* AHB SUB0 */
#define CSKY_SDIO0_BASE (0x21000000UL)
#define CSKY_SDIO1_BASE (0x22000000UL)
#define CSKY_DMAC0_BASE (0x23000000UL)
#define CSKY_SASC_BASE (0x24000000UL)
/* AHB SUB1 */
#define CSKY_AES_BASE (0x28000000UL)
#define CSKY_SHA_BASE (0x29000000UL)
#define CSKY_FFT_BASE (0x2A000000UL)
/* AHB SUB2 */
#define CSKY_AONCPR_BASE (0x30000000UL)
#define CSKY_CPR0_BASE (0x31000000UL)
#define CSKY_MCC0_BASE (0x32000000UL)
#define CSKY_RSA_BASE (0x33000000UL)
#define CSKY_TRNG_BASE (0x34000000UL)
/* CPU0 CK804 APB0 */
#define CSKY_WDT_BASE (0x38000000UL)
#define CSKY_RTC_BASE (0x38800000UL)
#define CSKY_LPTIM_BASE (0x39000000UL)
#define CSKY_TIM0_BASE (0x39800000UL)
#define CSKY_EFUSE_BASE (0x3A000000UL)
#define CSKY_QSPIC0_BASE (0x3A800000UL)
#define CSKY_PADREG_BASE (0x3B000000UL)
#define CSKY_TIPC_BASE (0x3B800000UL)
#define CSKY_GPIO0_BASE (0x3C000000UL)
#define CSKY_PWM0_BASE (0x3C800000UL)
#define CSKY_I2S0_BASE (0x3D000000UL)
#define CSKY_I2S1_BASE (0x3D800000UL)
#define CSKY_USI0_BASE (0x3E000000UL)
#define CSKY_USI1_BASE (0x3E800000UL)
#define CSKY_UART0_BASE (0x3F000000UL)
#define CSKY_UART1_BASE (0x3F800000UL)
#define CSKY_CK805_TCM0_BASE (0x80000000UL)
#define CSKY_CK805_TCM1_BASE (0x80020000UL)
#define CSKY_CK805_TCM0_SIZE (0x20000UL)
#define CSKY_CK805_TCM1_SIZE (0x10000UL)
/* CK805 SUB0 */
#define CSKY_DMAC1_BASE (0x88000000UL)
#define CSKY_MCA_BASE (0x89000000UL)
#define CSKY_MCC1_BASE (0x8A000000UL)
#define CSKY_CPR1_BASE (0x8B000000UL)
/* CK805 APB1 */
#define CSKY_CODEC_BASE (0x90000000UL)
#define CSKY_TIM1_BASE (0x90800000UL)
#define CSKY_TIM2_BASE (0x91000000UL)
#define CSKY_SPDIF_BASE (0x91800000UL)
#define CSKY_PDM_BASE (0x92000000UL)
#define CSKY_TDM_BASE (0x92800000UL)
#define CSKY_GPIO1_BASE (0x93000000UL)
#define CSKY_PWM1_BASE (0x93800000UL)
#define CSKY_I2S2_BASE (0x94000000UL)
#define CSKY_I2S3_BASE (0x94800000UL)
#define CSKY_USI2_BASE (0x95000000UL)
#define CSKY_USI3_BASE (0x95800000UL)
#define CSKY_UART2_BASE (0x96000000UL)
#define CSKY_UART3_BASE (0x96800000UL)
#define SDMMC_BASE_ADDR CSKY_SDIO0_BASE
#define SHA_CONTEXT_SIZE (224)
#define CONFIG_USI_V25
#define USI_USART_FUN_DIS 1
/* ================================================================================ */
/* ================ Peripheral declaration ================ */
/* ================================================================================ */
#define YUN_PMU ((pmu_reg_t *)CSKY_AONCPR_BASE)
#define YUN_CPR0 ((cpr0_reg_t *)CSKY_CPR0_BASE)
#define YUN_CPR1 ((cpr1_reg_t *)CSKY_CPR1_BASE)
#include <sys_freq.h>
#include <cpr_regs.h>
#include <pmu_regs.h>
/* ================================================================================ */
/* ================ otp declaration ================ */
/* ================================================================================ */
#define CONFIG_OTP_BASE_ADDR 0
#define CONFIG_OTP_BANK_SIZE 640
#ifdef __cplusplus
}
#endif
#endif /* SOC_H_ */
#ifndef STD_BOOL_H
#define STD_BOOL_H
#ifdef __cplusplus
#else
typedef unsigned char bool;
#define true 1
#define false 0
#endif
#endif
#ifndef STDDEF_H
#define STDDEF_H
#undef NULL
#ifndef __cplusplus
#define NULL ((void *)0)
#else /* C++ */
#define NULL 0
#endif /* C++ */
#endif
#ifndef STDIO_H
#define STDIO_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stddef.h"
#include "stdint.h"
#include "stdarg.h"
/* Standard sprintf() function. Work as the libc one. */
int sprintf(char * buf, const char *fmt, ...);
/* Standard snprintf() function from BSD, more secure... */
int snprintf(char * buf, size_t size, const char *fmt, ...);
/* Standard sscanf() function. Work as the libc one. */
int sscanf(const char * buf, const char * fmt, ...);
/* If you need to code your own printf... */
int vsprintf(char *buf, const char *fmt, va_list ap);
int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
int vsscanf(const char *fp, const char *fmt0, va_list ap);
#ifdef __cplusplus
}
#endif
#endif /* STDIO_H */
/*
* Copyright (C) 2015-2019 Alibaba Group Holding Limited
*/
#ifndef AOS_CANOPEN_H
#define AOS_CANOPEN_H
#ifdef __cplusplus
extern "C" {
#endif
#include <canopen_wrap.h>
int aos_canopen_init(PORT_CAN_TYPE can_port, PORT_TIMER_TYPE timer_port,
uint32_t baud, CO_Data *d);
int aos_canopen_od_init(CO_Data *d, co_register_function_callback_t *fun_callback);
int aos_canopen_od_handler(CO_Data *d, uint16_t index, uint8_t sub_index,
co_objectdict_cb *od_callback);
int aos_init_nodes(CO_Data *d, uint8_t id);
#ifdef __cplusplus
}
#endif
#endif /* AOS_CANOPEN_H */
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册