Exemple #1
0
 private void FrmCamera2Config_Load(object sender, EventArgs e)
 {
     // Initialize local and output iconic variables
     HOperatorSet.GenEmptyObj(out ho_Image);
     HOperatorSet.GenEmptyObj(out ho_ModelContour);
     HOperatorSet.GenEmptyObj(out ho_MeasureContour);
     HOperatorSet.GenEmptyObj(out ho_Contours);
     HOperatorSet.GenEmptyObj(out ho_ROI_0);
     HOperatorSet.GenEmptyObj(out ho_Image1);
     HOperatorSet.GenEmptyObj(out ho_ImageModel);
     HOperatorSet.GenEmptyObj(out ho_RegionDilation);
     HOperatorSet.GenEmptyObj(out ho_ImageReduced);
     HOperatorSet.GenEmptyObj(out ho_ModelContours);
     HOperatorSet.GenEmptyObj(out ho_ContoursAffineTrans);
     HOperatorSet.GenEmptyObj(out ho_ImageEmphasize);
     HOperatorSet.GenEmptyObj(out ho_Contour1);
     HOperatorSet.GenEmptyObj(out ho_UsedEdges);
     HOperatorSet.GenEmptyObj(out ho_Cross2);
     HOperatorSet.GenEmptyObj(out ho_ResultContours);
     seqGray.OnImageFileLoad     += SeqGray_OnImageFileLoad;
     propertyGrid1.SelectedObject = seqGray;
     c2s = Module.SerializableTool.FromByFile <Module.Camera2Serializable>("cam2.sol");
 }
Exemple #2
0
        private void Camera3()
        {
            c2s = Module.SerializableTool.FromByFile <Module.Camera2Serializable>("cam2.sol");
            //Image Acquisition 01: Code generated by Image Acquisition 01
            hv_ImageFiles = new HTuple();
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[0] = "G:/防火砖缺陷检测/Image_20201109161631787.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[1] = "G:/防火砖缺陷检测/Image_20201109161638427.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[2] = "G:/防火砖缺陷检测/Image_20201109161641675.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[3] = "G:/防火砖缺陷检测/Image_20201109161651523.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[4] = "G:/防火砖缺陷检测/Image_20201109161654667.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[5] = "G:/防火砖缺陷检测/Image_20201109161701411.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[6] = "G:/防火砖缺陷检测/Image_20201109161704812.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[7] = "G:/防火砖缺陷检测/Image_20201109161707571.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[8] = "G:/防火砖缺陷检测/Image_20201109161715763.bmp";
            if (hv_ImageFiles == null)
            {
                hv_ImageFiles = new HTuple();
            }
            hv_ImageFiles[9] = "G:/防火砖缺陷检测/Image_20201109161720699.bmp";

            for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_ImageFiles.TupleLength()
                                                                  )) - 1); hv_Index = (int)hv_Index + 1)
            {
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    ho_Image.Dispose();
                    HOperatorSet.ReadImage(out ho_Image, hv_ImageFiles.TupleSelect(hv_Index));
                    HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
                    HOperatorSet.SetPart(hWindow_Final1.hWindowControl.HalconWindow, 0, 0, hv_Height, hv_Width);
                }
                ho_ImageEmphasize.Dispose();

                HOperatorSet.Emphasize(ho_Image, out ho_ImageEmphasize, hv_Width, hv_Height,
                                       1);
                HOperatorSet.DispObj(ho_Image, hWindow_Final1.hWindowControl.HalconWindow);
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    HOperatorSet.FindScaledShapeModel(ho_Image, c2s.Modle, (new HTuple(0)).TupleRad()
                                                      , (new HTuple(360)).TupleRad(), 0.7, 1.3, 0.6, 0, 0.5, "none", 0, 0.3,
                                                      out hv_Row3, out hv_Column3, out hv_Angle3, out hv_Scale, out hv_Score);
                }
                HOperatorSet.TupleLength(hv_Score, out hv_Length);
                if ((int)(new HTuple(hv_Length.TupleEqual(0))) != 0)
                {
                    //disp_message(hWindow_Final1.hWindowControl.HalconWindow, "failed!!!!!!!!!!!!!!!", "window", 20,
                    //    20, "black", "true");
                    //disp_continue_message(hWindow_Final1.hWindowControl.HalconWindow, "black", "true");
                    ////wait_seconds (2)
                    //HDevelopStop();
                }
                else
                {
                    //hom_mat2d_identity (HomMat2DIdentity)
                    //hom_mat2d_translate (HomMat2DIdentity, Row, Column, HomMat2DTranslate)
                    //hom_mat2d_rotate (HomMat2DTranslate, Angle, Row, Column, HomMat2DRotate)
                    //hom_mat2d_scale (HomMat2DRotate, Scale, Scale, Row, Column, HomMat2DScale)
                    //affine_trans_contour_xld (ModelContours, ModelTrans, HomMat2DScale)
                    //dev_display (ModelTrans)
                    //下面开始测量尺寸

                    HOperatorSet.AlignMetrologyModel(c2s.MetrologyHandle, hv_Row3, hv_Column3,
                                                     hv_Angle3);

                    ho_ModelContour.Dispose();
                    HOperatorSet.GetMetrologyObjectModelContour(out ho_ModelContour, c2s.MetrologyHandle,
                                                                "all", 1.5);
                    //向图像应用测量模型
                    HOperatorSet.ApplyMetrologyModel(ho_Image, c2s.MetrologyHandle);
                    //获取测量卡尺
                    ho_Contour1.Dispose();
                    HOperatorSet.GetMetrologyObjectMeasures(out ho_Contour1, c2s.MetrologyHandle,
                                                            "all", "all", out hv_Row, out hv_Column);
                    HOperatorSet.TupleLength(hv_Score, out hv_Length);
                    if ((int)(new HTuple(hv_Length.TupleEqual(0))) != 0)
                    {
                    }
                    HOperatorSet.GetMetrologyObjectResult(c2s.MetrologyHandle, "all", "all", "used_edges",
                                                          "row", out hv_UsedRow);
                    HOperatorSet.GetMetrologyObjectResult(c2s.MetrologyHandle, "all", "all", "used_edges",
                                                          "column", out hv_UsedColumn);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_UsedEdges.Dispose();
                        HOperatorSet.GenCrossContourXld(out ho_UsedEdges, hv_UsedRow, hv_UsedColumn,
                                                        10, (new HTuple(45)).TupleRad());
                    }
                    //提取矩形边的长度
                    hv_RectIndices = 0;
                    HOperatorSet.GetMetrologyObjectResult(c2s.MetrologyHandle, hv_RectIndices,
                                                          "all", "result_type", "length1", out hv_Length1R);
                    HOperatorSet.GetMetrologyObjectResult(c2s.MetrologyHandle, hv_RectIndices,
                                                          "all", "result_type", "length2", out hv_Length2R);
                    //中心坐标及角度
                    HOperatorSet.GetMetrologyObjectResult(c2s.MetrologyHandle, hv_RectIndices,
                                                          "all", "result_type", "row", out hv_Parameter);
                    HOperatorSet.GetMetrologyObjectResult(c2s.MetrologyHandle, hv_RectIndices,
                                                          "all", "result_type", "column", out hv_Parameter1);
                    HOperatorSet.GetMetrologyObjectResult(c2s.MetrologyHandle, hv_RectIndices,
                                                          "all", "result_type", "phi", out hv_Parameter2);
                    HOperatorSet.SetColor(hWindow_Final1.hWindowControl.HalconWindow, "red");
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Cross2.Dispose();
                        HOperatorSet.GenCrossContourXld(out ho_Cross2, hv_Parameter, hv_Parameter1,
                                                        20, (new HTuple(45)).TupleRad());
                    }
                    //提取直线
                    //get_metrology_object_result (MetrologyHandle, 0, 'all', 'result_type', 'all_param', ParamLine1)
                    //get_metrology_object_result_contour (Contour, MetrologyHandle, 0, 'all', 1.5)
                    ho_ResultContours.Dispose();
                    HOperatorSet.GetMetrologyObjectResultContour(out ho_ResultContours, c2s.MetrologyHandle,
                                                                 "all", "all", 1.5);
                    HOperatorSet.DispObj(ho_ImageEmphasize, hWindow_Final1.hWindowControl.HalconWindow);
                    HOperatorSet.SetLineWidth(hWindow_Final1.hWindowControl.HalconWindow, 1);
                    HOperatorSet.SetColor(hWindow_Final1.hWindowControl.HalconWindow, "light gray");
                    HOperatorSet.DispObj(ho_Contour1, hWindow_Final1.hWindowControl.HalconWindow);
                    HOperatorSet.SetColor(hWindow_Final1.hWindowControl.HalconWindow, "green");
                    HOperatorSet.SetLineWidth(hWindow_Final1.hWindowControl.HalconWindow, 2);
                    HOperatorSet.DispObj(ho_ResultContours, hWindow_Final1.hWindowControl.HalconWindow);
                    HOperatorSet.SetLineWidth(hWindow_Final1.hWindowControl.HalconWindow, 1);
                    HOperatorSet.SetColor(hWindow_Final1.hWindowControl.HalconWindow, "white");
                    HOperatorSet.DispObj(ho_UsedEdges, hWindow_Final1.hWindowControl.HalconWindow);
                    ho_Image.Dispose();
                }
            }
            hv_ImageFiles.Dispose();
            GC.Collect();
        }