289 lines
7.8 KiB
C#
289 lines
7.8 KiB
C#
using Community;
|
||
using HalconDotNet;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.IO;
|
||
|
||
namespace Model.Vision
|
||
{
|
||
/// <summary>
|
||
/// 矩形区域模型
|
||
/// </summary>
|
||
public class V_RectangleModel : NotificationObject
|
||
{
|
||
public int ID { get; set; }
|
||
|
||
#region 区域轮廓参数
|
||
/// <summary>
|
||
/// 项目ID
|
||
/// </summary>
|
||
public int VeiID { get; set; }
|
||
|
||
/// <summary>
|
||
/// 区域类型,1:自由区域 2:图像校正区域
|
||
/// </summary>
|
||
public int AreaType { get; set; }
|
||
|
||
/// <summary>
|
||
/// 起点纵向坐标
|
||
/// </summary>
|
||
public double Point_Row1 { get; set; }
|
||
/// <summary>
|
||
/// 起点横向坐标
|
||
/// </summary>
|
||
public double Point_Column1 { get; set; }
|
||
/// <summary>
|
||
/// 终点纵向坐标
|
||
/// </summary>
|
||
public double Point_Row2 { get; set; }
|
||
/// <summary>
|
||
/// 终点横向坐标
|
||
/// </summary>
|
||
public double Point_Column2 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 矩形区域轮廓
|
||
/// </summary>
|
||
public HObject ho_RectangleModel;
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 支持文件名称
|
||
/// </summary>
|
||
public string HelpFileName { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否读取标定文件
|
||
/// </summary>
|
||
public bool WhetherReadFile { get; set; }
|
||
|
||
/// <summary>
|
||
/// 九点标定参数
|
||
/// </summary>
|
||
public HTuple hv_JiuDianCalibrationPar = null;
|
||
|
||
|
||
|
||
#region 光源各通道亮度
|
||
/// <summary>
|
||
/// 光源通道1亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness1 { get; set; }
|
||
/// <summary>
|
||
/// 光源通道2亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness2 { get; set; }
|
||
/// <summary>
|
||
/// 光源通道3亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness3 { get; set; }
|
||
/// <summary>
|
||
/// 光源通道4亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness4 { get; set; }
|
||
#endregion
|
||
|
||
|
||
#region 我的ROI
|
||
|
||
private V_ROI myROI;
|
||
/// <summary>
|
||
/// 我的ROI
|
||
/// </summary>
|
||
public V_ROI MyROI
|
||
{
|
||
get { return myROI; }
|
||
set
|
||
{
|
||
myROI = value == null ? new V_ROI() : value;
|
||
this.RaisePropertyChanged("MyROI");
|
||
}
|
||
}
|
||
|
||
public HTuple HomMat2D { get; set; }
|
||
|
||
#endregion
|
||
|
||
#region 我的ROI集合
|
||
private ObservableCollection<V_ROI> myRoiList;
|
||
/// <summary>
|
||
/// 我的ROI集合
|
||
/// </summary>
|
||
public ObservableCollection<V_ROI> MyRoiList
|
||
{
|
||
get { return myRoiList; }
|
||
set
|
||
{
|
||
myRoiList = value == null ? new ObservableCollection<V_ROI>() : value;
|
||
this.RaisePropertyChanged("MyRoiList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 我的角点
|
||
private V_CornerPoint myCorner;
|
||
/// <summary>
|
||
/// 我的角点
|
||
/// </summary>
|
||
public V_CornerPoint MyCorner
|
||
{
|
||
get { return myCorner; }
|
||
set
|
||
{
|
||
myCorner = value == null ? new V_CornerPoint() : value;
|
||
this.RaisePropertyChanged("MyCorner");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 定位相对坐标
|
||
/// </summary>
|
||
public List<V_Piont> LocateList { get; set; }
|
||
public List<ROI> RoiList { get; set; }
|
||
|
||
/// <summary>
|
||
/// 模板图片
|
||
/// </summary>
|
||
public HObject ModelImage;
|
||
|
||
|
||
public V_RectangleModel()
|
||
{
|
||
WhetherReadFile = true;
|
||
MyROI = new V_ROI() { ROIType = 1 };
|
||
MyRoiList = new ObservableCollection<V_ROI>();
|
||
LocateList = new List<V_Piont>();
|
||
}
|
||
|
||
|
||
|
||
#region 实例化矩形轮廓
|
||
/// <summary>
|
||
/// 实例化矩形轮廓
|
||
/// </summary>
|
||
public void Instantiation()
|
||
{
|
||
WhetherReadFile = true;
|
||
HOperatorSet.GenEmptyObj(out ho_RectangleModel);
|
||
//获取产品模型
|
||
ho_RectangleModel.Dispose();
|
||
HOperatorSet.GenRectangle1(out ho_RectangleModel, Point_Row1, Point_Column1, Point_Row2, Point_Column2);
|
||
}
|
||
#endregion
|
||
|
||
#region 标定文件的存取
|
||
/// <summary>
|
||
/// 保存标定文件
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool SaveCalibrationFile(HTuple hv_CalibrationPar,string cameraName)
|
||
{
|
||
this.HelpFileName = cameraName;
|
||
//先确保标定参数文件已存在
|
||
string filePath = @"Calibration/" + HelpFileName + ".tup"; //相机标定参数保存路径
|
||
|
||
if (!Directory.Exists(@"Calibration/"))
|
||
{
|
||
Directory.CreateDirectory(@"Calibration/");
|
||
}
|
||
try
|
||
{
|
||
HOperatorSet.WriteTuple(hv_CalibrationPar, filePath);
|
||
this.hv_JiuDianCalibrationPar = hv_CalibrationPar;
|
||
return true;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
#region 第二种保存文件的方法
|
||
//先确保标定参数文件已存在
|
||
// string filePath = @"Calibration/" + HelpFileName + ".dat"; //相机标定参数保存路径
|
||
|
||
//if (!Directory.Exists(@"Calibration/"))
|
||
//{
|
||
// Directory.CreateDirectory(@"Calibration/");
|
||
//}
|
||
|
||
|
||
//if (!File.Exists(filePath))
|
||
//{
|
||
// File.Create(filePath).Dispose();
|
||
//}
|
||
|
||
|
||
//if (File.Exists(filePath))
|
||
//{
|
||
// HTuple hv_SerializedItemHandle, hv_FileHandle;
|
||
// //保存标定参数
|
||
// HOperatorSet.SerializeHomMat2d(hv_CalibrationPar, out hv_SerializedItemHandle);
|
||
// HOperatorSet.OpenFile(filePath, "output_binary", out hv_FileHandle);
|
||
// HOperatorSet.FwriteSerializedItem(hv_FileHandle, hv_SerializedItemHandle);
|
||
// HOperatorSet.CloseFile(hv_FileHandle);
|
||
// this.hv_JiuDianCalibrationPar = hv_CalibrationPar;
|
||
// this.WhetherReadFile = true;
|
||
// return true;
|
||
//}
|
||
//else
|
||
//{
|
||
// return false;
|
||
//}
|
||
#endregion
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 读取标定参数
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool ReadCalibrationPar(string camereName)
|
||
{
|
||
if (WhetherReadFile == false && hv_JiuDianCalibrationPar != null)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
string filePath = @"Calibration/" + camereName + ".tup"; //相机标定参数保存路径
|
||
|
||
|
||
|
||
|
||
bool bl = false;
|
||
try
|
||
{
|
||
if (File.Exists(filePath))
|
||
{
|
||
HOperatorSet.ReadTuple(filePath, out hv_JiuDianCalibrationPar);
|
||
bl = true;
|
||
}
|
||
else
|
||
{
|
||
this.HelpFileName = VeiID + "_" + this.ID;
|
||
var oldfilePath = @"Calibration/" + HelpFileName + ".tup"; //相机标定参数保存路径
|
||
if (File.Exists(oldfilePath))
|
||
{
|
||
|
||
File.Copy(oldfilePath, filePath);
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
bl = false;
|
||
}
|
||
WhetherReadFile = !bl;
|
||
return bl;
|
||
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|