Beispiel #1
0
        /// <summary>
        /// 图像处理
        /// </summary>
        /// <returns>返回8个点位数组</returns>
        public double[] Process()
        {
            double[] coorderate = new double[8];
            double   hv_RowBegin1; double hv_ColBegin1; double hv_RowEnd1; double hv_ColEnd1; double hv_Nr1; double hv_Nc1; double hv_Dist1;
            double   hv_RowBegin2; double hv_ColBegin2; double hv_RowEnd2; double hv_ColEnd2; double hv_Nr2; double hv_Nc2; double hv_Dist2;
            //图像阈值化,获得region
            HRegion hRegion = Ho_image.Threshold((double)LowThreshold, (double)HighThreshold);
            //region转化为himage
            HImage hImage = hRegion.RegionToBin(255, 0, 512, 512);
            //减去ROI以外多余部分
            HImage image1 = hImage.ReduceDomain(Region1);
            HImage image2 = hImage.ReduceDomain(Region2);
            //生成边缘轮廓
            HXLDCont edges1 = image1.EdgesSubPix("canny", 1, 5, 5);
            HXLDCont edges2 = image2.EdgesSubPix("canny", 1, 5, 5);
            //分割轮廓
            HXLDCont xldContsplit1 = edges1.SegmentContoursXld("lines_circles", 5, 4, 2);
            HXLDCont xldContsplit2 = edges2.SegmentContoursXld("lines_circles", 5, 4, 2);
            //根据特征筛选轮廓
            HXLDCont xldCont1 = xldContsplit1.SelectContoursXld("contour_length", 100, 99999999, -0.5, 0.5);
            HXLDCont xldCont2 = xldContsplit2.SelectContoursXld("contour_length", 100, 99999999, -0.5, 0.5);

            //拟合直线
            xldCont1.FitLineContourXld("tukey", -1, 0, 5, 2, out hv_RowBegin1, out hv_ColBegin1, out hv_RowEnd1, out hv_ColEnd1, out hv_Nr1, out hv_Nc1, out hv_Dist1);
            xldCont2.FitLineContourXld("tukey", -1, 0, 5, 2, out hv_RowBegin2, out hv_ColBegin2, out hv_RowEnd2, out hv_ColEnd2, out hv_Nr2, out hv_Nc2, out hv_Dist2);
            coorderate[0] = hv_RowBegin1;
            coorderate[1] = hv_ColBegin1;
            coorderate[2] = hv_RowEnd1;
            coorderate[3] = hv_ColEnd1;
            coorderate[4] = hv_RowBegin2;
            coorderate[5] = hv_ColBegin2;
            coorderate[6] = hv_RowEnd2;
            coorderate[7] = hv_ColEnd2;
            return(coorderate);
        }
Beispiel #2
0
        private void bFindShape_Click(object sender, EventArgs e)
        {
            if (this.Image != null && this.Image.IsInitialized() &&
                this.EdgesRegion != null && this.EdgesRegion.IsInitialized())
            {
                if (this.IgnoreRegion != null)
                {
                    this.EdgesRegion = this.EdgesRegion.Difference(this.IgnoreRegion);
                }
                HImage reductImage = this.image.ReduceDomain(this.EdgesRegion);

                this.Edges = reductImage.EdgesSubPix("canny", 3, (double)this.minContrast.Value, (double)this.contrast.Value);
                reductImage.Dispose();
                this.hWindows.HalconWindow.SetDraw("margin");
                this.hWindows.HalconWindow.SetColor("red");
                this.hWindows.HalconWindow.DispXld(this.Edges);
            }
        }