301 lines
10 KiB
C#
301 lines
10 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Api.DataType;
|
|
using MilCommon;
|
|
using VisionCommon;
|
|
using Hermes;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
|
|
namespace MilCamera {
|
|
/// <summary>
|
|
/// MIL 카메라 에이전트
|
|
/// </summary>
|
|
public class MilCameraAgent : CameraAgentBase {
|
|
private Logger _Logger;
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="fovInfo">FOV 정보</param>
|
|
public MilCameraAgent(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 MIL_ID AllocDefaultImageBuffer() {
|
|
if (!MilEnvironment.Instance.HasValidLicense()) {
|
|
return MIL.M_NULL;
|
|
}
|
|
if (_CamConfig == null) {
|
|
_Logger.FuncE("_CamConfig is null.");
|
|
return MIL.M_NULL;
|
|
}
|
|
|
|
MIL_ID image = MIL.M_NULL;
|
|
MIL.MbufAlloc2d(
|
|
MilEnvironment.Instance.GetSystem(_CamConfig.CamConnConfig.BoardType, _CamConfig.CamConnConfig.BoardSlotPos),
|
|
_CamConfig.ImageSize.Width,
|
|
_CamConfig.ImageSize.Height,
|
|
8 + MIL.M_UNSIGNED,
|
|
MIL.M_IMAGE + MIL.M_GRAB + MIL.M_PROC + MIL.M_DISP,
|
|
ref image);
|
|
MIL.MbufClear(image, 0);
|
|
|
|
return image;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 버퍼로부터 이미지를 꺼내온다.
|
|
/// </summary>
|
|
/// <param name="cameraDisplay">디스플레이</param>
|
|
/// <param name="image">이미지</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int GetGrabImageFromBuffer(ICameraDisplay cameraDisplay, ref object image) {
|
|
var milCameraDisplay = cameraDisplay as IMilCameraDisplay;
|
|
FitAndClearImage(milCameraDisplay);
|
|
|
|
if (!_CamDev.IsActivated) {
|
|
_Logger.FuncE("Camera Not Activated.");
|
|
return E1.GENERIC;
|
|
}
|
|
if (image == null) {
|
|
_Logger.FuncE("image buffer is null.");
|
|
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 || _CamConfig == null) {
|
|
_Logger.FuncE("_CamDev or _CamConfig is null.");
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
var milCameraDisplay = cameraDisplay as IMilCameraDisplay;
|
|
FitAndClearImage(milCameraDisplay);
|
|
|
|
if (!_CamDev.IsActivated) {
|
|
_Logger.FuncE("Camera Not Activated.");
|
|
return E1.GENERIC;
|
|
}
|
|
// Sequnece에서 GrabSync 호출 시 MILCameraAgent로 들어아서 image가 null이면 return하기때문에 아래 부분 주석처리
|
|
//if (image == null) {
|
|
// _Logger.FuncE("image buffer is null.");
|
|
// return E1.GENERIC;
|
|
//}
|
|
|
|
return _CamDev.GrabSync(milCameraDisplay, ref image);
|
|
}
|
|
|
|
private void FitAndClearImage(IMilCameraDisplay milCameraDisplay) {
|
|
if (milCameraDisplay == null) {
|
|
return;
|
|
}
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
milCameraDisplay.FitImage(_CamDev.GetImageSize());
|
|
milCameraDisplay.ClearMeasureGraphics();
|
|
}));
|
|
}
|
|
|
|
//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 milCameraDisplay = cameraDisplay as IMilCameraDisplay;
|
|
|
|
// 현재 Fov를 사용하는 디스플레이의 라이브 버튼만 켜기
|
|
CamLiveBtnManager.SetVisibilityAsLiveStart(milCameraDisplay.GetDisplayType(), _FovInfo);
|
|
|
|
FitAndClearImage(milCameraDisplay);
|
|
|
|
_Logger.I("Start Live.");
|
|
_CamDev.StartLive(milCameraDisplay);
|
|
}
|
|
|
|
/// <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 int GetExposure() {
|
|
return _CamDev.GetExposure();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카메라 노출시간 쓰기
|
|
/// </summary>
|
|
/// <param name="exposureTime_ms">노출시간[ms]</param>
|
|
/// <returns>성공 유무</returns>
|
|
public override int SetExposure(int 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
|
|
|
|
#region For Custumizing (장비 전용 API)
|
|
public override int GetInitialExposure() {
|
|
return _CamDev.GetInitialExposure();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|