1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4
5 #include "ucloud_ai_common.h"
6 #include "ulog/ulog.h"
7 #if AOS_COMP_CLI
8 #include "aos/cli.h"
9 #endif
10
11 #define TAG "uclud_ai_example"
12 #define LOG printf
13
ucloud_ai_comp_example(int argc,char ** argv)14 static void ucloud_ai_comp_example(int argc, char **argv)
15 {
16 int model_index = -1;
17 int ret = -1;
18 char *image = NULL;
19
20 if (argc < 2) {
21 LOG("Please test with command: ucloud_ai_example -m [0~14]\n");
22 return;
23 }
24
25 if (!strncmp(argv[1], "init", 4)) {
26 /*init network*/
27 event_service_init(NULL);
28 netmgr_service_init(NULL);
29 LOG("ucloud_ai comp init successfully!\n");
30 return;
31 } else if (!strncmp(argv[1], "-m", 2)) {
32 if (argv[2] < 0 && argv[2] > 14) {
33 LOGE(TAG, "range of model value is 0 ~ 14, please try again\n");
34 return;
35 }
36 } else {
37 LOG("unkown command\n");
38 return;
39 }
40 model_index = atoi(argv[2]);
41
42 /*ucloud ai component init*/
43 ret = ucloud_ai_init();
44 if (ret < 0) {
45 LOGE(TAG, "ucloud_ai_init failed, ret: %d\n", ret);
46 return -1;
47 }
48 /*Config OSS Information*/
49 ucloud_ai_set_key_secret(OSS_ACCESS_KEY, OSS_ACCESS_SECRET);
50 ucloud_ai_set_oss_endpoint(OSS_ENDPOINT);
51 ucloud_ai_set_oss_bucket(OSS_BUCKET);
52
53 switch (model_index) {
54 #ifdef CONFIG_ALICLOUD_FACEBODY_ENABLE
55 case UCLOUD_AI_MODEL_COMPARING_FACEBODY:
56 LOG("Comparing facebody:\n");
57 ucloud_ai_facebody_comparing_face(FACE1_IMAGE, FACE2_IMAGE, NULL);
58 break;
59 case UCLOUD_AI_MODEL_GENERATE_HUMAN_ANIME_STYLE:
60 LOG("Generate human anime style:\n");
61 ucloud_ai_facebody_generate_human_anime_style(ANIME_IMAGE, NULL);
62 break;
63 case UCLOUD_AI_MODEL_RECOGNIZE_EXPRESSION:
64 LOG("Recognize expression:\n");
65 ucloud_ai_facebody_recognize_expression(EXPRESSION_IMAGE, NULL);
66 break;
67 #endif
68 #ifdef CONFIG_ALICLOUD_OBJECTDET_ENABLE
69 case UCLOUD_AI_MODEL_DETECT_OBJECT:
70 LOG("Detect object:\n");
71 ucloud_ai_objectdet_detect_object(OBJECT_IMAGE, NULL);
72 break;
73 case UCLOUD_AI_MODEL_DETECT_MAIN_BODY:
74 LOG("Detect main body:\n");
75 ucloud_ai_objectdet_detect_main_body(MAINBODY_IMAGE, NULL);
76 break;
77 #endif
78 #ifdef CONFIG_ALICLOUD_IMAGESEG_ENABLE
79 case UCLOUD_AI_MODEL_SEGMENT_COMMON_IMAGE:
80 LOG("Segment common image:\n");
81 ucloud_ai_imageseg_segment_common_image(MAINBODY_IMAGE, NULL);
82 break;
83 case UCLOUD_AI_MODEL_SEGMENT_FACE:
84 LOG("Segment face:\n");
85 ucloud_ai_imageseg_segment_face(FACE1_IMAGE, NULL);
86 break;
87 #endif
88 #ifdef CONFIG_ALICLOUD_OCR_ENABLE
89 case UCLOUD_AI_MODEL_RECOGNIZE_IDENTITY_CARD_FACE_SIDE:
90 LOG("Recognize identity card face side:\n");
91 ucloud_ai_ocr_recognize_identity_card_face_side(CARD_FACE_IMAGE, NULL);
92 break;
93 case UCLOUD_AI_MODEL_RECOGNIZE_IDENTITY_CARD_BACK_SIDE:
94 LOG("Recognize identity card back side:\n");
95 ucloud_ai_ocr_recognize_identity_card_back_side(CARD_BACK_IMAGE, NULL);
96 break;
97 case UCLOUD_AI_MODEL_RECOGNIZE_BANK_CARD:
98 LOG("Recognize bank card:\n");
99 ucloud_ai_ocr_recognize_bank_card(BANK_CARD_IMAGE, NULL);
100 break;
101 case UCLOUD_AI_MODEL_RECOGNIZE_CHARACTER:
102 LOG("Recognize character:\n");
103 ucloud_ai_ocr_recognize_character(CHARACTER_IMAGE, NULL);
104 break;
105 #endif
106 #ifdef CONFIG_ALICLOUD_IMAGERECOG_ENABLE
107 case UCLOUD_AI_MODEL_CLASSIFYING_RUBBISH:
108 LOG("Classifying rubbish:\n");
109 ucloud_ai_imagerecog_classifying_rubbish(RUBBISH_IMAGE, NULL);
110 break;
111 case UCLOUD_AI_MODEL_DETECT_FRUITS:
112 LOG("Detect fruits:\n");
113 ucloud_ai_imagerecog_detect_fruits(FRUITS_IMAGE, NULL);
114 break;
115 #endif
116 #ifdef CONFIG_ALICLOUD_IMAGEENHAN_ENABLE
117 case UCLOUD_AI_MODEL_ERASE_PERSON:
118 LOG("Erase person:\n");
119 ucloud_ai_imageenhan_erase_person(PERSON_ORG_IMAGE, IMAGEENHAN_ERASE_PERSON_USERMASK_URL, NULL);
120 break;
121 case UCLOUD_AI_MODEL_EXTEND_IMAGE_STYLE:
122 LOG("Extend image style:\n");
123 ucloud_ai_imageenhan_extend_image_style(STYLE_IMAGE, IMAGEENHAN_EXTEND_IMAGE_STYLE_URL, NULL);
124 break;
125 #endif
126 default:
127 break;
128 }
129
130 ret = ucloud_ai_uninit();
131 if (ret < 0) {
132 LOGE(TAG, "ucloud_ai_uninit failed, ret: %d\n", ret);
133 return -1;
134 }
135
136 return;
137 }
138
139 #if AOS_COMP_CLI
140 /* reg args: fun, cmd, description*/
141 ALIOS_CLI_CMD_REGISTER(ucloud_ai_comp_example, ucloud_ai, ucloud_ai component base example)
142 #endif
143