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;
///
/// 摄像头
///
public WebCamera2 WebCam { get; set; }
///
/// 是否检测到摄像头
///
public static bool HadWebcams { get; set; }
///
/// CreatCamera实例
///
private static CreatCamera2 _camera;
///
/// 锁
///
private static readonly object obj_lock = new();
///
/// 摄像头传感器名称
///
/// "USB CAMERA"
/// "Integrated Camera"
private readonly string CamSensorName = _config.LogiCamera2Name;// "Logitech HD Webcam C270";// "Logi C270 HD WebCam";//
///
/// 初始化
///
///
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!");
}
}
///
/// 默认值
///
public static CreatCamera2 Instance
{
get
{
lock (obj_lock)
{
if (_camera is null)
{
_camera = new CreatCamera2();
}
return _camera;
}
}
}
}
}