added -P for should_do_judge_according_time()
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "myrga.h"
|
||||
#include "pose_body.h"
|
||||
#include "rknn.h"
|
||||
#include "vertix.h"
|
||||
|
||||
extern long max_time_elapsed;
|
||||
|
||||
@@ -92,6 +93,11 @@ void convert_a_frame(MppFrame frame)
|
||||
{
|
||||
// lock acquired, should create thread and use pose_body
|
||||
|
||||
if (!should_do_judge_according_time()) {
|
||||
pthread_mutex_unlock(&frame_mutex);
|
||||
free(out);
|
||||
return;
|
||||
}
|
||||
pthread_t pose_body_handler;
|
||||
pthread_create(&pose_body_handler, NULL, pose_body_thread, (void *)out);
|
||||
pthread_detach(pose_body_handler);
|
||||
|
||||
@@ -108,6 +108,7 @@ static struct option long_options[] = {
|
||||
{"upload-port", required_argument, NULL, 'p'},
|
||||
{"workspace", required_argument, NULL, 'w'},
|
||||
{"threshold", required_argument, NULL, 'r'},
|
||||
{"time-period", required_argument, NULL, 'P'},
|
||||
{0, 0, 0}};
|
||||
|
||||
void print_usage(char *cmd)
|
||||
@@ -154,10 +155,11 @@ void parse_options(int argc, char **argv)
|
||||
int thresh;
|
||||
conf_threshold = DEFAULT_CONF_THRESHOLD;
|
||||
char *cmd = argv[0];
|
||||
int ok;
|
||||
while (1)
|
||||
{
|
||||
int option_index = 0;
|
||||
c = getopt_long_only(argc, argv, "es:m:w:c:t:p:r:", long_options, &option_index);
|
||||
c = getopt_long_only(argc, argv, "es:m:w:c:t:p:r:P:", long_options, &option_index);
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
@@ -200,6 +202,13 @@ void parse_options(int argc, char **argv)
|
||||
}
|
||||
conf_threshold = (float)thresh / 100.0;
|
||||
break;
|
||||
case 'P':
|
||||
ok = get_all_time_period_from_arguments(optarg);
|
||||
if (ok != 0) {
|
||||
printf("failed to parse time period\n");
|
||||
exit(-1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
print_usage(cmd);
|
||||
exit(-1);
|
||||
|
||||
@@ -119,7 +119,7 @@ int print_object_detect_result(rknn_app_context_t *rknn, object_detect_result_li
|
||||
continue;
|
||||
}
|
||||
char *label = labels[group->results[i].cls_id];
|
||||
if (group->results[i].cls_id != 4 && group->results[i].prop < conf_threshold) {
|
||||
if (group->results[i].prop < conf_threshold) {
|
||||
printf("skip prop = %f for class %s\n", group->results[i].prop, label);
|
||||
continue;
|
||||
}
|
||||
|
||||
+154
-1
@@ -1,8 +1,11 @@
|
||||
#include "vertix.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "pose_body.h"
|
||||
|
||||
Polygon workspace;
|
||||
time_gap_t global_time_gap;
|
||||
|
||||
void dump_polygon_to_file(char *filename) {
|
||||
FILE *fp = fopen(filename, "w+");
|
||||
@@ -134,4 +137,154 @@ bool is_point_in_workspace(int left, int top, int right, int bottom)
|
||||
dump_box_info(inside, left, top, right, bottom);
|
||||
#endif
|
||||
return inside;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取今天的秒数
|
||||
int get_today_seconds() {
|
||||
time_t current_time;
|
||||
struct tm time_info;
|
||||
int total_seconds;
|
||||
|
||||
time(¤t_time);
|
||||
localtime_r(¤t_time, &time_info);
|
||||
total_seconds = time_info.tm_hour * 3600 + time_info.tm_min * 60 + time_info.tm_sec;
|
||||
return total_seconds;
|
||||
}
|
||||
|
||||
int should_do_judge_according_time() {
|
||||
int now = get_today_seconds();
|
||||
int ok = false;
|
||||
if (global_time_gap.in) {
|
||||
for (int i = 0; i < global_time_gap.size; i++) {
|
||||
if (global_time_gap.periods[i].from <= now && global_time_gap.periods[i].to >= now) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
// not in
|
||||
for (int i = 0; i < global_time_gap.size; i++) {
|
||||
if (global_time_gap.periods[i].from > now || global_time_gap.periods[i].to < now) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get_today_seconds_from_string(const char *str) {
|
||||
char *token;
|
||||
char *rest = (char*)str;
|
||||
int hour = 0, minute = 0, second = 0;
|
||||
|
||||
char *origin = (char*)malloc(sizeof(char)*(strlen(str)+1));
|
||||
strncpy(origin, str, strlen(str));
|
||||
origin[strlen(str)] = '\0';
|
||||
|
||||
token = strtok_r(origin, ":", &rest);
|
||||
|
||||
if (token != NULL) {
|
||||
hour = atoi(token);
|
||||
} else {
|
||||
free(origin);
|
||||
return -1;
|
||||
}
|
||||
token = strtok_r(NULL, ":", &rest);
|
||||
if (token != NULL) {
|
||||
minute = atoi(token);
|
||||
}
|
||||
token = strtok_r(NULL, ":", &rest);
|
||||
if (token != NULL) {
|
||||
second = atoi(token);
|
||||
}
|
||||
|
||||
free(origin);
|
||||
return hour * 3600 + minute * 60 + second;
|
||||
}
|
||||
|
||||
time_period_t* get_time_period_from_string(char *str) {
|
||||
char *token;
|
||||
char *rest = str;
|
||||
char *origin = (char*)malloc(sizeof(char)*(strlen(str)+1));
|
||||
strncpy(origin, str, strlen(str));
|
||||
origin[strlen(str)] = '\0';
|
||||
|
||||
printf("\norigin=%s\n", origin);
|
||||
token = strtok_r(origin, "-", &rest);
|
||||
printf("token1 = %s\n", token);
|
||||
if (token == NULL) {
|
||||
printf("token1 is null\n");
|
||||
free(origin);
|
||||
return NULL;
|
||||
}
|
||||
printf("start_token = %s\n", token);
|
||||
int start = get_today_seconds_from_string(token);
|
||||
if (start < 0) {
|
||||
free(origin);
|
||||
return NULL;
|
||||
}
|
||||
printf("rest = \"%s\"", rest);
|
||||
if (strlen(rest) == 0) {
|
||||
token = "23:59:59";
|
||||
} else {
|
||||
token = rest;
|
||||
}
|
||||
printf("end_token = %s\n", token);
|
||||
int end = get_today_seconds_from_string(token);
|
||||
|
||||
printf("start = %d, end = %d\n", start, end);
|
||||
free(origin);
|
||||
|
||||
time_period_t *result = (time_period_t*)malloc(sizeof(time_period_t));
|
||||
result->from = start;
|
||||
result->to = end;
|
||||
return result;
|
||||
}
|
||||
|
||||
int get_all_time_period_from_arguments(const char *str) {
|
||||
if (strlen(str) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char in = 1;
|
||||
|
||||
char *origin = (char*)malloc(sizeof(char)*(strlen(str)+1));
|
||||
strncpy(origin, str, strlen(str));
|
||||
origin[strlen(str)] = '\0';
|
||||
|
||||
int offset = 0;
|
||||
if (str[0] == '!') {
|
||||
offset = 1;
|
||||
in = 0;
|
||||
}
|
||||
|
||||
char *rest;
|
||||
char *info;
|
||||
char *start = origin;
|
||||
printf(in ? "in" : "not in ");
|
||||
|
||||
global_time_gap.periods = (time_period_t*) malloc(sizeof(time_period_t)*64);
|
||||
|
||||
int size = 0;
|
||||
while ((info = strtok_r(start, ",", &rest)) != NULL) {
|
||||
time_period_t* period = get_time_period_from_string(info);
|
||||
if (period == NULL) {
|
||||
printf("failed to parse gap: %s\n", info);
|
||||
return -2;
|
||||
}
|
||||
global_time_gap.periods[size].from = period->from;
|
||||
global_time_gap.periods[size].from = period->to;
|
||||
free(period);
|
||||
size++;
|
||||
if (size >= 64) {
|
||||
printf("too many periods specified: > 64\n");
|
||||
free(global_time_gap.periods);
|
||||
free(origin);
|
||||
return -3;
|
||||
}
|
||||
start = NULL;
|
||||
}
|
||||
global_time_gap.size = size;
|
||||
free(origin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,30 @@
|
||||
#ifndef __MY_VERTIX_H__
|
||||
#define __MY_VERTIX_H__
|
||||
|
||||
typedef struct {
|
||||
int from;
|
||||
int to;
|
||||
} time_period_t;
|
||||
|
||||
typedef struct {
|
||||
// 如果in为0,则表示需要再这段时间,否则,表示在这段时间之外
|
||||
bool in;
|
||||
int size;
|
||||
time_period_t *periods;
|
||||
} time_gap_t;
|
||||
|
||||
extern time_gap_t global_time_gap;
|
||||
|
||||
|
||||
int should_do_judge_according_time();
|
||||
|
||||
// 获取今天的秒数
|
||||
int get_today_seconds();
|
||||
|
||||
// 将16:05:00类似的字符串,转换成一天的秒数
|
||||
int get_all_time_period_from_arguments(const char *str);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float x;
|
||||
|
||||
Reference in New Issue
Block a user