您的位置:首页 > 房产 > 建筑 > rv1126利用rkmedia、opencv、rockx……完成人脸识别

rv1126利用rkmedia、opencv、rockx……完成人脸识别

2024/12/23 8:50:34 来源:https://blog.csdn.net/weixin_48444982/article/details/140608408  浏览:    关键词:rv1126利用rkmedia、opencv、rockx……完成人脸识别

一、总体框架

视频采集、处理使用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;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com