#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <stdio.h>
#pragma comment(lib, "cv")
#pragma comment(lib, "cxcored")
#pragma comment(lib, "highgui")
//////////////////////////////////////////////////////////////////////////
void start_write_struct(CvFileStorage* fs, const char *struct_name)
{
cvStartWriteStruct(fs, struct_name, CV_NODE_MAP);
}
void end_write_struct(CvFileStorage* fs)
{
cvEndWriteStruct(fs);
}
void write_param(CvFileStorage* fs, const char *name, double val)
{
cvWriteReal(fs, name, val);
}
void *start_read_struct(CvFileStorage* fs, void *node, const char *struct_name)
{
// 获得第x层数据节点
CvFileNode* node1 = cvGetFileNodeByName(fs, (CvFileNode*)node, struct_name);
return node1; //null for fail
}
void end_read_struct(CvFileStorage* fs)
{
//nothing todo here
}
double read_param(CvFileStorage* fs, void* node, const char *name, double default)
{
return cvReadRealByName(fs, (CvFileNode*)node, name, default);
}
//////////////////////////////////////////////////////////////////////////
//osd
typedef struct
{
bool m_bShowTrackInfo; //是否叠加跟踪信息checkbox, 默认vefalse
int m_objBoxType; //跟踪框形状:下拉列表框,包括项:外框=0、内框=1,十字=2
//默认外框=0
bool m_bShowTrack; //是否叠加轨迹信息, 默认vefalse
int m_nShowTrackTime; //叠加时间长度(s), 默认30
int m_trackColor; //type|r|g|b; 默认type=0
//type: 0随机颜色; 1自定义, 则低24bit是颜色rgb
CvScalar color;
}VE_AlgOsdParam;
void write_osd_para(CvFileStorage* fs, VE_AlgOsdParam ¶)
{
const char *name = "VE_AlgOsdParam";
start_write_struct(fs, name);
write_param(fs, "m_bShowTrackInfo", para.m_bShowTrackInfo);
write_param(fs, "m_objBoxType", para.m_objBoxType);
write_param(fs, "m_bShowTrack", para.m_bShowTrack);
write_param(fs, "m_nShowTrackTime", para.m_nShowTrackTime);
write_param(fs, "m_trackColor", para.m_trackColor);
{
start_write_struct(fs, "color");
write_param(fs, "_0", para.color.val[0]);
write_param(fs, "_1", para.color.val[1]);
write_param(fs, "_2", para.color.val[2]);
write_param(fs, "_3", para.color.val[3]);
end_write_struct(fs);
}
end_write_struct(fs);
}
void read_osd_para(CvFileStorage* fs, VE_AlgOsdParam *para, const VE_AlgOsdParam *def)
{
//copy default para first
memcpy(para, def, sizeof(para[0]));
// 获得第一层数据节点
//CvFileNode* node = cvGetFileNodeByName(fs, 0, "VE_AlgOsdParam");
void *node = start_read_struct(fs, 0, "VE_AlgOsdParam");
if (node == NULL)
{
return;
}
para[0].m_bShowTrack = (bool)read_param(fs, node, "m_bShowTrackInfo", def[0].m_bShowTrack);
para[0].m_objBoxType = read_param(fs, node, "m_objBoxType", def[0].m_objBoxType);
para[0].m_bShowTrack = read_param(fs, node, "m_bShowTrack", def[0].m_bShowTrack);
para[0].m_nShowTrackTime = (bool)read_param(fs, node, "m_nShowTrackTime", def[0].m_nShowTrackTime);
para[0].m_trackColor = read_param(fs, node, "m_trackColor", def[0].m_trackColor);
{
node = start_read_struct(fs, node, "color");
if (node == NULL)
{
return;
}
para[0].color.val[0] = read_param(fs, node, "_0", def[0].m_trackColor);
para[0].color.val[1] = read_param(fs, node, "_1", def[0].m_trackColor);
para[0].color.val[2] = read_param(fs, node, "_2", def[0].m_trackColor);
para[0].color.val[3] = read_param(fs, node, "_3", def[0].m_trackColor);
end_read_struct(fs);
}
end_read_struct(fs);
}
void my_test_osd_para()
{
// 创建文件存储对象
VE_AlgOsdParam osdPara = {0};
osdPara.color.val[0] = 255;
CvFileStorage *fs=cvOpenFileStorage("test.xml",0,CV_STORAGE_WRITE);
write_osd_para(fs, osdPara);
// 释放文件存储对象
cvReleaseFileStorage(&fs);
fs=cvOpenFileStorage("test.xml",0,CV_STORAGE_READ);
VE_AlgOsdParam osdPara1 = {0};
read_osd_para(fs, &osdPara1, &osdPara);
cvReleaseFileStorage(&fs);
}
void main()
{
my_test_osd_para();
}
评论0