• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /*
17  * 该cpp文件为ai sample的主函数文件,通过编译ai sample会生成一个可执行文件,可通过
18  * ./可执行文件+index方式可以选择运行相关场景。index 0代表运行垃圾分类,index 1
19  * 代表运行手部检测+手势识别,index 2代表网球检测。可通过enter键进行退出。
20  *
21  * The cpp file is the main function file of the ai sample.
22  * After compiling the ai sample, an executable file will be generated.
23  * You can choose to run related scenarios through the ./executable file+index method.
24  * Index 0 means running trash classification, index 1 means running hand detection + gesture recognition,
25  * index 2 means tennis ball detection. It can be exited by pressing the enter key.
26  */
27 
28 #include <iostream>
29 #include "unistd.h"
30 #include "sdk.h"
31 #include "sample_media_ai.h"
32 #include "sample_media_opencv.h"
33 
34 using namespace std;
35 
36 /*
37  * 函数:显示用法
38  * function: show usage
39  */
SAMPLE_AI_Usage(char * pchPrgName)40 static void SAMPLE_AI_Usage(char* pchPrgName)
41 {
42     printf("Usage : %s <index> \n", pchPrgName);
43     printf("index:\n");
44     printf("\t 0) cnn trash_classify(resnet18).\n");
45     printf("\t 1) hand classify(yolov2+resnet18).\n");
46     printf("\t 2) tennis detect(opencv).\n");
47 }
48 
49 /*
50  * 函数:ai sample主函数
51  * function : ai sample main function
52  */
main(int argc,char * argv[])53 int main(int argc, char *argv[])
54 {
55     HI_S32 s32Ret = HI_FAILURE;
56     sample_media_opencv mediaOpencv;
57     if (argc < 2 || argc > 2) { // 2: argc indicates the number of parameters
58         SAMPLE_AI_Usage(argv[0]);
59         return HI_FAILURE;
60     }
61 
62     if (!strncmp(argv[1], "-h", 2)) { // 2: used to compare the first 2 characters
63         SAMPLE_AI_Usage(argv[0]);
64         return HI_SUCCESS;
65     }
66     sdk_init();
67     /*
68      * MIPI为GPIO55,开启液晶屏背光
69      * MIPI is GPIO55, Turn on the backlight of the LCD screen
70      */
71     system("cd /sys/class/gpio/;echo 55 > export;echo out > gpio55/direction;echo 1 > gpio55/value");
72 
73     switch (*argv[1]) {
74         case '0':
75             SAMPLE_MEDIA_CNN_TRASH_CLASSIFY();
76             break;
77         case '1':
78             SAMPLE_MEDIA_HAND_CLASSIFY();
79             break;
80         case '2':
81             mediaOpencv.SAMPLE_MEDIA_TENNIS_DETECT();
82             break;
83         default:
84             SAMPLE_AI_Usage(argv[0]);
85             break;
86     }
87     sdk_exit();
88     SAMPLE_PRT("\nsdk exit success\n");
89     return s32Ret;
90 }
91