Exemplo n.º 1
0
 public void EraseHRegion(HRegion region)
 {
     if (MaskRegion != null)
     {
         HRegion buff = MaskRegion.Difference(region);
         MaskRegion.Dispose();
         MaskRegion = buff;
     }
 }
Exemplo n.º 2
0
        public override void FindModel()
        {
            HImage img = InputImg;

            if (SearchRegion == null || !SearchRegion.IsInitialized())
            {
                SearchRegion = img.GetDomain();
            }

            if (createNewModelID)
            {
                if (!CreateNccModel())
                {
                    return;
                }
            }

            if (!nCCModel.IsInitialized())
            {
                throw new Exception("无创建的模板");
            }

            HRegion domain          = img.GetDomain();
            HRegion differentdomain = domain.Difference(SearchRegion);
            HImage  searchImg       = img.PaintRegion(differentdomain, 0.0, "fill");
            HImage  cropImg         = searchImg.ReduceDomain(SearchRegion);

            domain.Dispose();
            differentdomain.Dispose();

            OutputResult.Reset();


            try
            {
                double t1, t2;
                t1 = HSystem.CountSeconds();
                HOperatorSet.FindNccModel(cropImg, nCCModel, nCCParam.mStartingAngle, nCCParam.mAngleExtent, nCCParam.MinScore,
                                          nCCParam.NumMatches, nCCParam.mMaxOverlap, nCCParam.SubPixel, 0, out OutputResult.Row, out OutputResult.Col, out OutputResult.Angle, out OutputResult.Score);

                OutputResult.TemplateHand = nCCModel;
                t2 = HSystem.CountSeconds();
                OutputResult.Time  = 1000.0 * (t2 - t1);
                OutputResult.Count = OutputResult.Row.Length;
            }
            catch (HOperatorException ex)
            {
                if (ex.GetErrorCode() != 9400)
                {
                    throw ex;
                }
            }

            searchImg.Dispose();
            cropImg.Dispose();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the ModelROI region for all objects contained
        /// in ROIList, by adding and subtracting the positive and
        /// negative ROI objects.
        /// </summary>
        public bool defineModelROI()
        {
            HRegion tmpAdd, tmpDiff, tmp;
            double  row, col;

            if (stateROI == MODE_ROI_NONE)
            {
                return(true);
            }

            tmpAdd  = new HRegion();
            tmpDiff = new HRegion();
            tmpAdd.GenEmptyRegion();
            tmpDiff.GenEmptyRegion();

            for (int i = 0; i < ROIList.Count; i++)
            {
                switch (((ROI)ROIList[i]).getOperatorFlag())
                {
                case ROI.POSITIVE_FLAG:
                    tmp    = ((ROI)ROIList[i]).getRegion();
                    tmpAdd = tmp.Union2(tmpAdd);
                    break;

                case ROI.NEGATIVE_FLAG:
                    tmp     = ((ROI)ROIList[i]).getRegion();
                    tmpDiff = tmp.Union2(tmpDiff);
                    break;

                default:
                    break;
                }        //end of switch
            }            //end of for

            ModelROI = null;

            if (tmpAdd.AreaCenter(out row, out col) > 0)
            {
                tmp = tmpAdd.Difference(tmpDiff);
                if (tmp.AreaCenter(out row, out col) > 0)
                {
                    ModelROI = tmp;
                }
            }
            //in case the set of positiv and negative ROIs dissolve
            if (ModelROI == null || ROIList.Count == 0)
            {
                return(false);
            }
            //ModelRoiContour =   ModelROI.GenContourRegionXld("border_holes");
            //viewController.clearList();
            //viewController.addIconicVar(ModelRoiContour);
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取+-运算后的roi轮廓
        /// </summary>
        public bool DefineModelROI()
        {
            HRegion tmpAdd, tmpDiff, tmp;
            double  row, col;

            if (stateROIOperation == ROIOperation.None)
            {
                return(true);
            }

            tmpAdd  = new HRegion();
            tmpDiff = new HRegion();
            tmpAdd.GenEmptyRegion();
            tmpDiff.GenEmptyRegion();

            for (int i = 0; i < ROIList.Count; i++)
            {
                switch (ROIList[i].OperatorFlag)
                {
                case ROIOperation.Positive:
                    tmp    = ROIList[i].GetRegion();
                    tmpAdd = tmp.Union2(tmpAdd);
                    break;

                case ROIOperation.Negative:
                    tmp     = ROIList[i].GetRegion();
                    tmpDiff = tmp.Union2(tmpDiff);
                    break;

                default:
                    break;
                } //end of switch
            }     //end of for

            modelROI = null;

            if (tmpAdd.AreaCenter(out row, out col) > 0)
            {
                tmp = tmpAdd.Difference(tmpDiff);
                if (tmp.AreaCenter(out row, out col) > 0)
                {
                    modelROI = tmp;
                }
            }

            //in case the set of positiv and negative ROIs dissolve
            if (modelROI == null || ROIList.Count == 0)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        public static HImage ReduceDomainForRing(this HImage hImage, double centerX, double centerY, double innerRadius,
                                                 double outerRadius)
        {
            var innerCircle = new HRegion();

            innerCircle.GenCircle(centerY, centerX, innerRadius);

            var outerCircle = new HRegion();

            outerCircle.GenCircle(centerY, centerX, outerRadius);

            var ring         = outerCircle.Difference(innerCircle);
            var reducedImage = hImage.ChangeDomain(ring);

            innerCircle.Dispose();
            outerCircle.Dispose();
            ring.Dispose();

//            reducedImage.CropDomain()
//                      .ToBitmapSource()
//                      .SaveToJpeg("_EnhanceEdgeArea_Domain.jpg");

            return(reducedImage);
        }
Exemplo n.º 6
0
        public SurfaceResult SearchSurface(HImage image, SurfaceDefinition definition)
        {
            var swSearchSurface = new NotifyStopwatch("SearchSurface: " + definition.Name);

            if (definition.SaveAllCacheImageEnabled)
            {
//                definition.SaveCacheImageEnabled = true;
                foreach (var part in definition.ExcludeParts)
                {
                    part.SaveCacheImageEnabled = true;
                }
                foreach (var part in definition.IncludeParts)
                {
                    part.SaveCacheImageEnabled = true;
                }
            }

            var surfaceResult = new SurfaceResult()
            {
                Definition = definition.DeepClone(),
            };

            var unionIncludeRegion = new HRegion();
            var unionIncludeDomain = new HRegion();

            unionIncludeRegion.GenEmptyRegion();
            unionIncludeDomain.GenEmptyRegion();

            var unionExcludeRegion = new HRegion();
            var unionExcludeDomain = new HRegion();

            unionExcludeRegion.GenEmptyRegion();
            unionExcludeDomain.GenEmptyRegion();

            foreach (var excludeRegion in definition.ExcludeParts)
            {
                var     sw     = new NotifyStopwatch("excludeRegion.Process: " + excludeRegion.Name);
                HRegion region = excludeRegion.Extract(image);
                sw.Dispose();
                var domain = excludeRegion.Domain;

                unionExcludeRegion = unionExcludeRegion.Union2(region);
                unionExcludeDomain = unionExcludeDomain.Union2(domain);

                if (excludeRegion.SaveCacheImageEnabled)
                {
                    var fileName = "SurfaceDefinition_" + definition.Name + "_Exclude_" + excludeRegion.Name;
                    image.SaveCacheImagesForRegion(domain, region, fileName);
                }

                surfaceResult.ExcludeRegionResults.Add(new RegionResult()
                {
                    SurfaceGroupName = definition.GroupName,
                    SurfaceName      = definition.Name,
                    RegionName       = excludeRegion.Name,
                    Domain           = domain,
                    Region           = region,
                });

                //                    region.Dispose();
                //                    domain.Dispose();
            }

            foreach (var includeRegion in definition.IncludeParts)
            {
                var domain = includeRegion.Domain;
                unionIncludeDomain = unionIncludeDomain.Union2(domain);

                var remainDomain = domain.Difference(unionExcludeRegion);
                var reducedImage = image.ChangeDomain(remainDomain);

                HRegion region;
                using (new NotifyStopwatch("includeRegion.Process: " + includeRegion.Name))
                    region = includeRegion.Extract(reducedImage);
                var remainRegion = region.Difference(unionExcludeRegion);
                unionIncludeRegion = unionIncludeRegion.Union2(remainRegion);

                if (includeRegion.SaveCacheImageEnabled)
                {
                    var fileName = "SurfaceDefinition_" + definition.Name + "_Include_" + includeRegion.Name;
                    //                        _hDevelopExportHelper.HImage.SaveCacheImagesForRegion(domain, remainRegion, fileName);
                    image.SaveCacheImagesForRegion(domain, remainRegion, unionExcludeRegion,
                                                   fileName);
                }

                surfaceResult.IncludeRegionResults.Add(new RegionResult()
                {
                    SurfaceGroupName = definition.GroupName,
                    SurfaceName      = definition.Name,
                    RegionName       = includeRegion.Name,
                    Domain           = domain,
                    Region           = remainRegion,
                });
            }

            if (definition.SaveCacheImageEnabled && definition.IncludeParts.Any())
            {
                var fileName = "SurfaceDefinition_" + definition.Name + "_Include";
                image.SaveCacheImagesForRegion(unionIncludeDomain, unionIncludeRegion,
                                               unionExcludeRegion, fileName);
            }

            if (definition.SaveCacheImageEnabled && definition.ExcludeParts.Any())
            {
                var fileName = "SurfaceDefinition_" + definition.Name + "_Exclude";
                image.SaveCacheImagesForRegion(unionExcludeDomain, unionExcludeRegion,
                                               fileName);
            }

            surfaceResult.ExcludeRegion = unionExcludeRegion;
            surfaceResult.IncludeRegion = unionIncludeRegion;

            swSearchSurface.Dispose();
            return(surfaceResult);
        }
        /// <summary>
        /// 获取+-运算后的roi轮廓
        /// </summary>
        public bool DefineModelROI()
        {
            HRegion tmpAdd, tmpDiff, tmp;
            double  row, col;

            if (stateROIOperation == ROIOperation.None)  //ROI搜索模式
            {
                return(true);
            }

            tmpAdd  = new HRegion();
            tmpDiff = new HRegion();
            tmpAdd.GenEmptyRegion();
            tmpDiff.GenEmptyRegion();

            for (int i = 0; i < ROIList.Count; i++)
            {
                switch (ROIList[i].OperatorFlag)
                {
                case ROIOperation.Positive:
                    tmp    = ROIList[i].GetRegion();
                    tmpAdd = tmp.Union2(tmpAdd);       //把所有求和模式的ROI Region联合在一起
                    break;

                case ROIOperation.Negative:
                    tmp     = ROIList[i].GetRegion();
                    tmpDiff = tmp.Union2(tmpDiff);      //把所有求差模式的ROI Region联合在一起。
                    break;

                case ROIOperation.Tuya:
                    tmp = ROIList[i].GetRegion();
                    if (tmp != null && tmp.IsInitialized())
                    {
                        tmpDiff = tmp.Union2(tmpDiff);      //把所有求差模式的ROI Region联合在一起。
                    }
                    break;

                default:
                    break;
                } //end of switch
            }     //end of for

            modelROI = null;

            if (tmpAdd.AreaCenter(out row, out col) > 0)
            {
                tmp = tmpAdd.Difference(tmpDiff);
                if (tmp.AreaCenter(out row, out col) > 0) //如果tmpAdd > tmpDiff;
                {
                    modelROI = tmp;                       //把差值赋给modelROI。
                }
            }

            //in case the set of positiv and negative ROIs dissolve
            if (modelROI == null || ROIList.Count == 0)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Calculates the ModelROI region for all objects contained
        /// in ROIList, by adding and subtracting the positive and
        /// negative ROI objects.
        /// </summary>
        public bool defineModelROI()
        {
            HRegion tmpAdd, tmpDiff, tmp;
            double  row, col;
            double  rowDiff, colDiff;

            if (stateROI == MODE_ROI_NONE)
            {
                return(true);
            }

            tmp     = new HRegion();
            tmpAdd  = new HRegion();
            tmpDiff = new HRegion();
            tmpAdd.GenEmptyRegion();
            tmpDiff.GenEmptyRegion();

            for (int i = 0; i < ROIList.Count; i++)
            {
                switch (((ROI)ROIList[i]).getOperatorFlag())
                {
                case ROI.POSITIVE_FLAG:
                    tmp    = ((ROI)ROIList[i]).getRegion();
                    tmpAdd = tmp.Union2(tmpAdd);
                    break;

                case ROI.NEGATIVE_FLAG:
                    tmp     = ((ROI)ROIList[i]).getRegion();
                    tmpDiff = tmp.Union2(tmpDiff);
                    break;

                default:
                    break;
                } //end of switch
            }     //end of for

            ModelROI = null;

            if (tmpAdd.AreaCenter(out row, out col) > 0)
            {
                if (tmpDiff.AreaCenter(out rowDiff, out colDiff) > 0)
                {
                    tmp = tmpAdd.Difference(tmpDiff);
                }
                else
                {
                    tmp = tmpAdd;
                }
                if (tmp.AreaCenter(out row, out col) > 0)
                {
                    ModelROI = tmp;
                }
            }

            //in case the set of positiv and negative ROIs dissolve
            if (ModelROI == null || ROIList.Count == 0)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Calculates the ModelROI region for all objects contained 
        /// in ROIList, by adding and subtracting the positive and 
        /// negative ROI objects.
        /// </summary>
        public bool defineModelROI()
        {
            HRegion tmpAdd, tmpDiff, tmp;
            double row, col;

            if (stateROI == MODE_ROI_NONE)
                return true;

            tmpAdd = new HRegion();
            tmpDiff = new HRegion();
            tmpAdd.GenEmptyRegion();
            tmpDiff.GenEmptyRegion();

            for (int i = 0; i < ROIList.Count; i++)
            {
                switch (((ROI)ROIList[i]).getOperatorFlag())
                {
                    case ROI.POSITIVE_FLAG:
                        tmp = ((ROI)ROIList[i]).getRegion();
                        tmpAdd = tmp.Union2(tmpAdd);
                        break;
                    case ROI.NEGATIVE_FLAG:
                        tmp = ((ROI)ROIList[i]).getRegion();
                        tmpDiff = tmp.Union2(tmpDiff);
                        break;
                    default:
                        break;
                }//end of switch
            }//end of for

            ModelROI = null;

            if (tmpAdd.AreaCenter(out row, out col) > 0)
            {
                tmp = tmpAdd.Difference(tmpDiff);
                if (tmp.AreaCenter(out row, out col) > 0)
                    ModelROI = tmp;
            }

            //in case the set of positiv and negative ROIs dissolve
            if (ModelROI == null || ROIList.Count == 0)
                return false;

            return true;
        }