2.4C#开发环境 xml格式保存参数----范例实现
1 程序参数保存目录层次说明
1 选择程序号| 相机号|窗口号
2 导入参数:就会从本地目录读取参数,并且显示图片和ROI
3 保存参数:把当前控件图片和ROI信息保存到指定程序号|相机号|窗口号中
2 参数CFilter_Param 举例
/// <summary>
/// CFilter_Param
/// VisionTool param 举例说明
/// </summary>
public class CFilter_Param
{
[XmlIgnore]
public Mat m_register_img;
public BD_Vision.Region m_region;
public ROI_single[] m_rois;
public CFilter_Param()
{
m_register_img = new Mat();
m_region = new BD_Vision.Region();
m_rois = ROI_single.init(5);
}
}
3 保存参数
保存地址信息和效果如下
int proNO = (int)num_programNO.Value;
int camNO = (int)num_camNO.Value;
int winNO = (int)num_winNO.Value;
string filepath = Application.StartupPath + "\\ProgramData\\Pro_" + proNO.ToString("000") + "\\Cam_" + camNO.ToString("0") + "\\CFilter\\Win_" + winNO.ToString("000") + "\\";
string filename = "cfilter_param.xml";
if (!get_FileCtx().FolderExist(filepath))
get_FileCtx().CreateFolder(filepath);
cfilter_param.m_rois = BD_OperateSet.ROIs_Deep_Copy(bdPictureBox1.m_ROIs);
get_FileCtx().Save_XML_File_Serialize(filepath, filename, typeof(CFilter_Param), cfilter_param);
// m_register_img 要单独读取
filename = "m_register_img.png";
BD_OperateSet.Assign_Mat(ref cfilter_param.m_register_img,ref bdPictureBox1.m_raw_mat);
if (BD_OperateSet.MatisNotNull(cfilter_param.m_register_img))
Cv2.ImWrite(filepath + filename, cfilter_param.m_register_img);
4 读取参数
这里仅仅演示读取一个窗口的效果,如果多个相机,多个窗口,请大家思考下
int proNO = (int)num_programNO.Value;
int camNO = (int)num_camNO.Value;
int winNO = (int)num_winNO.Value;
string filepath = Application.StartupPath + "\\ProgramData\\Pro_" + proNO.ToString("000") + "\\Cam_" + camNO.ToString("0") + "\\CFilter\\Win_" + winNO.ToString("000") + "\\";
string filename = "cfilter_param.xml";
if (get_FileCtx().FileExist(filepath, filename))
{
cfilter_param = (CFilter_Param)get_FileCtx().Read_XML_File_Deserializer(filepath, filename, typeof(CFilter_Param));
if (cfilter_param == null)
cfilter_param = new CFilter_Param();
}
else
{
cfilter_param = new CFilter_Param();
}
// m_register_img 要单独读取
filename = "m_register_img.png";
BD_OperateSet.Assign_Temp(ref cfilter_param.m_register_img, Cv2.ImRead(filepath + filename, ImreadModes.Unchanged));
bdPictureBox1.Display_Mat(ref cfilter_param.m_register_img);
bdPictureBox1.InitDisp_InterActive_ROIs(cfilter_param.m_rois,new Scalar(0,255,0),1);