feat(helmet detect): add knowing app helmet detect

This commit is contained in:
Liu Yongkai
2021-08-04 17:45:56 +08:00
parent 2d8147a92b
commit 21f57bf229
12 changed files with 3883 additions and 11 deletions
@@ -26,6 +26,11 @@
],
"kmodel_path": "/kmodel/human.kmodel",
"kmodel_size": 1903016,
"obj_thresh": 0.3,
"obj_thresh": [
0.3
],
"labels": [
"human"
],
"nms_thresh": 0.3
}
@@ -14,8 +14,10 @@ int net_input_size[2] = {};
int sensor_output_size[2] = {};
char kmodel_path[127] = "";
int kmodel_size = 0;
float obj_thresh = 1.0;
float obj_thresh[20] = {};
float nms_thresh = 0.0;
char labels[20][32] = {};
int class_num = 0;
#define THREAD_PRIORITY_HUMAN_D (11)
static pthread_t instrusiontid = 0;
@@ -131,10 +133,34 @@ static void param_parse()
json_item = cJSON_GetObjectItem(json_obj, "kmodel_size");
kmodel_size = json_item->valueint;
printf("Got kmodel_size: %d\n", kmodel_size);
// labels
json_item = cJSON_GetObjectItem(json_obj, "labels");
class_num = cJSON_GetArraySize(json_item);
if (0 >= class_num) {
printf("No labels!");
exit(-1);
} else {
printf("Got %d labels\n");
}
for (int i = 0; i < class_num; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
memcpy(labels[i], json_item->valuestring, strlen(json_item->valuestring));
printf("%d: %f\n", i, labels[i]);
}
// obj_thresh
json_item = cJSON_GetObjectItem(json_obj, "obj_thresh");
obj_thresh = json_item->valuedouble;
printf("Got obj_thresh: %f\n", obj_thresh);
array_size = cJSON_GetArraySize(json_item);
if (class_num != array_size) {
printf("label number and thresh number mismatch! label number : %d, obj thresh number %d", class_num, array_size);
exit(-1);
} else {
printf("Got %d obj_thresh\n");
}
for (int i = 0; i < array_size; i++) {
json_array_item = cJSON_GetArrayItem(json_item, i);
obj_thresh[i] = json_array_item->valuedouble;
printf("%d: %f\n", i, obj_thresh[i]);
}
// nms_thresh
json_item = cJSON_GetObjectItem(json_obj, "nms_thresh");
nms_thresh = json_item->valuedouble;
@@ -224,7 +250,10 @@ void instrusion_detect()
}
instrusion_detect_rl.anchor_number = ANCHOR_NUM;
instrusion_detect_rl.anchor = anchor;
instrusion_detect_rl.threshold = obj_thresh;
instrusion_detect_rl.threshold = malloc(class_num * sizeof(float));
for (int idx = 0; idx < class_num; idx++) {
instrusion_detect_rl.threshold[idx] = obj_thresh[idx];
;
instrusion_detect_rl.nms_value = nms_thresh;
result = region_layer_init(&instrusion_detect_rl, net_output_shape[0], net_output_shape[1], net_output_shape[2],
net_input_size[1], net_input_size[0]);