79 lines
3.2 KiB
C#
79 lines
3.2 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using System;
|
|
using MilCommon;
|
|
|
|
namespace MilCamera {
|
|
/// <summary>
|
|
/// 이미지 반전 및 회전을 위한 Tool
|
|
/// </summary>
|
|
public class MilImgFlipAndRotationTool : ImgToolBase {
|
|
private Logger _Logger;
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="camId">카메라 ID</param>
|
|
/// <param name="camConfig">카메라 컨피그</param>
|
|
public MilImgFlipAndRotationTool(eCamId camId, CamConfig camConfig) : base(camId, camConfig) {
|
|
_Logger = new Logger(string.Format("MilImgFlipAndRotationTool[{0}]", camId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 이미지 반전 및 회전
|
|
/// </summary>
|
|
/// <param name="srcImage">소스 이미지</param>
|
|
/// <param name="filteredImage">결과 이미지</param>
|
|
public void FlipAndRotation(MIL_ID srcImage, ref MIL_ID filteredImage) {
|
|
try {
|
|
if (IsFlipEnabled() && !IsRotationEnabled()) { // Flip
|
|
ApplyFlip(srcImage, ref filteredImage);
|
|
}
|
|
else if (!IsFlipEnabled() && IsRotationEnabled()) { // Rotation
|
|
ApplyRotation(srcImage, ref filteredImage);
|
|
}
|
|
else if (IsFlipEnabled() && IsRotationEnabled()) { // Flip & Rotation
|
|
ApplyFlip(srcImage, ref srcImage);
|
|
ApplyRotation(srcImage, ref filteredImage);
|
|
}
|
|
else { // None
|
|
MilEnvironment.CopyImage(srcImage, filteredImage);
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
private void ApplyFlip(MIL_ID image, ref MIL_ID flipedImage) {
|
|
try {
|
|
//TactTimeChecker.Start(TactTimeType.FlipImage, "ApplyFlip");
|
|
long operation = (CamConfig.FlipAndRotation.ImageFlip.Equals(eImageFlip.LeftToRight)) ? MIL.M_FLIP_HORIZONTAL : MIL.M_FLIP_VERTICAL;
|
|
MIL.MimFlip(image, flipedImage, operation, MIL.M_DEFAULT);
|
|
//TactTimeChecker.Stop(TactTimeType.FlipImage, "ApplyFlip");
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
private void ApplyRotation(MIL_ID image, ref MIL_ID rotatedImage) {
|
|
try {
|
|
//TactTimeChecker.Start(TactTimeType.RotateImage, "ApplyRotation");
|
|
int direction = -1; // 시계 방향 회전을 위해 -1을 곱한다.
|
|
double finalAngle = (double)CamConfig.FlipAndRotation.ImageRotation + CamConfig.FlipAndRotation.ImageRotationOffset;
|
|
MIL.MimRotate(image, rotatedImage, finalAngle * direction,
|
|
MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NEAREST_NEIGHBOR + MIL.M_OVERSCAN_CLEAR);
|
|
//TactTimeChecker.Stop(TactTimeType.RotateImage, "ApplyRotation");
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
}
|
|
} |