CreatGraber.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 
  2. using System.Collections.Generic;
  3. using SHJX.Service.Common.ReadXML;
  4. using SHJX.Service.Common.Logging;
  5. using Microsoft.Extensions.Logging;
  6. namespace SHJX.Service.Common.Camera
  7. {
  8. public class CreatGraber
  9. {
  10. private static readonly ILogger logger = LogFactory.BuildLogger(typeof(CreatGraber));
  11. /// <summary>
  12. /// 摄像头
  13. /// </summary>
  14. public WebCamera WebCam { get; set; }
  15. public ColorDataGraber Graber { get; set; }
  16. /// <summary>
  17. /// 是否检测到摄像头
  18. /// </summary>
  19. public bool HadWebcams { get; set; }
  20. public CreatGraber(string LogiCameraName, out int cameraNum)
  21. {
  22. cameraNum = 0;
  23. TitrationSettings.SensorPara = new SensorsParameter();
  24. #region 检测识别系统中的探头设备
  25. HadWebcams = false;
  26. for (var i = 0; i < WebCamera.GetCameraCounts(); i++)
  27. {
  28. // 部分型号摄像头名称包含特殊符号,难以输入,故修改为名称关键词识别匹配,且兼容之前版本
  29. if (!WebCamera.GetCameraName(i).ToLower().Contains(TitrationSettings.SensorPara.CamSensorName.ToLower()) )
  30. continue;
  31. WebCam = new WebCamera(WebCamera.GetCameraMoniker(i));
  32. string camName = WebCam.vidCapDevice.Source.Split('&')[3];
  33. logger.LogInformation("相机编号为"+ camName + ",请配写入配置文件中");
  34. if (LogiCameraName.Equals( camName))
  35. {
  36. HadWebcams = true;
  37. cameraNum = 1;
  38. break;
  39. }
  40. }
  41. if (WebCam is null)
  42. {
  43. logger.LogError("未找到摄像头!");
  44. }
  45. WebCam ??= new WebCamera();
  46. Graber = new ColorDataGraber(WebCam)
  47. {
  48. Interval = 40,
  49. RectROI = TitrationSettings.SensorPara.RoiSample
  50. };
  51. #endregion
  52. }
  53. }
  54. }