|  | @@ -10,7 +10,6 @@ using System.Linq;
 | 
	
		
			
				|  |  |  using System.Text;
 | 
	
		
			
				|  |  |  using System.Threading.Tasks;
 | 
	
		
			
				|  |  |  using Prism.Mvvm;
 | 
	
		
			
				|  |  | -using static Cognex.VisionPro.QuickBuild.CogJobManager;
 | 
	
		
			
				|  |  |  using LampInspectionMachine.Log4xml;
 | 
	
		
			
				|  |  |  using Cognex.VisionPro.ImageFile;
 | 
	
		
			
				|  |  |  using System.Drawing;
 | 
	
	
		
			
				|  | @@ -40,6 +39,7 @@ using System.Diagnostics;
 | 
	
		
			
				|  |  |  using LampInspectionMachine.Cameralibs.HKCamera;
 | 
	
		
			
				|  |  |  using Newtonsoft.Json.Linq;
 | 
	
		
			
				|  |  |  using OpenCvSharp.Dnn;
 | 
	
		
			
				|  |  | +using LampInspectionMachine.Interfaces;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |  {
 | 
	
	
		
			
				|  | @@ -73,9 +73,6 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          public delegate void ChangeEventHandler(ICogImage e);
 | 
	
		
			
				|  |  |          public event ChangeEventHandler OnChange;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          public CameraService CameraService { get; set; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          public CogJobManager MyJobManager { get => myJobManager; set => myJobManager = value; }
 | 
	
	
		
			
				|  | @@ -101,36 +98,30 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          public ObservableCollection<CameraInfo> CamConfigs { get => _CamConfigs; set { SetProperty(ref _CamConfigs, value); } }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          public bool IsTriggerModel { get => _isTriggerModel; set { SetProperty(ref _isTriggerModel, value); } }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          public ICamera MyCamera { get => myCamera; set { SetProperty(ref myCamera, value); } }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          /// <summary>
 | 
	
		
			
				|  |  |          /// 相机对应模板工具
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          public List<CogToolBlock> CamTemplateS { get => _CamTemplateS; set => _CamTemplateS = value; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          public event Action<int> ToolBlockSwitched;
 | 
	
		
			
				|  |  |          /// <summary>
 | 
	
		
			
				|  |  |          /// 当前选中相机的SN
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          public string CurrCameraSn { get => _CurrCameraSn; set { SetProperty(ref _CurrCameraSn, value); } }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private  ObservableCollection<CameraInfo> _CamConfigs=new ObservableCollection<CameraInfo>();
 | 
	
		
			
				|  |  | +        private ObservableCollection<CameraInfo> _CamConfigs = new ObservableCollection<CameraInfo>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private List<CogToolBlock> _CamTemplateS=new  List<CogToolBlock>();
 | 
	
		
			
				|  |  | +        private List<CogToolBlock> _CamTemplateS = new List<CogToolBlock>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          private CogToolBlock cogToolBlock1;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private CameraInfo _CurrCamConfig=null;
 | 
	
		
			
				|  |  | +        private CameraInfo _CurrCamConfig = null;
 | 
	
		
			
				|  |  |          private ICamera myCamera;
 | 
	
		
			
				|  |  | -        private  bool _isTriggerModel=false;
 | 
	
		
			
				|  |  | +        private bool _isTriggerModel = false;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /// <summary>
 | 
	
	
		
			
				|  | @@ -138,11 +129,11 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          private CogJobManagerEdit myJobManagerEdit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private ObservableCollection<string>  _CameraList=new ObservableCollection<string>();
 | 
	
		
			
				|  |  | +        private ObservableCollection<string> _CameraList = new ObservableCollection<string>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private string _CurrCameraSn="";
 | 
	
		
			
				|  |  | +        private string _CurrCameraSn = "";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public Stopwatch stopwatch=new Stopwatch();
 | 
	
		
			
				|  |  | +        public Stopwatch stopwatch = new Stopwatch();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          public Management()
 | 
	
		
			
				|  |  |          {
 | 
	
	
		
			
				|  | @@ -159,7 +150,7 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              CameraService = new CameraService();
 | 
	
		
			
				|  |  |              CameraList = FindLoadCamera();
 | 
	
		
			
				|  |  | -            if ( CamConfigs.Count == 0 )
 | 
	
		
			
				|  |  | +            if (CamConfigs.Count == 0)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  CamConfigs.Add(new CameraInfo() { VppFileName = "Cam1.vpp" });
 | 
	
	
		
			
				|  | @@ -168,8 +159,6 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |                  CamConfigs.Add(new CameraInfo() { VppFileName = "Cam4.vpp" });
 | 
	
		
			
				|  |  |                  CamConfigs.Add(new CameraInfo() { VppFileName = "Cam5.vpp" });
 | 
	
		
			
				|  |  |                  CamConfigs.Add(new CameraInfo() { VppFileName = "Cam6.vpp" });
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -187,7 +176,7 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              tipService.ShowMsg("相机模板加载2%");
 | 
	
		
			
				|  |  | -            CogToolBlock cogToolBlock = ( CogToolBlock ) CogSerializer.LoadObjectFromFile(Environment.CurrentDirectory + "\\Vpp\\Cam1.vpp");
 | 
	
		
			
				|  |  | +            CogToolBlock cogToolBlock = (CogToolBlock)CogSerializer.LoadObjectFromFile(Environment.CurrentDirectory + "\\Vpp\\Cam1.vpp");
 | 
	
		
			
				|  |  |              CamTemplateS.Add(cogToolBlock);
 | 
	
		
			
				|  |  |              //tipService.ShowMsg("相机模板加载10%");
 | 
	
		
			
				|  |  |              //cogToolBlock = ( CogToolBlock ) CogSerializer.LoadObjectFromFile(Environment.CurrentDirectory + "\\Vpp\\Cam2.vpp");
 | 
	
	
		
			
				|  | @@ -219,17 +208,17 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          public void SoftTrigger()
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if ( isConnected )
 | 
	
		
			
				|  |  | +            if (isConnected)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  MyCamera.StopGrabbing();
 | 
	
		
			
				|  |  |                  LogHelper.Info($"软触发配置写入");
 | 
	
		
			
				|  |  | -                MyCamera.SetTriggerModeOff();
 | 
	
		
			
				|  |  | -                CurrCamConfig.TriggerMode = false;
 | 
	
		
			
				|  |  | -                MyCamera.SetTriggerSoftware();
 | 
	
		
			
				|  |  | -                if ( !MyCamera.CheckImageCallbackEvent(CamCallBack) )
 | 
	
		
			
				|  |  | -                    MyCamera.ImageCallbackEvent -= CamCallBack;
 | 
	
		
			
				|  |  | -                if ( MyCamera.CheckImageCallbackEvent(CamVisionProCallBack) )
 | 
	
		
			
				|  |  | -                    MyCamera.ImageCallbackEvent += CamVisionProCallBack;
 | 
	
		
			
				|  |  | +                //MyCamera.SetTriggerModeOff();
 | 
	
		
			
				|  |  | +                //CurrCamConfig.TriggerMode = false;
 | 
	
		
			
				|  |  | +                //MyCamera.SetTriggerSoftware();
 | 
	
		
			
				|  |  | +                //if (!MyCamera.CheckImageCallbackEvent(CamCallBack))
 | 
	
		
			
				|  |  | +                //    MyCamera.ImageCallbackEvent -= CamCallBack;
 | 
	
		
			
				|  |  | +                //if (MyCamera.CheckImageCallbackEvent(CamVisionProCallBack))
 | 
	
		
			
				|  |  | +                //    MyCamera.ImageCallbackEvent += CamVisionProCallBack;
 | 
	
		
			
				|  |  |                  LogHelper.Info($"软触发取图");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  MyCamera.Grab();
 | 
	
	
		
			
				|  | @@ -242,13 +231,13 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          public void SoftTrigger__Continue()
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            MyCamera.SetTriggerModeOff();
 | 
	
		
			
				|  |  | -            CurrCamConfig.TriggerMode = false;
 | 
	
		
			
				|  |  | -            MyCamera.SetTriggerSoftware();
 | 
	
		
			
				|  |  | -            if ( MyCamera.CheckImageCallbackEvent(CamCallBack) )
 | 
	
		
			
				|  |  | -                MyCamera.ImageCallbackEvent += CamCallBack;
 | 
	
		
			
				|  |  | -            if ( !MyCamera.CheckImageCallbackEvent(CamVisionProCallBack) )
 | 
	
		
			
				|  |  | -                MyCamera.ImageCallbackEvent -= CamVisionProCallBack;
 | 
	
		
			
				|  |  | +            //MyCamera.SetTriggerModeOff();
 | 
	
		
			
				|  |  | +            //CurrCamConfig.TriggerMode = false;
 | 
	
		
			
				|  |  | +            //MyCamera.SetTriggerSoftware();
 | 
	
		
			
				|  |  | +            //if (MyCamera.CheckImageCallbackEvent(CamCallBack))
 | 
	
		
			
				|  |  | +            //    MyCamera.ImageCallbackEvent += CamCallBack;
 | 
	
		
			
				|  |  | +            //if (!MyCamera.CheckImageCallbackEvent(CamVisionProCallBack))
 | 
	
		
			
				|  |  | +            //    MyCamera.ImageCallbackEvent -= CamVisionProCallBack;
 | 
	
		
			
				|  |  |              LogHelper.Info($"连续采集启动");
 | 
	
		
			
				|  |  |              MyCamera.StartGrabbing();
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -257,13 +246,13 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          public void SetHardTrigger_CallBack()
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              LogHelper.Info($"硬触发模式 启动");
 | 
	
		
			
				|  |  | -            MyCamera.SetTriggerModeOn();
 | 
	
		
			
				|  |  | -            CurrCamConfig.TriggerMode = true;
 | 
	
		
			
				|  |  | -            MyCamera.SetTriggerSoftware(0);
 | 
	
		
			
				|  |  | -            if ( !MyCamera.CheckImageCallbackEvent(CamCallBack) )
 | 
	
		
			
				|  |  | -                MyCamera.ImageCallbackEvent -= CamCallBack;
 | 
	
		
			
				|  |  | -            if ( MyCamera.CheckImageCallbackEvent(CamVisionProCallBack) )
 | 
	
		
			
				|  |  | -                MyCamera.ImageCallbackEvent += CamVisionProCallBack;
 | 
	
		
			
				|  |  | +            //MyCamera.SetTriggerModeOn();
 | 
	
		
			
				|  |  | +            //CurrCamConfig.TriggerMode = true;
 | 
	
		
			
				|  |  | +            //MyCamera.SetTriggerSoftware(0);
 | 
	
		
			
				|  |  | +            //if (!MyCamera.CheckImageCallbackEvent(CamCallBack))
 | 
	
		
			
				|  |  | +            //    MyCamera.ImageCallbackEvent -= CamCallBack;
 | 
	
		
			
				|  |  | +            //if (MyCamera.CheckImageCallbackEvent(CamVisionProCallBack))
 | 
	
		
			
				|  |  | +            //    MyCamera.ImageCallbackEvent += CamVisionProCallBack;
 | 
	
		
			
				|  |  |              MyCamera.StartGrabbing();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          /// <summary>
 | 
	
	
		
			
				|  | @@ -271,13 +260,13 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  |          public ObservableCollection<string> FindLoadCamera()
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            List<string> listsn = CameraService.GetDeviceEnum();
 | 
	
		
			
				|  |  | -            if ( listsn.Count > 0 )
 | 
	
		
			
				|  |  | +            var listsn = MvCamera.GetDevices();
 | 
	
		
			
				|  |  | +            if (listsn.Length > 0)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                ObservableCollection<string> strings=new ObservableCollection<string>();
 | 
	
		
			
				|  |  | -                for ( int i = 0; i < listsn.Count; i++ )
 | 
	
		
			
				|  |  | +                ObservableCollection<string> strings = new ObservableCollection<string>();
 | 
	
		
			
				|  |  | +                for (int i = 0; i < listsn.Length; i++)
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    strings.Add(listsn[ i ]);
 | 
	
		
			
				|  |  | +                    //strings.Add(listsn[i].);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  return strings;
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -292,17 +281,17 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          public void InitCamera(string name)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              // 初始化相机
 | 
	
		
			
				|  |  | -            if ( isConnected && myCamera != null )
 | 
	
		
			
				|  |  | +            if (isConnected && myCamera != null)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  myCamera.CloseDevice();
 | 
	
		
			
				|  |  |                  myCamera = null;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            Guid guid= new Guid();
 | 
	
		
			
				|  |  | +            Guid guid = new Guid();
 | 
	
		
			
				|  |  |              CameraService.CreateCamera(guid, new CameraInfo() { SerialNumber = name });
 | 
	
		
			
				|  |  |              myCamera = CameraService.GetCamera(guid);
 | 
	
		
			
				|  |  |              bool res = myCamera.OpenDevice();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if ( !res )
 | 
	
		
			
				|  |  | +            if (!res)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  myCamera.CloseDevice();
 | 
	
		
			
				|  |  |                  myCamera = null;
 | 
	
	
		
			
				|  | @@ -317,13 +306,13 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          public void InitCameras()
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              CameraService = new CameraService();
 | 
	
		
			
				|  |  | -            foreach ( var item in CamConfigs )
 | 
	
		
			
				|  |  | +            foreach (var item in CamConfigs)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  try
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  |                      CameraService.CreateCamera(item.Id, item);
 | 
	
		
			
				|  |  |                      CameraService.GetCamera(item.Id).CameraConnectChangedEvent += Management_CameraConnectChangedEvent;
 | 
	
		
			
				|  |  | -                    if ( CameraService.GetCamera(item.Id).OpenDevice() )
 | 
	
		
			
				|  |  | +                    if (CameraService.GetCamera(item.Id).OpenDevice())
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -333,7 +322,7 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                catch ( Exception ex )
 | 
	
		
			
				|  |  | +                catch (Exception ex)
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -363,9 +352,9 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              try
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -               
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                  Image = image;
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              finally
 | 
	
		
			
				|  |  |              {
 | 
	
	
		
			
				|  | @@ -382,9 +371,9 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              try
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                  Image = image;
 | 
	
		
			
				|  |  | -               
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              finally
 | 
	
		
			
				|  |  |              {
 | 
	
	
		
			
				|  | @@ -398,8 +387,8 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              // 验证像素格式(支持MONO8/RGB8转灰度)
 | 
	
		
			
				|  |  | -            if ( pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 &&
 | 
	
		
			
				|  |  | -                pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed )
 | 
	
		
			
				|  |  | +            if (pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 &&
 | 
	
		
			
				|  |  | +                pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  throw new ArgumentException("Unsupported pixel format");
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -421,10 +410,10 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              // IntPtr destPtr = cogImage.GetPixelData(CogImageDataModeConstants.ReadWrite);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if ( pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 )
 | 
	
		
			
				|  |  | +            if (pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  // 直接拷贝MONO8数据
 | 
	
		
			
				|  |  | -                SafeMemoryCopy(destPtr, pData,  width * height );
 | 
	
		
			
				|  |  | +                SafeMemoryCopy(destPtr, pData, width * height);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              else // RGB转灰度
 | 
	
		
			
				|  |  |              {
 | 
	
	
		
			
				|  | @@ -434,12 +423,12 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |                  unsafe
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  |                      byte* pDest = (byte*)destPtr.ToPointer();
 | 
	
		
			
				|  |  | -                    for ( int i = 0; i < rgbBuffer.Length; i += 3 )
 | 
	
		
			
				|  |  | +                    for (int i = 0; i < rgbBuffer.Length; i += 3)
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  |                          // RGB转灰度公式:0.299*R + 0.587*G + 0.114*B
 | 
	
		
			
				|  |  | -                        *pDest++ = ( byte ) ( 0.299 * rgbBuffer[ i ] +
 | 
	
		
			
				|  |  | -                                         0.587 * rgbBuffer[ i + 1 ] +
 | 
	
		
			
				|  |  | -                                         0.114 * rgbBuffer[ i + 2 ] );
 | 
	
		
			
				|  |  | +                        *pDest++ = (byte)(0.299 * rgbBuffer[i] +
 | 
	
		
			
				|  |  | +                                         0.587 * rgbBuffer[i + 1] +
 | 
	
		
			
				|  |  | +                                         0.114 * rgbBuffer[i + 2]);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -449,7 +438,7 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          // 将海康相机帧数据转换为CogImage24PlanarColor彩色图像
 | 
	
		
			
				|  |  |          public static ICogImage ConvertToColorCogImage(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if ( pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed )
 | 
	
		
			
				|  |  | +            if (pFrameInfo.enPixelType != MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  throw new ArgumentException("Only RGB8 format supported for color conversion");
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -463,9 +452,9 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              // 获取三个颜色平面指针
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            CogImage8Grey red= cogColorImage.GetPlane(CogImagePlaneConstants.Red);
 | 
	
		
			
				|  |  | -            CogImage8Grey green= cogColorImage.GetPlane(CogImagePlaneConstants.Green);
 | 
	
		
			
				|  |  | -            CogImage8Grey blue= cogColorImage.GetPlane(CogImagePlaneConstants.Blue);
 | 
	
		
			
				|  |  | +            CogImage8Grey red = cogColorImage.GetPlane(CogImagePlaneConstants.Red);
 | 
	
		
			
				|  |  | +            CogImage8Grey green = cogColorImage.GetPlane(CogImagePlaneConstants.Green);
 | 
	
		
			
				|  |  | +            CogImage8Grey blue = cogColorImage.GetPlane(CogImagePlaneConstants.Blue);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -473,11 +462,11 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |      CogImageDataModeConstants.ReadWrite,
 | 
	
		
			
				|  |  |      0, 0,
 | 
	
		
			
				|  |  |      red.Width, red.Height).Scan0;  // 获取像素数据指针
 | 
	
		
			
				|  |  | -            IntPtr greenPtr =cogColorImage.GetPlane(CogImagePlaneConstants.Green).Get8GreyPixelMemory(
 | 
	
		
			
				|  |  | +            IntPtr greenPtr = cogColorImage.GetPlane(CogImagePlaneConstants.Green).Get8GreyPixelMemory(
 | 
	
		
			
				|  |  |      CogImageDataModeConstants.ReadWrite,
 | 
	
		
			
				|  |  |      0, 0,
 | 
	
		
			
				|  |  |      red.Width, red.Height).Scan0; ;
 | 
	
		
			
				|  |  | -            IntPtr bluePtr =cogColorImage.GetPlane(CogImagePlaneConstants.Blue).Get8GreyPixelMemory(
 | 
	
		
			
				|  |  | +            IntPtr bluePtr = cogColorImage.GetPlane(CogImagePlaneConstants.Blue).Get8GreyPixelMemory(
 | 
	
		
			
				|  |  |      CogImageDataModeConstants.ReadWrite,
 | 
	
		
			
				|  |  |      0, 0,
 | 
	
		
			
				|  |  |      red.Width, red.Height).Scan0; ;
 | 
	
	
		
			
				|  | @@ -492,11 +481,11 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |                  byte* pGreen = (byte*)greenPtr.ToPointer();
 | 
	
		
			
				|  |  |                  byte* pBlue = (byte*)bluePtr.ToPointer();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                for ( int i = 0; i < rgbBuffer.Length; i += 3 )
 | 
	
		
			
				|  |  | +                for (int i = 0; i < rgbBuffer.Length; i += 3)
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    *pRed++ = rgbBuffer[ i ];     // R
 | 
	
		
			
				|  |  | -                    *pGreen++ = rgbBuffer[ i + 1 ]; // G
 | 
	
		
			
				|  |  | -                    *pBlue++ = rgbBuffer[ i + 2 ];  // B
 | 
	
		
			
				|  |  | +                    *pRed++ = rgbBuffer[i];     // R
 | 
	
		
			
				|  |  | +                    *pGreen++ = rgbBuffer[i + 1]; // G
 | 
	
		
			
				|  |  | +                    *pBlue++ = rgbBuffer[i + 2];  // B
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return cogColorImage;
 | 
	
	
		
			
				|  | @@ -506,7 +495,7 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          private void ImageCallback(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              ICogImage resultImage;
 | 
	
		
			
				|  |  | -            if ( pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8 )
 | 
	
		
			
				|  |  | +            if (pFrameInfo.enPixelType == MvCamCtrl.NET.MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  resultImage = ConvertToCogImage(pData, ref pFrameInfo);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -515,7 +504,7 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |                  resultImage = ConvertToColorCogImage(pData, ref pFrameInfo);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -           
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              Image = resultImage;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -530,9 +519,9 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |              try
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                cogToolBlock1.Inputs[ 0 ].Value = image;
 | 
	
		
			
				|  |  | +                cogToolBlock1.Inputs[0].Value = image;
 | 
	
		
			
				|  |  |                  cogToolBlock1.Run();
 | 
	
		
			
				|  |  | -                Image = ( ICogImage ) cogToolBlock1.Outputs[ 6 ].Value;
 | 
	
		
			
				|  |  | +                Image = (ICogImage)cogToolBlock1.Outputs[6].Value;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              finally
 | 
	
		
			
				|  |  |              {
 | 
	
	
		
			
				|  | @@ -549,12 +538,12 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          public static Bitmap SafeConvert(WriteableBitmap wb)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              Bitmap bmp = new Bitmap(wb.PixelWidth, wb.PixelHeight);
 | 
	
		
			
				|  |  | -            using ( var ms = new System.IO.MemoryStream() )
 | 
	
		
			
				|  |  | +            using (var ms = new System.IO.MemoryStream())
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  var encoder = new PngBitmapEncoder();
 | 
	
		
			
				|  |  |                  encoder.Frames.Add(BitmapFrame.Create(wb));
 | 
	
		
			
				|  |  |                  encoder.Save(ms);
 | 
	
		
			
				|  |  | -                bmp = ( Bitmap ) System.Drawing.Image.FromStream(ms);
 | 
	
		
			
				|  |  | +                bmp = (Bitmap)System.Drawing.Image.FromStream(ms);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return bmp;
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -566,21 +555,21 @@ namespace LampInspectionMachine.Core
 | 
	
		
			
				|  |  |          // 安全封装方法(带参数校验)
 | 
	
		
			
				|  |  |          public static void SafeMemoryCopy(IntPtr dest, IntPtr src, int byteCount)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if ( dest == IntPtr.Zero || src == IntPtr.Zero )
 | 
	
		
			
				|  |  | +            if (dest == IntPtr.Zero || src == IntPtr.Zero)
 | 
	
		
			
				|  |  |                  throw new ArgumentNullException("指针参数不能为null");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if ( byteCount <= 0 )
 | 
	
		
			
				|  |  | +            if (byteCount <= 0)
 | 
	
		
			
				|  |  |                  throw new ArgumentOutOfRangeException("字节数必须大于0");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            RtlMoveMemory(dest, src, ( uint ) byteCount);
 | 
	
		
			
				|  |  | +            RtlMoveMemory(dest, src, (uint)byteCount);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          /// <summary>
 | 
	
		
			
				|  |  |          /// 将WriteableBitmap转换为CogImage8Grey(自动处理彩色转灰度)
 | 
	
		
			
				|  |  |          /// </summary>
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          public void OnSwitchToolBlock(int index)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            cogToolBlock1 = CamTemplateS[ index ];
 | 
	
		
			
				|  |  | +            cogToolBlock1 = CamTemplateS[index];
 | 
	
		
			
				|  |  |              ToolBlockSwitched?.Invoke(index); // 触发事件,传递索引参数。
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 |