282 lines
9.2 KiB
C#
282 lines
9.2 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Api.DataType;
|
|
using CogCommon;
|
|
using VisionCommon;
|
|
using Hermes;
|
|
using Cognex.VisionPro;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
|
|
namespace CogCamera {
|
|
/// <summary>
|
|
/// Cognex 카메라 에이전트
|
|
/// </summary>
|
|
public class CogCameraAgent : CameraAgentBase {
|
|
private Logger _Logger;
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="fovInfo">FOV 정보</param>
|
|
public CogCameraAgent(FovInfo fovInfo) : base(fovInfo) {
|
|
_Logger = new Logger(string.Format("CamAgent[{0}]", fovInfo.FovName));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 이미지 사이즈 가져오기
|
|
/// </summary>
|
|
/// <returns>이미지 사이즈</returns>
|
|
public override ImageSize GetImageSize() {
|
|
return _CamDev.GetImageSize();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 이미지 버퍼 복제
|
|
/// </summary>
|
|
/// <returns>복제 버퍼</returns>
|
|
public override object CloneImageBuffer() {
|
|
if (_CamDev != null && _CamDev.IsActivated) {
|
|
return _CamDev.CloneImageBuffer();
|
|
}
|
|
else {
|
|
return AllocDefaultImageBuffer();
|
|
}
|
|
}
|
|
|
|
private ICogImage AllocDefaultImageBuffer() {
|
|
if (_CamConfig == null) {
|
|
_Logger.FuncE("_CamConfig is null.");
|
|
return null;
|
|
}
|
|
|
|
ICogImage image = new CogImage8Grey(_CamConfig.ImageSize.Width, _CamConfig.ImageSize.Height);
|
|
CogEnvironment.ClearImage(image);
|
|
|
|
return image;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 버퍼로부터 이미지를 꺼내온다.
|
|
/// </summary>
|
|
/// <param name="cameraDisplay">디스플레이</param>
|
|
/// <param name="image">이미지</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int GetGrabImageFromBuffer(ICameraDisplay cameraDisplay, ref object image) {
|
|
var cogCameraDisplay = cameraDisplay as ICogCameraDisplay;
|
|
FitAndClearImage(cogCameraDisplay);
|
|
|
|
if (!_CamDev.IsActivated) {
|
|
_Logger.FuncE("Camera Not Activated.");
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
return _CamDev.GetGrabImageFromBuffer(cameraDisplay, ref image);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 동기식 그랩
|
|
/// </summary>
|
|
/// <param name="cameraDisplay">디스플레이</param>
|
|
/// <param name="image">그랩 이미지</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int GrabSync(ICameraDisplay cameraDisplay, ref object image) {
|
|
if (_CamDev == null) {
|
|
_Logger.FuncE("_CamDev is null.");
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
var cogCameraDisplay = cameraDisplay as ICogCameraDisplay;
|
|
FitAndClearImage(cogCameraDisplay);
|
|
|
|
if (!_CamDev.IsActivated) {
|
|
_Logger.FuncE("Camera Not Activated.");
|
|
return E1.GENERIC;
|
|
}
|
|
//if (_CamDev.IsLiveRunning) {
|
|
// StopLive();
|
|
//}
|
|
|
|
return _CamDev.GrabSync(cogCameraDisplay, ref image);
|
|
}
|
|
|
|
private void FitAndClearImage(ICogCameraDisplay cogCameraDisplay) {
|
|
if (cogCameraDisplay == null) {
|
|
return;
|
|
}
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
cogCameraDisplay.FitImage(_CamConfig.ImageSize);
|
|
cogCameraDisplay.ClearAllGraphics();
|
|
}));
|
|
}
|
|
|
|
//public MIL_ID GetGrabImageFromQueue(eGrabTrigSrcType grabTrigSrcType) {
|
|
// return _MilCamera.GetGrabImageFromQueue(grabTrigSrcType);
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 라이브 시작
|
|
/// </summary>
|
|
/// <param name="cameraDisplay">디스플레이</param>
|
|
public override void StartLive(ICameraDisplay cameraDisplay) {
|
|
if (_CamDev == null) {
|
|
_Logger.FuncE("_CamDev is null.");
|
|
return;
|
|
}
|
|
if (!_CamDev.IsActivated) {
|
|
_Logger.FuncE("Camera Not Activated.");
|
|
return;
|
|
}
|
|
|
|
var cogCameraDisplay = cameraDisplay as ICogCameraDisplay;
|
|
|
|
// 현재 Fov를 사용하는 디스플레이의 라이브 버튼만 켜기
|
|
CamLiveBtnManager.SetVisibilityAsLiveStart(cogCameraDisplay.GetDisplayType(), _FovInfo);
|
|
|
|
FitAndClearImage(cogCameraDisplay);
|
|
|
|
_Logger.I("Start Live.");
|
|
_CamDev.StartLive(cogCameraDisplay);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 라이브 종료
|
|
/// </summary>
|
|
public override void StopLive() {
|
|
if (_CamDev == null) {
|
|
_Logger.FuncE("_CamDev is null.");
|
|
return;
|
|
}
|
|
|
|
// 같은 HwCam을 사용하는 디스플레이의 라이브 버튼만 켜기
|
|
CamLiveBtnManager.SetVisibilityAsLiveStop(_FovInfo);
|
|
|
|
_Logger.I("Stop Live.");
|
|
_CamDev.StopLive();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 라이브 상태 체크
|
|
/// </summary>
|
|
/// <returns>라이브 상태</returns>
|
|
public override bool IsLiveRunning() {
|
|
return _CamDev.IsLiveOn();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카메라 노출시간 읽기
|
|
/// </summary>
|
|
/// <returns>노출시간</returns>
|
|
public override double GetExposure() {
|
|
return _CamDev.GetExposure();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카메라 노출시간 쓰기
|
|
/// </summary>
|
|
/// <param name="exposureTime_ms">노출시간[ms]</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int SetExposure(double exposureTime_ms) {
|
|
return _CamDev.SetExposure(exposureTime_ms);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 이미지 반전 & 회전 Config 갱신
|
|
/// </summary>
|
|
/// <param name="flipAndRotation">이미지 반전 & 회전 Config</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int ResetFlipAndRotation(FlipAndRotation flipAndRotation) {
|
|
return _CamDev.ResetFlipAndRotation(flipAndRotation);
|
|
}
|
|
|
|
#region Activate & Deactivate
|
|
public override int Activate() {
|
|
return _CamDev.Activate();
|
|
}
|
|
|
|
public override int Deactivate() {
|
|
return _CamDev.Deactivate();
|
|
}
|
|
#endregion
|
|
|
|
#region For Flying
|
|
/// <summary>
|
|
/// 플라잉 시작
|
|
/// </summary>
|
|
/// <param name="fovInfo">FOV 정보</param>
|
|
/// <param name="param">추가 파라미터</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int StartFlying(FovInfo fovInfo, object param = null) {
|
|
return _CamDev.StartFlying(fovInfo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 플라잉 종료
|
|
/// </summary>
|
|
/// <param name="param">추가 파라미터</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int StopFlying(object param = null) {
|
|
return _CamDev.StopFlying();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 플라잉 상태 체크
|
|
/// </summary>
|
|
/// <returns>성공 유무</returns>
|
|
public override bool IsFlyingRunning() {
|
|
return _CamDev.IsFlyingRunning();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재 플라잉 인덱스 가져오기
|
|
/// </summary>
|
|
/// <returns>현재 플라잉 인덱스</returns>
|
|
public override int GetCurrentFlyingIdx() {
|
|
return _CamDev.GetCurrentFlyingIdx();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 플라잉 이미지 가져오기
|
|
/// </summary>
|
|
/// <param name="flyingIdx">플라잉 인덱스</param>
|
|
/// <returns>플라잉 이미지</returns>
|
|
public override object GetFlyingImage(int flyingIdx) {
|
|
return _CamDev.GetFlyingImage(flyingIdx);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 플라잉 이미지 전체 가져오기
|
|
/// </summary>
|
|
/// <returns>플라잉 이미지 전체</returns>
|
|
public override object[] GetFlyingImages() {
|
|
return _CamDev.GetFlyingImages();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 플라잉 합성(원장) 이미지 가져오기. *원장 : Child 이미지를 조합하여 한 장으로 만듬
|
|
/// </summary>
|
|
/// <returns>플아잉 합성(원장) 이미지</returns>
|
|
public override object GetParentImage() {
|
|
return _CamDev.GetParentImage();
|
|
}
|
|
#endregion
|
|
|
|
#region For Child Image
|
|
/// <summary>
|
|
/// Child 이미지들로 Parent(원장) 이미지가 정상적으로 만들어지는지 검증
|
|
/// </summary>
|
|
/// <param name="cameraDisplay">디스플레이</param>
|
|
/// <param name="image">원장(부모) 이미지</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int VerifyChildImage(ICameraDisplay cameraDisplay, ref object image) {
|
|
return _CamDev.VerifyChildImage(cameraDisplay, ref image);
|
|
}
|
|
#endregion
|
|
}
|
|
} |