You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.5 KiB
C#

using HalconDotNet;
using Rs.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Flow.Camera
{
/// <summary>
/// 模板参数类
/// </summary>
public class ModelParameter
{
/// <summary>
/// 模板ID
/// </summary>
public HTuple ModelID { get; set; }
/// <summary>
/// 搜索区域
/// </summary>
public HObject SearchRegion { get; set; }
/// <summary>
/// 二维码区域
/// </summary>
public HObject BarCodeRegion { get; set; }
/// <summary>
/// 起始角度
/// </summary>
public string AngleStart { get; set; }
/// <summary>
/// 旋转角度
/// </summary>
public string AngleExtent { get; set; }
/// <summary>
/// 分数
/// </summary>
public string Score { get; set; }
/// <summary>
/// 模板匹配结果
/// </summary>
public HTuple ModelMatchResult { get; set; }
/// <summary>
/// 加载参数
/// </summary>
public ModelParameter(string itemName)
{
string modelDir = Path.Combine("Recipe",GlobalVar.CurRecipe, itemName);
if(Directory.Exists(modelDir))
{
IniHelper ini = new IniHelper(Path.Combine(modelDir, "default.ini"));
AngleStart = ini.ReadValue("ModelParam", "AngleStart", "-10");
AngleExtent = ini.ReadValue("ModelParam", "AngleExtent", "10");
Score = ini.ReadValue("ModelParam", "Score", "0.5");
string paramPath = Path.Combine(modelDir, "param.tup");
HOperatorSet.ReadTuple(paramPath, out HTuple modelParam);
ModelMatchResult = modelParam;
string filePath = Path.Combine(modelDir, "model.shm");
HOperatorSet.ReadShapeModel(filePath, out HTuple downCamModelID);
ModelID = downCamModelID;
string searchReg = Path.Combine(modelDir, "search.reg");
HOperatorSet.ReadRegion(out HObject searchRegion, searchReg);
SearchRegion = searchRegion;
string barCodeReg = Path.Combine(modelDir, "barcode.reg");
HOperatorSet.ReadRegion(out HObject barCodeRegion, searchReg);
BarCodeRegion = barCodeRegion;
}
}
}
}