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