using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
using OpenCvSharp;

namespace Hawkeye.VisionBuilder.Workflow.Operations.Edge;

[Category("Edge")]
public class SobelOperation:BaseOperation
{
    protected override void InterpretInternal(Context context)
    {
        if(!CheckImageExists(context)) return;
        var sobelY = context.ActiveImage!.ImageData.Sobel(MatType.CV_16S, 0, 1);
        var sobelX = context.ActiveImage!.ImageData.Sobel(MatType.CV_16S, 1, 0);

        sobelX = sobelX.ConvertScaleAbs() * 0.5;
        sobelY = sobelY.ConvertScaleAbs() * 0.5;

        sobelX += sobelY;

        context.ActiveImage = new HawkeyeImage()
        {
            ImageData = sobelX
        };
        Status = "Sobel";
        Result = true;
    }
}