• 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 #include <iostream>
17 #include "unistd.h"
18 #include "sdk.h"
19 #include "sample_media_ai.h"
20 #include "sample_media_opencv.h"
21 
22 using namespace std;
23 
24 /* function : show usage */
SAMPLE_AI_Usage(char * pchPrgName)25 static void SAMPLE_AI_Usage(char* pchPrgName)
26 {
27     printf("Usage : %s <index> \n", pchPrgName);
28     printf("index:\n");
29     printf("\t 0) cnn trash_classify(resnet18).\n");
30     printf("\t 1) hand classify(yolov2+resnet18).\n");
31     printf("\t 2) tennis detect(opencv).\n");
32 }
33 
34 /*
35  * function    : main()
36  * Description : main
37  */
main(int argc,char * argv[])38 int main(int argc, char *argv[])
39 {
40     HI_S32 s32Ret = HI_FAILURE;
41     sample_media_opencv mediaOpencv;
42     if (argc < 2 || argc > 2) { // 2: argc indicates the number of parameters
43         SAMPLE_AI_Usage(argv[0]);
44         return HI_FAILURE;
45     }
46 
47     if (!strncmp(argv[1], "-h", 2)) { // 2: used to compare the first 2 characters
48         SAMPLE_AI_Usage(argv[0]);
49         return HI_SUCCESS;
50     }
51     sdk_init();
52     /* MIPI is GPIO55, Turn on the backlight of the LCD screen */
53     system("cd /sys/class/gpio/;echo 55 > export;echo out > gpio55/direction;echo 1 > gpio55/value");
54 
55     switch (*argv[1]) {
56         case '0':
57             SAMPLE_MEDIA_CNN_TRASH_CLASSIFY();
58             break;
59         case '1':
60             SAMPLE_MEDIA_HAND_CLASSIFY();
61             break;
62         case '2':
63             mediaOpencv.SAMPLE_MEDIA_TENNIS_DETECT();
64             break;
65         default:
66             SAMPLE_AI_Usage(argv[0]);
67             break;
68     }
69     sdk_exit();
70     SAMPLE_PRT("\nsdk exit success\n");
71     return s32Ret;
72 }
73