public void GenDetectionRegionResult(HRegion modelRegion)
        {
            if (resultRegion == null)
            {
                resultRegion = new HRegion();
            }
            if (resultRegion != null && resultRegion.IsInitialized())
            {
                resultRegion.Dispose();
            }
            resultRegion.GenEmptyObj();

            HRegion temp = new HRegion();

            for (int i = 0; i < row.Length; i++)
            {
                HHomMat2D mat1 = new HHomMat2D();
                mat1.VectorAngleToRigid(
                    createShapeModel.refCoordinates[0].D,
                    createShapeModel.refCoordinates[1].D,
                    createShapeModel.refCoordinates[2].D,
                    row[i].D, column[i].D, angle[i].D);
                mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D);
                //图像偏移
                temp = mat1.AffineTransRegion(modelRegion, "nearest_neighbor");
                //获取模板集合
                resultRegion = resultRegion.ConcatObj(temp);
                temp.Dispose();
            }
        }
示例#2
0
 public HRegion TransRegion(HRegion region)
 {
     try
     {
         HHomMat2D matd = new HHomMat2D();
         matd.VectorAngleToRigid(this.info.ModelRegionRow, this.info.ModelRegionCol, this.info.ModelRegionAngle, this.info.ResultY, this.info.ResultX, this.info.ResultAngle);
         if (IsSuccess)
         {
             region = matd.AffineTransRegion(region, "nearest_neighbor");
             return(region);
         }
     }
     catch (Exception ex)
     {
         WriteErrorLog("VisionTool", ToolName + "模板" + ex.ToString());
     }
     return(null);
 }
        private void DefineMat2Ds()
        {
            if (mat2Ds == null)
            {
                mat2Ds = new List <HHomMat2D>();
            }
            else
            {
                mat2Ds.Clear();
            }
            for (int i = 0; i < row_temp.Length; i++)
            {
                HHomMat2D homMat2D = new HHomMat2D();
                homMat2D.VectorAngleToRigid(
                    createShapeModel.refCoordinates[0].D, createShapeModel.refCoordinates[1].D, createShapeModel.refCoordinates[2].D,
                    row_temp[i].D, column_temp[i].D, angle_temp[i].D);
                HRegion boundary_region;
                if (SearchRegion == null | !SearchRegion.IsInitialized())
                {
                    boundary_region = refImage.GetDomain().Boundary("inner");
                }
                else
                {
                    boundary_region = SearchRegion.Boundary("inner");
                }

                HTuple row_rect2, col_rect2, phi_rect2, lenght1_rect2, lenght2_rect2;
                if (this.createShapeModel.modelRegion == null || !this.createShapeModel.modelRegion.IsInitialized())
                {
                    return;
                }
                this.createShapeModel.modelRegion.SmallestRectangle2(out row_rect2, out col_rect2, out phi_rect2, out lenght1_rect2, out lenght2_rect2);

                HRegion small_rect2_region = new HRegion();
                small_rect2_region.GenRectangle2(row_rect2, col_rect2, phi_rect2, lenght1_rect2, lenght2_rect2);

                HRegion small_rect2_region_affine = homMat2D.AffineTransRegion(small_rect2_region, "nearest_neighbor");

                HObject Area_temp;
                HOperatorSet.Intersection(boundary_region, small_rect2_region_affine, out Area_temp);
                HTuple area, row_tt, col_tt;
                HOperatorSet.AreaCenter(Area_temp, out area, out row_tt, out col_tt);
                if (area.D == 0)
                {
                    mat2Ds.Add(homMat2D);
                    row    = row.TupleConcat(row_temp[i]);
                    column = column.TupleConcat(column_temp[i]);
                    angle  = angle.TupleConcat(angle_temp[i]);
                    scale  = scale.TupleConcat(scale_temp[i]);
                    score  = score.TupleConcat(score_temp[i]);
                }
                if (boundary_region != null && boundary_region.IsInitialized())
                {
                    boundary_region.Dispose();
                }
                if (small_rect2_region_affine != null && small_rect2_region_affine.IsInitialized())
                {
                    small_rect2_region_affine.Dispose();
                }
                if (small_rect2_region != null && small_rect2_region.IsInitialized())
                {
                    small_rect2_region.Dispose();
                }
                if (Area_temp != null && Area_temp.IsInitialized())
                {
                    Area_temp.Dispose();
                }
            }
        }