一、总体框架
视频采集、处理使用rkmedia:vi模块进行视频输入、rga模块进行视频处理
人脸识别:先获取rga输出码流,再调用rkmedia的模型对人脸进行推理(线程1)
打框框:opencv(线程2),且在打完框后把视频输入至venc(编码)
rtsp推流:获得venc编码数据后进行rtsp推流
根据这些模块、整体码流流向如下图:
二、部分笔记
首先初始化了人脸数据库(init_face_data())其内容如下:
1.连接sql数据库,打开后可以看到其中也是简单的封装函数sqlite3_open
2.初始化了一个特殊类S_THREAD_MAP
3.map<string,rockx_face_feature_t>就是一个姓名与人脸特征的map
4.QueryFaceFeature是获取数据库中所有信息到map中 。涉及到对sql的操作
5.set_thread_map是对获取的所有人脸信息map保存到了一个全局表量数组里,保存在第task_id
void init_face_data()
{
Connection_Sqlite3DataBase();
int task_id = 0;
S_THREAD_MAP thread_map;
map<string, rockx_face_feature_t> maps = QueryFaceFeature();
thread_map.thread_map = maps;
set_thread_map(task_id, &thread_map);
}
Connection_Sqlite3DataBase内容如下
int Connection_Sqlite3DataBase()
{
rc = sqlite3_open("/mnt/nfs/face.db", &db);
if (rc != SQLITE_OK)
{
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
else
{
printf("You have opened a sqlite3 database named bind.db successfully!\nCongratulation! Have fun!\n");
}
return 0;
}
S_THREAD_MAP内部如下,map_id 以及一个姓名与人脸特征结构体
class S_THREAD_MAP{
public:
int map_id;
map<string, rockx_face_feature_t> thread_map;
};
QueryFaceFeature内容如下:
map<string, rockx_face_feature_t> QueryFaceFeature()
{
rockx_face_feature_t rockx_face_feature = {0, 0};
map<string, rockx_face_feature_t> rockx_face_feature_map;
sqlite3_stmt *stmt;
char *sql = "select name, feature_size, face_feature from face_data_table";
//准备查询语句 准备从db数据库查找sql(name feature_size face_feature)
int ret = sqlite3_prepare(db, sql, strlen(sql), &stmt, 0);
int id = 0, len = 0;
char * name;
int feature_size;
if (ret == SQLITE_OK)
{
//真正开始查找 当一行查找成功后执行下面代码
while (sqlite3_step(stmt) == SQLITE_ROW)
{
name = (char *)sqlite3_column_text(stmt, 0);
printf("name = %s\n", name);
feature_size = sqlite3_column_int(stmt, 1);
printf("feature_size = %d\n", feature_size);
//rockx_face_feature.feature = (MByte *)malloc(feature_size);
const void *feature = sqlite3_column_blob(stmt, 2);
memset(rockx_face_feature.feature, 0, feature_size);
memcpy(rockx_face_feature.feature, feature, feature_size);
rockx_face_feature.len = feature_size;
string str(name);
//插入人脸数据
rockx_face_feature_map.insert(pair<string, rockx_face_feature_t>(str, rockx_face_feature));
}
}
sqlite3_finalize(stmt);
sqlite3_close(db);
//返回所有信息
return rockx_face_feature_map;
}
set_thread_map
int set_thread_map(unsigned int map_id, S_THREAD_MAP *map)
{
pthread_mutex_lock(&g_thread_maps_mutex);
g_thread_maps[map_id] = *map;
pthread_mutex_unlock(&g_thread_maps_mutex);
return 0;
}