217 lines
7.1 KiB
C#
217 lines
7.1 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using CogCommon;
|
|
using VisionCommon;
|
|
using Hermes;
|
|
using Cognex.VisionPro;
|
|
using System;
|
|
using System.IO;
|
|
using System.Drawing;
|
|
using VisionCommonUI;
|
|
|
|
namespace CogPattern {
|
|
/// <summary>
|
|
/// 밝기 설정 클래스
|
|
/// </summary>
|
|
public class Brightness : PatternBase, IPatternFinder, IDisposable {
|
|
/// <inheritdoc/>
|
|
public string FILE_EXT_PATTERN { get; set; } // 불필요
|
|
private BrightnessParamExt _paramExt = null;
|
|
|
|
private readonly Logger _logger;
|
|
private readonly PatternInfo _patternInfo;
|
|
/// <summary>
|
|
/// 밝기 설정 클래스 생성자
|
|
/// </summary>
|
|
/// <param name="patternInfo">패턴 정보</param>
|
|
public Brightness(PatternInfo patternInfo) {
|
|
_patternInfo = patternInfo;
|
|
_logger = new Logger(
|
|
$"Brightness_{patternInfo.GetPatternIndex()}");
|
|
InitContext();
|
|
}
|
|
|
|
private void InitContext() {
|
|
if (E1.OK != Load()) {
|
|
Create();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 패턴 파일 경로
|
|
/// </summary>
|
|
/// <returns>문자열</returns>
|
|
public string GetPatternFilePath(string patternName = PatternConstants.FILE_NAME_PATTERN) {
|
|
return Path.Combine(new string[] {
|
|
PatternConstants.GetSubPatternDirPath(_patternInfo),
|
|
patternName + FILE_EXT_PATTERN
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 밝기 정보 파일 불러오기
|
|
/// </summary>
|
|
/// <returns>성공 유무</returns>
|
|
public int Load() {
|
|
var patternFilePath = GetPatternFilePath();
|
|
|
|
if (!File.Exists(patternFilePath)) {
|
|
_logger.I($"Pattern File does NOT exist : {patternFilePath}");
|
|
return E2.NOT_FOUND;
|
|
}
|
|
|
|
_paramExt = LoadParamExt();
|
|
|
|
return E1.OK;
|
|
}
|
|
/// <summary>
|
|
/// 밝기 정보 파일 저장
|
|
/// </summary>
|
|
/// <returns>성공 유무</returns>
|
|
public int Save() {
|
|
var patternFilePath = GetPatternFilePath();
|
|
var patternDirPath = Path.GetDirectoryName(patternFilePath);
|
|
if (!Directory.Exists(patternDirPath)) {
|
|
Directory.CreateDirectory(patternDirPath);
|
|
}
|
|
|
|
return SaveParamExt(_paramExt);
|
|
}
|
|
/// <summary>
|
|
/// 밝기 정보 생성
|
|
/// </summary>
|
|
/// <returns>성공 유무</returns>
|
|
public int Create() {
|
|
_paramExt = LoadParamExt();
|
|
return E1.OK;
|
|
}
|
|
/// <summary>
|
|
/// 밝기 정보 파일 제거
|
|
/// </summary>
|
|
/// <returns>성공 유무</returns>
|
|
public int Remove() {
|
|
var patternFilePath = GetPatternFilePath();
|
|
var patternDirPath = Path.GetDirectoryName(patternFilePath);
|
|
if (Directory.Exists(patternDirPath)) {
|
|
Directory.Delete(patternDirPath, recursive: true);
|
|
}
|
|
|
|
return E1.OK;
|
|
}
|
|
/// <summary>
|
|
/// ROI영역 가져오기
|
|
/// </summary>
|
|
/// <returns>ROI Class</returns>
|
|
public ROI GetFindROI() {
|
|
return _paramExt.FindROI.Clone() as ROI;
|
|
}
|
|
/// <summary>
|
|
/// ROI영역 설정
|
|
/// </summary>
|
|
/// <param name="findRoi">ROI영역</param>
|
|
/// <returns>성공 유무</returns>
|
|
public int SetFindROI(ROI findRoi) {
|
|
if (ROI.IsNullOrEmpty(findRoi)) {
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
_paramExt.FindROI = findRoi.Clone() as ROI;
|
|
|
|
return E1.OK;
|
|
}
|
|
/// <summary>
|
|
/// 밝기 설정 파라미터 가져오기
|
|
/// </summary>
|
|
/// <returns>IRunParam</returns>
|
|
public IRunParam GetRunParam() {
|
|
return new BrightnessRunParam() {
|
|
BrightnessParamExt = _paramExt.Clone() as BrightnessParamExt
|
|
};
|
|
}
|
|
/// <summary>
|
|
/// 밝기 설정 파라미터 설정하기
|
|
/// </summary>
|
|
/// <returns>성공 유무</returns>
|
|
public int SetRunParam(IRunParam runParam) {
|
|
_paramExt = ((BrightnessRunParam)runParam).BrightnessParamExt.Clone() as BrightnessParamExt;
|
|
return E1.OK;
|
|
}
|
|
/// <summary>
|
|
/// 설정된 밝기로 패턴 찾기
|
|
/// </summary>
|
|
/// <param name="image">이미지</param>
|
|
/// <returns>패턴 결과</returns>
|
|
public PatternResult Find(object image) {
|
|
return CogBrightness.Find((ICogImage)image, _paramExt.FindROI.Clone() as ROI, _paramExt);
|
|
}
|
|
/// <summary>
|
|
/// 설정된 밝기로 패턴 찾기
|
|
/// </summary>
|
|
/// <param name="image">이미지</param>
|
|
/// <param name="findRoi">ROI</param>
|
|
/// <returns>패턴 결과</returns>
|
|
public PatternResult Find(object image, ROI findRoi) {
|
|
return CogBrightness.Find((ICogImage)image, findRoi, _paramExt);
|
|
}
|
|
/// <summary>
|
|
/// 찾지 못한 결과 가져오기
|
|
/// </summary>
|
|
/// <returns>패턴 결과</returns>
|
|
public PatternResult GetNotFoundPatternResult() {
|
|
return CogBrightness.GetNotFoundPatternResult();
|
|
}
|
|
/// <summary>
|
|
/// GetTool
|
|
/// </summary>
|
|
public object GetTool() {
|
|
throw new NotImplementedException();
|
|
}
|
|
/// <summary>
|
|
/// 결과 그리기
|
|
/// </summary>
|
|
/// <param name="patternResult">결과정보</param>
|
|
/// <param name="cameraDisplay">결과표시될 Display</param>
|
|
/// <param name="isFixturePattern">픽스쳐 여부</param>
|
|
public void Draw(
|
|
PatternResult patternResult, ICameraDisplay cameraDisplay, bool isFixturePattern = false) {
|
|
CogBrightness.Draw(patternResult, cameraDisplay as ICogCameraDisplay);
|
|
}
|
|
/// <summary>
|
|
/// 밝기 설정 아이콘 가져오기
|
|
/// </summary>
|
|
/// <returns>비트맵</returns>
|
|
public Bitmap GetThumbnail() {
|
|
return ThumbnailImage.Brightness();
|
|
}
|
|
|
|
#region IDisposible
|
|
/// <summary>
|
|
/// 자원 회수
|
|
/// </summary>
|
|
public void Dispose() {
|
|
}
|
|
#endregion
|
|
|
|
#region Brightness Specific
|
|
/// <summary>
|
|
/// 확장 파라미터 불러오기
|
|
/// </summary>
|
|
/// <returns>BrightnessParamExt</returns>
|
|
public BrightnessParamExt LoadParamExt() {
|
|
return BrightnessParamExt.Load(PatternConstants.GetSubPatternDirPath(_patternInfo));
|
|
}
|
|
/// <summary>
|
|
/// 확장 파라미터 저장하기
|
|
/// </summary>
|
|
/// <returns>성공 유무</returns>
|
|
public int SaveParamExt(BrightnessParamExt brightnessParamExt) {
|
|
return BrightnessParamExt.Save(
|
|
PatternConstants.GetSubPatternDirPath(_patternInfo),
|
|
brightnessParamExt);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|