| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using SHJX.Service.Common.Logging;
- using Microsoft.Extensions.Logging;
- using SHJX.Service.Common.ReadXML;
- namespace shjxCamera
- {
- public class CreatCamera2
- {
- private static readonly ILogger logger = LogFactory.BuildLogger(typeof(CreatCamera2));
- private static ReadConfigUtil _config =ReadConfigUtil.Instance;
- /// <summary>
- /// 摄像头
- /// </summary>
- public WebCamera2 WebCam { get; set; }
- /// <summary>
- /// 是否检测到摄像头
- /// </summary>
- public static bool HadWebcams { get; set; }
- /// <summary>
- /// CreatCamera实例
- /// </summary>
- private static CreatCamera2 _camera;
- /// <summary>
- /// 锁
- /// </summary>
- private static readonly object obj_lock = new();
- /// <summary>
- /// 摄像头传感器名称
- /// </summary>
- /// "USB CAMERA"
- /// "Integrated Camera"
- private readonly string CamSensorName = _config.LogiCamera2Name;// "Logitech HD Webcam C270";// "Logi C270 HD WebCam";//
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="log"></param>
- public CreatCamera2()
- {
- Titration2Settings.SensorPara = new SensorsParameter2();
- string camName = "";
- HadWebcams = false;
- for (int i = 0; i < WebCamera2.GetCameras().Count; i++)
- {
- // 部分型号摄像头名称包含特殊符号,难以输入,故修改为名称关键词识别匹配,且兼容之前版本
- if (!WebCamera2.GetCameraName(i).ToLower().Contains(CamSensorName.ToLower()))
- {
- continue;
- }
- WebCam = null;
- WebCam = new WebCamera2(WebCamera2.GetCameraMoniker(i));
- camName = WebCam.VidCapDevice2.Source.Split('&')[3];
- logger.LogInformation("相机2编号为" + camName + ",请配写入配置文件中");
- if (_config.LogiCamera2.Equals(camName))
- {
- HadWebcams = true;
- break;
- }
- }
- if (!HadWebcams)
- {
- logger.LogError("未找到摄像头2!");
- }
- else
- {
- logger.LogDebug($"找到摄像头2!");
- }
- }
- /// <summary>
- /// 默认值
- /// </summary>
- public static CreatCamera2 Instance
- {
- get
- {
- lock (obj_lock)
- {
- if (_camera is null)
- {
- _camera = new CreatCamera2();
- }
- return _camera;
- }
- }
- }
- }
- }
|