//
// File generated by HDevelop for HALCON/.NET (C#) Version 21.05.0.0
// Non-ASCII strings in this file are encoded in local-8-bit encoding (cp936).
// 
// Please note that non-ASCII characters in string constants are exported
// as octal codes in order to guarantee that the strings are correctly
// created on all systems, independent on any compiler settings.
// 
// Source files with different encoding should not be mixed in one project.
//

using HalconDotNet;

public partial class HDevelopExport
{
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
  public HDevelopExport()
  {
    // Default settings used in HDevelop
    HOperatorSet.SetSystem("width", 512);
    HOperatorSet.SetSystem("height", 512);
    if (HalconAPI.isWindows)
      HOperatorSet.SetSystem("use_window_thread","true");
    action();
  }
#endif

  // Procedures 
#if !NO_EXPORT_MAIN
  // Main procedure 
  private void action()
  {


    // Local iconic variables 

    HObject ho_Image, ho_GrayImage, ho_Circle;
    HObject ho_ImageReduced;

    // Local control variables 

    HTuple hv_WindowHandle = new HTuple(), hv_Row = new HTuple();
    HTuple hv_Column = new HTuple(), hv_Radius = new HTuple();
    HTuple hv_ModelID = new HTuple(), hv_Row1 = new HTuple();
    HTuple hv_Column1 = new HTuple(), hv_Angle = new HTuple();
    HTuple hv_Scale = new HTuple(), hv_Score = new HTuple();
    // Initialize local and output iconic variables 
    HOperatorSet.GenEmptyObj(out ho_Image);
    HOperatorSet.GenEmptyObj(out ho_GrayImage);
    HOperatorSet.GenEmptyObj(out ho_Circle);
    HOperatorSet.GenEmptyObj(out ho_ImageReduced);
    try
    {
      HOperatorSet.SetWindowAttr("background_color","black");
      HOperatorSet.OpenWindow(0,0,512,512,0,"visible","",out hv_WindowHandle);
      HDevWindowStack.Push(hv_WindowHandle);
      ho_Image.Dispose();
      HOperatorSet.ReadImage(out ho_Image, "D:/小鹿.jpg");

      ho_GrayImage.Dispose();
      HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
      hv_Row.Dispose();hv_Column.Dispose();hv_Radius.Dispose();
      HOperatorSet.DrawCircle(hv_WindowHandle, out hv_Row, out hv_Column, out hv_Radius);
      ho_Circle.Dispose();
      HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius);

      ho_ImageReduced.Dispose();
      HOperatorSet.ReduceDomain(ho_GrayImage, ho_Circle, out ho_ImageReduced);

      hv_ModelID.Dispose();
      HOperatorSet.CreateScaledShapeModel(ho_ImageReduced, "auto", -0.39, 0.79, "auto", 
          0.9, 1.1, "auto", "auto", "use_polarity", "auto", "auto", out hv_ModelID);


      HOperatorSet.WriteShapeModel(hv_ModelID, "./匹配模板.shm");

      hv_Row1.Dispose();hv_Column1.Dispose();hv_Angle.Dispose();hv_Scale.Dispose();hv_Score.Dispose();
      HOperatorSet.FindScaledShapeModel(ho_GrayImage, hv_ModelID, -0.39, 0.78, 0.9, 
          1.1, 0.5, 1, 0.5, "least_squares", 0, 0.9, out hv_Row1, out hv_Column1, 
          out hv_Angle, out hv_Scale, out hv_Score);

      dev_display_shape_matching_results(hv_ModelID, "red", hv_Row1, hv_Column1, 
          hv_Angle, 1, 1, 0);


      using (HDevDisposeHelper dh = new HDevDisposeHelper())
      {
      disp_message(hv_WindowHandle, (((("结果坐标:"+hv_Row1)+new HTuple(","))+hv_Column1)+new HTuple(","))+hv_Column1, 
          "window", hv_Row1, hv_Column1, "black", "true");
      }

    }
    catch (HalconException HDevExpDefaultException)
    {
      ho_Image.Dispose();
      ho_GrayImage.Dispose();
      ho_Circle.Dispose();
      ho_ImageReduced.Dispose();

      hv_WindowHandle.Dispose();
      hv_Row.Dispose();
      hv_Column.Dispose();
      hv_Radius.Dispose();
      hv_ModelID.Dispose();
      hv_Row1.Dispose();
      hv_Column1.Dispose();
      hv_Angle.Dispose();
      hv_Scale.Dispose();
      hv_Score.Dispose();

      throw HDevExpDefaultException;
    }
    ho_Image.Dispose();
    ho_GrayImage.Dispose();
    ho_Circle.Dispose();
    ho_ImageReduced.Dispose();

    hv_WindowHandle.Dispose();
    hv_Row.Dispose();
    hv_Column.Dispose();
    hv_Radius.Dispose();
    hv_ModelID.Dispose();
    hv_Row1.Dispose();
    hv_Column1.Dispose();
    hv_Angle.Dispose();
    hv_Scale.Dispose();
    hv_Score.Dispose();

  }

#endif


}
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public class HDevelopExportApp
{
  static void Main(string[] args)
  {
    new HDevelopExport();
  }
}
#endif

