using System.Collections.Generic; using SHJX.Service.Common.ReadXML; using SHJX.Service.Common.Logging; using Microsoft.Extensions.Logging; namespace SHJX.Service.Common.Camera { public class CreatGraber { private static readonly ILogger logger = LogFactory.BuildLogger(typeof(CreatGraber)); /// /// 摄像头 /// public WebCamera WebCam { get; set; } public ColorDataGraber Graber { get; set; } /// /// 是否检测到摄像头 /// public bool HadWebcams { get; set; } public CreatGraber(string LogiCameraName, out int cameraNum) { cameraNum = 0; TitrationSettings.SensorPara = new SensorsParameter(); #region 检测识别系统中的探头设备 HadWebcams = false; for (var i = 0; i < WebCamera.GetCameraCounts(); i++) { // 部分型号摄像头名称包含特殊符号,难以输入,故修改为名称关键词识别匹配,且兼容之前版本 if (!WebCamera.GetCameraName(i).ToLower().Contains(TitrationSettings.SensorPara.CamSensorName.ToLower()) ) continue; WebCam = new WebCamera(WebCamera.GetCameraMoniker(i)); string camName = WebCam.vidCapDevice.Source.Split('&')[3]; logger.LogInformation("相机编号为"+ camName + ",请配写入配置文件中"); if (LogiCameraName.Equals( camName)) { HadWebcams = true; cameraNum = 1; break; } } if (WebCam is null) { logger.LogError("未找到摄像头!"); } WebCam ??= new WebCamera(); Graber = new ColorDataGraber(WebCam) { Interval = 40, RectROI = TitrationSettings.SensorPara.RoiSample }; #endregion } } }