48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using Cognex.VisionPro;
|
|
using Cognex.VisionPro.PixelMap;
|
|
using System;
|
|
using VisionCommon;
|
|
|
|
namespace CogPattern {
|
|
public class CogBinarization {
|
|
private static Logger _Logger = new Logger(typeof(CogBinarization).Name);
|
|
|
|
public static void Binarize(
|
|
ICogImage srcImage, ref ICogImage dstImage, double thresholdLow, double thresholdHigh, eForegroundColor foregroundColor) {
|
|
|
|
try {
|
|
var pixelMapTool = new CogPixelMapTool();
|
|
|
|
pixelMapTool.RunParams.AutoComputeEnabled = false;
|
|
pixelMapTool.RunParams.ClearReferencePoints();
|
|
pixelMapTool.RunParams.SetInputDepth(srcImage);
|
|
pixelMapTool.RunParams.AddReferencePointAbsolute(0, 0);
|
|
pixelMapTool.RunParams.AddReferencePointAbsolute((int)thresholdLow - 1, 0);
|
|
pixelMapTool.RunParams.AddReferencePointAbsolute((int)thresholdLow, 255);
|
|
pixelMapTool.RunParams.AddReferencePointAbsolute((int)thresholdHigh - 1, 255);
|
|
pixelMapTool.RunParams.AddReferencePointAbsolute((int)thresholdHigh, 0);
|
|
|
|
if (foregroundColor == eForegroundColor.White) {
|
|
pixelMapTool.RunParams.OutputInverted = false;
|
|
}
|
|
else {
|
|
pixelMapTool.RunParams.OutputInverted = true;
|
|
}
|
|
|
|
//pixelMapTool.Region = roi;
|
|
pixelMapTool.InputImage = srcImage;
|
|
pixelMapTool.Run();
|
|
dstImage = pixelMapTool.OutputImage;
|
|
pixelMapTool.Dispose();
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
}
|
|
} |