• 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 <stdlib.h>
17 #include <string.h>
18 #include <stdio.h>
19 #include <errno.h>
20 
21 #include "sample_comm_nnie.h"
22 #include "ai_infer_process.h"
23 #include "sample_media_ai.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif /* End of #ifdef __cplusplus */
30 
31 #define MODEL_FILE_HAND    "/userdata/models/hand_classify/hand_detect.wk" // darknet framework wk model
32 #define PIRIOD_NUM_MAX     49 // Logs are printed when the number of targets is detected
33 #define DETECT_OBJ_MAX     32 // detect max obj
34 
35 static uintptr_t g_handModel = 0;
36 
Yolo2FdLoad(uintptr_t * model)37 static HI_S32 Yolo2FdLoad(uintptr_t* model)
38 {
39     SAMPLE_SVP_NNIE_CFG_S *self = NULL;
40     HI_S32 ret;
41 
42     ret = Yolo2Create(&self, MODEL_FILE_HAND);
43     *model = ret < 0 ? 0 : (uintptr_t)self;
44     SAMPLE_PRT("Yolo2FdLoad ret:%d\n", ret);
45 
46     return ret;
47 }
48 
HandDetectInit()49 HI_S32 HandDetectInit()
50 {
51     return Yolo2FdLoad(&g_handModel);
52 }
53 
Yolo2FdUnload(uintptr_t model)54 static HI_S32 Yolo2FdUnload(uintptr_t model)
55 {
56     Yolo2Destory((SAMPLE_SVP_NNIE_CFG_S*)model);
57     return 0;
58 }
59 
HandDetectExit()60 HI_S32 HandDetectExit()
61 {
62     return Yolo2FdUnload(g_handModel);
63 }
64 
HandDetect(uintptr_t model,IVE_IMAGE_S * srcYuv,DetectObjInfo boxs[])65 static HI_S32 HandDetect(uintptr_t model, IVE_IMAGE_S *srcYuv, DetectObjInfo boxs[])
66 {
67     SAMPLE_SVP_NNIE_CFG_S *self = (SAMPLE_SVP_NNIE_CFG_S*)model;
68     int objNum;
69     int ret = Yolo2CalImg(self, srcYuv, boxs, DETECT_OBJ_MAX, &objNum);
70     if (ret < 0) {
71         SAMPLE_PRT("Hand detect Yolo2CalImg FAIL, for cal FAIL, ret:%d\n", ret);
72         return ret;
73     }
74 
75     return objNum;
76 }
77 
HandDetectCal(IVE_IMAGE_S * srcYuv,DetectObjInfo resArr[])78 HI_S32 HandDetectCal(IVE_IMAGE_S *srcYuv, DetectObjInfo resArr[])
79 {
80     int ret = HandDetect(g_handModel, srcYuv, resArr);
81     return ret;
82 }
83 
84 #ifdef __cplusplus
85 #if __cplusplus
86 }
87 #endif
88 #endif /* End of #ifdef __cplusplus */
89