基于halcon的黑白面积算法

//
// File generated by HDevelop for HALCON/.NET (C#) Version 23.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;
using System.Windows.Forms;

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

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


    // Local iconic variables 

    HObject ho_Msg1, ho_Circle, ho_c2, ho_ContCircle;

    // Local control variables 

    HTuple hv_Width = new HTuple(), hv_Height = new HTuple();
    HTuple hv_WindowHandle = new HTuple(), hv_Row = new HTuple();
    HTuple hv_Column = new HTuple(), hv_Radius = new HTuple();
    HTuple hv_AbsHisto3 = new HTuple(), hv_RelHisto3 = new HTuple();
    HTuple hv_HistoBorder = new HTuple(), hv_Min = new HTuple();
    HTuple hv_Max = new HTuple(), hv_Range = new HTuple();
    HTuple hv_Histo = new HTuple(), hv_BinSize = new HTuple();
    HTuple hv_Mean = new HTuple(), hv_Deviation = new HTuple();
    // Initialize local and output iconic variables 
    HOperatorSet.GenEmptyObj(out ho_Msg1);
    HOperatorSet.GenEmptyObj(out ho_Circle);
    HOperatorSet.GenEmptyObj(out ho_c2);
    HOperatorSet.GenEmptyObj(out ho_ContCircle);
    //read_image (Msg1, 'C:/Users/lenovo/Desktop/ͼƬ/msg1.bmp')
    ho_Msg1.Dispose();
    HOperatorSet.ReadImage(out ho_Msg1, "C:/Users/lenovo/Desktop/chilun.bmp");

    HOperatorSet.GetImageSize(ho_Msg1, out hv_Width, out hv_Height);
    HOperatorSet.SetWindowAttr("background_color","black");
    HOperatorSet.OpenWindow(0,0,1024,1224,0,"visible","",out hv_WindowHandle);
    HDevWindowStack.Push(hv_WindowHandle);
    if (HDevWindowStack.IsOpen())
    {
      HOperatorSet.DispObj(ho_Msg1, HDevWindowStack.GetActive());
    }
    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_c2.Dispose();
    HOperatorSet.GenCircle(out ho_c2, 1043.6, 1198.4, 182.312);
    //disp_cross (WindowHandle, 112, 112, 38, 30)
    ho_ContCircle.Dispose();
    HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row, hv_Column, hv_Radius, 
        0, 6.28318, "positive", 1);
    //draw_region (Region, WindowHandle)
    //gen_region_contour_xld (ContCircle, Region1, 'filled')
    
    //read_image (Image, 'fabrik')
    //get_image_size (Image, Width, Height)
    
	//开发者QQ 1960697656
    //Calculate the gray value distribution of the image
    hv_HistoBorder = 0.2;
    HOperatorSet.MinMaxGray(ho_Circle, ho_Msg1, 0, out hv_Min, out hv_Max, out hv_Range);
    using (HDevDisposeHelper dh = new HDevDisposeHelper())
    {
    HOperatorSet.GrayHistoRange(ho_Circle, ho_Msg1, hv_Min, hv_Max, (((hv_Max-hv_Min)+1)).TupleInt()
        , out hv_Histo, out hv_BinSize);
    }
    HOperatorSet.TupleMean(hv_Histo, out hv_Mean);
    HOperatorSet.TupleDeviation(hv_Histo, out hv_Deviation);
    //mean_matrix (Histo, 'columns', MatrixMeanID)
    //myMean := Histo.mean
    //mean:=Histo.mean
    ho_Msg1.Dispose();
    ho_Circle.Dispose();
    ho_c2.Dispose();
    ho_ContCircle.Dispose();

    

  }
    private void action2()
    {


        // Local iconic variables 

        HObject ho_Msg1, ho_Circle, ho_c2, ho_ContCircle;

        // Local control variables 

        HTuple hv_Width = null, hv_Height = null, hv_WindowHandle = null;
        HTuple hv_Row = null, hv_Column = null, hv_Radius = null;
        HTuple hv_AbsHisto3 = null, hv_RelHisto3 = null, hv_HistoBorder = null;
        HTuple hv_Min = null, hv_Max = null, hv_Range = null, hv_Histo = null;
        HTuple hv_BinSize = null, hv_Mean = null, hv_Deviation = null;
        // Initialize local and output iconic variables 
        HOperatorSet.GenEmptyObj(out ho_Msg1);
        HOperatorSet.GenEmptyObj(out ho_Circle);
        HOperatorSet.GenEmptyObj(out ho_c2);
        HOperatorSet.GenEmptyObj(out ho_ContCircle);
        //read_image (Msg1, 'C:/Users/lenovo/Desktop/ͼƬ/msg1.bmp')
        ho_Msg1.Dispose();
        HOperatorSet.ReadImage(out ho_Msg1, "C:/Users/lenovo/Desktop/chilun.bmp");

        HOperatorSet.GetImageSize(ho_Msg1, out hv_Width, out hv_Height);
        HOperatorSet.SetWindowAttr("background_color", "black");

        hv_WindowHandle = UsedFace.HWCtrl.HalconWindow;
        HOperatorSet.SetDraw(hv_WindowHandle, "margin");
        HOperatorSet.SetColor(hv_WindowHandle, "red");

        //HOperatorSet.OpenWindow(0, 0, 1024, 1224, 0, "", "", out hv_WindowHandle);
        //HDevWindowStack.Push(hv_WindowHandle);
        //if (HDevWindowStack.IsOpen())
        //{
        //    HOperatorSet.DispObj(ho_Msg1, HDevWindowStack.GetActive());
        //}
        HOperatorSet.GetImageSize(ho_Msg1, out hv_Width, out hv_Height);
        //HOperatorSet.Rgb1ToGray(ho_Msg1, out ho_GrayImage);
        HOperatorSet.SetPart(UsedFace.HWCtrl.HalconWindow, 0, 0, hv_Height, hv_Width);
        HOperatorSet.DispObj(ho_Msg1,UsedFace.HWCtrl.HalconWindow);

        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_c2.Dispose();
        HOperatorSet.GenCircle(out ho_c2, 1043.6, 1198.4, 182.312);
        //disp_cross (WindowHandle, 112, 112, 38, 30)
        ho_ContCircle.Dispose();
        HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row, hv_Column, hv_Radius,
            0, 6.28318, "positive", 1);
        //draw_region (Region, WindowHandle)
        //gen_region_contour_xld (ContCircle, Region1, 'filled')
        //read_image (Image, 'fabrik')
    	//get_image_size (Image, Width, Height)
    
		//开发者邮箱 1960697656@qq.com
    	//Calculate the gray value distribution of the image
        hv_HistoBorder = 0.2;
        HOperatorSet.MinMaxGray(ho_Circle, ho_Msg1, 0, out hv_Min, out hv_Max, out hv_Range);
        HOperatorSet.GrayHistoRange(ho_Circle, ho_Msg1, hv_Min, hv_Max, (((hv_Max - hv_Min) + 1)).TupleInt()
            , out hv_Histo, out hv_BinSize);
        HOperatorSet.TupleMean(hv_Histo, out hv_Mean);
        HOperatorSet.TupleDeviation(hv_Histo, out hv_Deviation);
        //mean_matrix (Histo, 'columns', MatrixMeanID)
        //myMean:=Histo.mean
        //mean:=Histo.mean
        ho_Msg1.Dispose();
        ho_Circle.Dispose();
        ho_c2.Dispose();
        ho_ContCircle.Dispose();
        //HMisc
        //HOperatorSet
        string msg = string.Format("最小值为:{0}最大值为:{1}平均值为:{2}方差为:{3}", new object[] {hv_Min, hv_Max, hv_Mean,hv_Mean,hv_Deviation });
        MessageBox.Show(msg);
    }
#endif


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


  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值