67 lines
2.5 KiB
C#
67 lines
2.5 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;
|
|
using Aurora.Api.Devices;
|
|
using VisionAI;
|
|
|
|
namespace MilPattern {
|
|
/// <summary>
|
|
/// Tesseract AI OCR ¸ðµâ
|
|
/// </summary>
|
|
internal static class TesseractRead {
|
|
private static Logger _logger = new Logger(typeof(TesseractRead).Name);
|
|
|
|
private static TesseractAgent _TesseractAgent;
|
|
|
|
public static void SetRunParam(OcrParamExt paramExt) {
|
|
if (_TesseractAgent == null) {
|
|
_TesseractAgent = new TesseractAgent();
|
|
}
|
|
_TesseractAgent.SetRunParam(paramExt.CustomTextLength, paramExt.TesseractParamExt.WhiteList, paramExt.TesseractParamExt.BlackList);
|
|
}
|
|
|
|
public static PatternResult Find(MIL_ID image, OcrParamExt paramExt) {
|
|
var bitmap = MilEnvironment.ConvertToBitmap(image);
|
|
//bitmap.Save(Path.Combine(@"D:\\01_Projects\\250417\\AuroraVision\\AuroraVision\\VisionAI", "bitmapTest.png")); // µð¹ö±ë¿ë
|
|
|
|
TsOcrOutputParam outputParam = _TesseractAgent.ReadOCR(bitmap, paramExt.FindROI.Angle.Degree, paramExt.NoLengthLimit);
|
|
|
|
var finderResult = ExtractResults(outputParam, MilEnvironment.GetImageCenter(image), paramExt);
|
|
finderResult.TactTimeInMilliSec = outputParam.TactTime_Ms;
|
|
|
|
return finderResult;
|
|
}
|
|
|
|
private static PatternResult ExtractResults(TsOcrOutputParam outputParam, ImagePoint imageCenter, OcrParamExt paramExt) {
|
|
var results = new List<OcrResult>();
|
|
|
|
if (outputParam.Status == eInspStatus.OK) {
|
|
results.Add(new OcrResult(
|
|
ocrType: eOcrType.Tesseract,
|
|
position: new ImagePoint(paramExt.FindROI.Width / 2, paramExt.FindROI.Height / 2),
|
|
offset: new ImagePoint(),
|
|
angle: paramExt.FindROI.Angle.Clone() as Angle,
|
|
score: outputParam.Score,
|
|
text: outputParam.Text,
|
|
findRoi: paramExt.FindROI.Clone() as ROI,
|
|
eFoundStatus.FoundOK));
|
|
}
|
|
|
|
return new PatternResult() {
|
|
MoreInfo = eOcrType.Tesseract,
|
|
Status = (results.Count > 0) ? eFoundStatus.FoundOK : eFoundStatus.NotFound,
|
|
Results = results
|
|
};
|
|
}
|
|
}
|
|
}
|