Пример #1
0
    // Main procedure
    public void action_load(HWindowControl hWindowControl1, string ImagePath)
    {
        HObject        ho_Image;
        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        HTuple         hv_Width = null, hv_Height = null, hv_WindowHandle = null;

        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
        }
        HOperatorSet.GenEmptyObj(out ho_Image);
        // ho_Image.Dispose();
        //DisposeAllObj();
        initaVariables();
        //对话框设置
        //        string ImagePath;
        //        openFileDialog1.Filter = "JPEG文件|*.jpg|BMP文件|*.bmp|png文件|*.png";
        //        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        //        {
        //将打开的文件名赋给ImagePath字符串变量
        //            ImagePath = openFileDialog1.FileName;
        HOperatorSet.ReadImage(out ho_Image, ImagePath);
//        }
        //打开窗口,将显示图片控件的句柄赋给窗口句柄,使窗口在控件中打开,并设置窗口宽高为显示图片控件的宽高
        HOperatorSet.OpenWindow(0, 0, hWindowControl1.Width, hWindowControl1.Height, hWindowControl1.HalconWindow, "", "", out hv_WindowHandle);
        //HDevWindowStack.Push(hv_WindowHandle);

        //if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.DispObj(ho_Image, hv_WindowHandle);// HDevWindowStack.GetActive());
        }
        ho_Image.Dispose();
        hWindowControl1.Invalidate();
        hWindowControl1.Refresh();
        hWindowControl1.Update();
    }
Пример #2
0
 /// <summary>
 /// Triggers a repaint of the HALCON window
 /// </summary>
 public void repaint()
 {
     repaint(viewPort.HalconWindow);
     viewPort.Refresh();
 }
Пример #3
0
    public void action(HWindowControl hWindowControl1, String FilePath, String filename, String index)
    {
        initaVariables();
        try
        {
            //This program demonstrates how to detect small texture
            //defects on the surface of plastic items by using the fast
            //fourier transform (FFT).
            //First, we construct a suitable filter using Gaussian
            //filters. Then, the images and the filter are convolved
            //by using fast fourier transforms. Finally, the defects
            //are detected in the filtered images by using
            //morphology operators.
            //
            //Initializations
            dev_update_off();

            /*if (HDevWindowStack.IsOpen())
             * {
             *  HOperatorSet.CloseWindow(HDevWindowStack.Pop());
             * }  LEI */

            //read image from file
            ho_Image.Dispose();

            //1.read image
            HOperatorSet.ReadImage(out ho_Image, FilePath + index);// "metal/tube_01");

//            ho_ROI_0.Dispose();
//           HOperatorSet.GenRectangle1(out ho_ROI_0, 3.33632, 300.556, 990.549, 1648.14);
            ho_ROI_0.Dispose();
            HOperatorSet.GetImageSize(ho_Image, out hov_Width, out hov_Height);
            HOperatorSet.GenRectangle1(out ho_ROI_0, 0, 0, 1200, 4096);//metal
            //HOperatorSet.GenRectangle1(out ho_ROI_0, 0, 620.059, 1998.27, 3603.45);//tube的
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
            //get_domain (ImageReduced, Domain)
            ho_ImagePart.Dispose();
            HOperatorSet.CropDomain(ho_ImageReduced, out ho_ImagePart);

            HOperatorSet.GetImageSize(ho_ImagePart, out hv_Width, out hv_Height);
            HOperatorSet.SetWindowAttr("background_color", "black");
            //HOperatorSet.OpenWindow(0, 0, hv_Width, hv_Height, 0, "visible", "", out hv_WindowHandle);
            //HDevWindowStack.Push(hv_WindowHandle);

            HOperatorSet.OpenWindow(0, 0, hWindowControl1.Width, hWindowControl1.Height, hWindowControl1.HalconWindow, "", "", out hv_WindowHandle);
            HDevWindowStack.Push(hv_WindowHandle);

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_ImagePart, HDevWindowStack.GetActive());
            }
            ho_ImagePart.Dispose();
            hWindowControl1.Refresh();

            set_display_font(hv_WindowHandle, 14, "mono", "true", "false");
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 3);
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
            }
            //
            //Optimize the fft speed for the specific image size
            HOperatorSet.OptimizeRftSpeed(hv_Width, hv_Height, "standard");
            //
            //Construct a suitable filter by combining two gaussian
            //filters
            hv_Sigma1 = 10.0;
            hv_Sigma2 = 3.0;
            ho_GaussFilter1.Dispose();
            HOperatorSet.GenGaussFilter(out ho_GaussFilter1, hv_Sigma1, hv_Sigma1, 0.0,
                                        "none", "rft", hv_Width, hv_Height);
            ho_GaussFilter2.Dispose();
            HOperatorSet.GenGaussFilter(out ho_GaussFilter2, hv_Sigma2, hv_Sigma2, 0.0,
                                        "none", "rft", hv_Width, hv_Height);
            ho_Filter.Dispose();
            HOperatorSet.SubImage(ho_GaussFilter1, ho_GaussFilter2, out ho_Filter, 1, 0);
            //
            //Process the images iteratively
            hv_NumImages = 5;
            HTuple end_val34  = hv_NumImages;
            HTuple step_val34 = 1;
            //for (hv_Index = 1; hv_Index.Continue(end_val34, step_val34); hv_Index = hv_Index.TupleAdd(step_val34))
            //{
            HandleOneImage(FilePath, index);
            //}
        }
        catch (HalconException HDevExpDefaultException)
        {
            System.Diagnostics.Debug.WriteLine(HDevExpDefaultException.GetErrorMessage());
            Console.WriteLine(HDevExpDefaultException.StackTrace);
            //System.Diagnostics.Debug.Assert(false, HDevExpDefaultException.GetErrorMessage());
            DisposeAllObj();

            // throw HDevExpDefaultException;
        }

        DisposeAllObj();
    }