准备
准备好虹软SDK,编译通过。
复制database.h, database.c到samplecode.cpp那个目录,并包含头文件。
创建对应的文件夹…/oem, …/userdata
数据库和表
数据库的名称为face_conf.db
里面有一张表 face_conf
表中有以下的列
id INTEGER PRIMARY KEY AUTOINCREMENT
name varchar(255) NOT NULL UNIQUE
blob_conf BLOB
text_conf varchar(255)
int_conf INTEGER
float_conf FLOAT
更改对应项
#define PRE_PATH "../oem"
#define BAK_PATH "../userdata"
#define DATABASE_PATH PRE_PATH "/face_conf.db"
#define BAK_DATABASE_PATH BAK_PATH "/face_conf.db"
#define DATABASE_TABLE "face_conf"
#define NAME_LEN 256
#define TEXT_LEN 500
#define USER_NAME "User"
#define DATABASE_VERSION "version_0"
int database_init(void)
{
char *err;
char cmd[256];
if (sqlite3_open(DATABASE_PATH, &g_db) != SQLITE_OK) {
printf("%s open database %s failed!\n", __func__, DATABASE_PATH);
return -1;
}
snprintf(cmd, sizeof(cmd),
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(%d) NOT NULL UNIQUE, blob_conf BLOB, text_conf varchar(%d), int_conf INTEGER, float_conf FLOAT);",
DATABASE_TABLE,
NAME_LEN,
TEXT_LEN);
if (sqlite3_exec(g_db, cmd, 0, 0, &err) != SQLITE_OK) {
sqlite3_close(g_db);
g_db = NULL;
printf("%s create table %s failed!\n", __func__, DATABASE_TABLE);
return -1;
}
return 0;
}
调用database_init
在samplecode.cpp文件中调用database_init
//初始化数据库
int ret = database_init();
if(ret != 0)
{
printf("database_init false! \n");
return -1;
}
while(1);
编译
在cmake文件里面添加对应的库和文件
add_executable(arcsoft_face_engine_test
./inc/amcomdef.h
./inc/arcsoft_face_sdk.h
./inc/asvloffscreen.h
./inc/merror.h
./database.c
./database.h
./samplecode.cpp)
#链接库文件
target_link_libraries(arcsoft_face_engine_test
arcsoft_face
arcsoft_face_engine
sqlite3
)
cmake并且编译
face/samplecode/ASFTestDemo/build$ make
Scanning dependencies of target arcsoft_face_engine_test
[ 33%] Building C object CMakeFiles/arcsoft_face_engine_test.dir/database.c.o
[ 66%] Building CXX object CMakeFiles/arcsoft_face_engine_test.dir/samplecode.cpp.o
[100%] Linking CXX executable arcsoft_face_engine_test
[100%] Built target arcsoft_face_engine_test
测试
face/samplecode/ASFTestDemo/build$ ./arcsoft_face_engine_test
^C
定住,ctrl+c退出
用软件打开…/oem/face_conf.db
编辑里面的内容,保存下来