116 lines
5.0 KiB
C#
116 lines
5.0 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using MilCommon;
|
|
using VisionCommon;
|
|
using Hermes;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace MilPattern {
|
|
/// <summary>
|
|
/// String & OCR Reader 모듈
|
|
/// </summary>
|
|
internal static class MilOcr {
|
|
private static Logger _logger = new Logger(typeof(MilOcr).Name);
|
|
|
|
public static OcrRunParam GetRunParam(MIL_ID contextId_Str, MIL_ID contextId_Ocr) {
|
|
var runParam = new OcrRunParam();
|
|
|
|
try {
|
|
// RunParam은 *.msr 혹은 *.mfo 파일에서 관리하기로 한다.
|
|
|
|
// String Read
|
|
//double threshold = 0;
|
|
//MIL.MstrInquire(contextId_Str, MIL.M_DEFAULT, MIL.M_THRESHOLD_VALUE + MIL.M_AUTO_COMPUTE, ref threshold);
|
|
//runParam.OcrParamExt.StrReadParamExt.Threshold = (int)threshold;
|
|
//runParam.OcrParamExt.StrReadParamExt.Speed = (eMilSpeed)Convert.ToInt32(MIL.MstrInquire(contextId_Str, MIL.M_DEFAULT, MIL.M_SPEED + MIL.M_DEFAULT, MIL.M_NULL));
|
|
|
|
// OCR Read
|
|
//MIL.MocrInquire(contextId_Ocr, MIL.M_THRESHOLD + MIL.M_AUTO, ref threshold);
|
|
//runParam.OcrParamExt.OcrReadParamExt.Threshold = (int)threshold;
|
|
//runParam.OcrParamExt.OcrReadParamExt.Speed = (eMilSpeed)Convert.ToInt32(MIL.MocrInquire(contextId_Ocr, MIL.M_SPEED, MIL.M_NULL));
|
|
}
|
|
catch (Exception e) {
|
|
_logger.FuncE(e.Message);
|
|
}
|
|
|
|
return runParam;
|
|
}
|
|
|
|
public static int SetRunParam(MIL_ID contextId, IRunParam runParam) {
|
|
if (runParam is OcrRunParam) {
|
|
// RunParam은 *.msr 혹은 *.mfo 파일에서 관리하기로 한다.
|
|
|
|
//var param = runParam as OcrRunParam;
|
|
|
|
//MIL.MstrControl(contextId, MIL.M_DEFAULT, MIL.M_SPEED, (double)param.OcrParamExt.StrReadParamExt.Speed);
|
|
//if (param.OcrParamExt.StrReadParamExt.AutoThreshold) {
|
|
// MIL.MstrControl(contextId, MIL.M_DEFAULT, MIL.M_THRESHOLD_VALUE, MIL.M_AUTO_COMPUTE);
|
|
//}
|
|
//else {
|
|
// MIL.MstrControl(contextId, MIL.M_DEFAULT, MIL.M_THRESHOLD_VALUE, (double)param.OcrParamExt.StrReadParamExt.Threshold);
|
|
//}
|
|
|
|
//MIL.MocrControl(contextId, MIL.M_SPEED, (double)param.OcrParamExt.OcrReadParamExt.Speed);
|
|
//if (param.OcrParamExt.OcrReadParamExt.AutoThreshold) {
|
|
// MIL.MocrControl(contextId, MIL.M_THRESHOLD, MIL.M_AUTO);
|
|
//}
|
|
//else {
|
|
// MIL.MocrControl(contextId, MIL.M_THRESHOLD, param.OcrParamExt.OcrReadParamExt.Threshold);
|
|
//}
|
|
|
|
return E1.OK;
|
|
}
|
|
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
public static PatternResult GetNotFoundPatternResult() {
|
|
return new PatternResult() {
|
|
Status = eFoundStatus.NotFound,
|
|
Results = new List<OcrResult>()
|
|
};
|
|
}
|
|
|
|
public static void Draw(PatternResult patternResult, IMilCameraDisplay milCameraDisplay) {
|
|
MIL_ID staticGraphicList = 0;
|
|
MIL.MdispInquire(milCameraDisplay.GetMilDisplayId(), MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, ref staticGraphicList);
|
|
|
|
if (patternResult.Status == eFoundStatus.FoundOK) {
|
|
var results = patternResult.Results as List<OcrResult>;
|
|
var crosses = new List<Cross>();
|
|
|
|
foreach (var result in results) {
|
|
if (result.ImagePosition.X == 0 && result.ImagePosition.Y == 0) {
|
|
continue;
|
|
}
|
|
|
|
var color = GraphicColors.PatternFoundOK;
|
|
var cross = new Cross(result.ImagePosition.Clone() as ImagePoint, 50);
|
|
crosses.Add(cross);
|
|
|
|
milCameraDisplay.SetPatternTracking(cross);
|
|
milCameraDisplay.AddCross(cross, color);
|
|
|
|
var msgs = new List<string>();
|
|
msgs.Add(string.Format("OcrType : {0}", result.OcrType));
|
|
msgs.Add(string.Format("X : {0:0.00}", result.ImagePosition.X));
|
|
msgs.Add(string.Format("Y : {0:0.00}", result.ImagePosition.Y));
|
|
msgs.Add(string.Format("Angle : {0:0.00}", result.Angle.Degree));
|
|
msgs.Add(string.Format("Score : {0:0.00}", result.Score));
|
|
msgs.Add(string.Format("TactTime : {0} ms", Math.Round(patternResult.TactTimeInMilliSec)));
|
|
msgs.Add(string.Format("Text : {0}", result.Text));
|
|
milCameraDisplay.AddTextList(
|
|
GraphicColors.PatternFoundOK, new ImagePoint(result.ImagePosition.X, result.ImagePosition.Y), msgs);
|
|
}
|
|
milCameraDisplay.DrawPatternTrackings(crosses);
|
|
}
|
|
}
|
|
}
|
|
}
|