using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Reflection; namespace LB_VisionProcesses.Cameras { public class Total { /// /// 图像计数 /// public int iImageCount { get; set; } = 0; /// /// 扫描计数 /// public int iScanCount { get; set; } = 0; /// /// 完整轮胎计数 /// public int TyreCount { get; set; } = 0; /// /// 每张轮胎所需图像数(2D相机使用,默认1表示3D相机) /// public int ImagesPerTyre { get; set; } = 1; /// /// 当前轮胎的图像序号(0~ImagesPerTyre-1) /// public int CurrentImageIndex { get; set; } = 0; /// /// 轮胎OK计数 /// public int TyreOK { get; set; } = 0; /// /// 轮胎NG计数 /// public int TyreNG { get; set; } = 0; /// /// 当前轮胎ID /// public int CurrentTyreID { get; set; } = 1; public Total() { } public Total(int iImageCount, int iScanCount) { this.iImageCount = iImageCount; this.iScanCount = iScanCount; } /// /// 添加图像并更新轮胎计数 /// /// 图像检测结果 /// 是否完成一个轮胎 public bool AddImageResult(bool imageResult) { iImageCount++; CurrentImageIndex++; // 检查是否完成一个轮胎 if (CurrentImageIndex >= ImagesPerTyre) { TyreCount++; CurrentImageIndex = 0; // 更新轮胎OK/NG计数(n张中任一NG则整胎NG) if (imageResult) TyreOK++; else TyreNG++; CurrentTyreID++; return true; } return false; } /// /// 获取轮胎良品率 /// public double TyreRateOK => TyreCount > 0 ? (TyreOK / (double)TyreCount) * 100 : 0; public void Clear() { iImageCount = 0; iScanCount = 0; TyreCount = 0; CurrentImageIndex = 0; TyreOK = 0; TyreNG = 0; CurrentTyreID = 1; } /// /// 重置轮胎计数(保留ImagesPerTyre配置) /// public void ResetTyreCount() { TyreCount = 0; CurrentImageIndex = 0; TyreOK = 0; TyreNG = 0; CurrentTyreID = 1; } } public interface ICamera : IDisposable { #region operate Dictionary> CollectedImages { get; set; } /// /// 获取相机SN枚举 /// /// List GetListEnum(); /// /// 初始化相机 /// /// /// bool InitDevice(string SN, object Handle); /// /// 注销相机 /// bool CloseDevice(); /// /// 软触发模式 启动相机 /// /// bool StartWith_SoftTriggerModel(); /// /// 硬触发模式 启动相机 /// /// /// bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0); /// /// 等待软/硬触发获取图像 /// /// /// /// bool GetImage(out Bitmap bitmap, int outtime = 3000); /// /// 软触发获取图像 /// /// /// /// bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000); /// /// 软触发单次 /// /// bool SoftTrigger(); /// /// 连续采集模式 /// /// bool StartContinuousGrab(); #endregion #region SettingConfig /// /// 设置相机参数 /// /// void SetCamConfig(CameraConfig config); /// /// 获取相机参数 /// /// void GetCamConfig(out CameraConfig config); /// /// 设置触发模式及触发源 /// /// /// /// bool SetTriggerMode(TriggerMode mode, TriggerSource source = TriggerSource.Line0); /// /// 获取触发模式及触发源 /// /// /// /// bool GetTriggerMode(out TriggerMode mode, out TriggerSource source); /// /// 设置曝光时长 /// /// /// bool SetExpouseTime(double value); /// /// 获取曝光时长 /// /// /// bool GetExpouseTime(out double value); /// /// 设置硬触发极性 /// /// /// bool SetTriggerPolarity(TriggerPolarity polarity); /// /// 获取硬触发极性 /// /// /// bool GetTriggerPolarity(out TriggerPolarity polarity); /// /// 设置触发滤波时间 (us) /// /// /// bool SetTriggerFliter(double flitertime); /// /// 获取触发滤波时间 (us) /// /// /// bool GetTriggerFliter(out double flitertime); /// /// 设置触发延时 /// /// /// bool SetTriggerDelay(double delay); /// /// 获取触发延时 /// /// /// bool GetTriggerDelay(out double delay); /// /// 设置增益 /// /// /// bool SetGain(double gain); /// /// 获取增益值 /// /// /// bool GetGain(out double gain); /// /// 设置信号线模式 /// /// /// /// bool SetLineMode(IOLines line, LineMode mode); /// /// 设置信号线电平状态 /// /// /// /// bool SetLineStatus(IOLines line, LineStatus linestatus); /// /// 获取信号线电平状态 /// /// /// /// bool GetLineStatus(IOLines line, out LineStatus lineStatus); /// /// 自动白平衡 /// /// bool AutoBalanceWhite(); /// /// 开始采图 /// /// bool StartGrabbing(); /// /// 停止采图 /// /// bool StopGrabbing(); #endregion } public enum CameraBrand { /// /// 华睿工业相机 /// HRCamera, /// /// 兰宝工业相机 /// LBCamera, /// /// 未知相机 /// UNSUPPORTED } public enum IOLines { Line0, Line1, Line2, Line3, Line4, Line5 } public enum LineMode { Input, Output } public enum LineStatus { Hight, Low } public enum TriggerMode { Off, On } public enum TriggerPolarity { RisingEdge, FallingEdge, HighLevel, LowLevel } public enum TriggerSource { Software, Line0, Line1, Line2, Line3, Line4, Line5, None } public class CameraEventArgs { public string SN { get; set; } public Bitmap Bitmap { get; set; } public string[] arrResult; public CameraEventArgs() { } public CameraEventArgs(string sn, Bitmap bitmap, string[] arrResult = null) { this.SN = sn; this.Bitmap = bitmap; this.arrResult = arrResult; } } }