Ejemplo n.º 1
0
        /// <summary>
        /// 抓取相机的图像,输出Halcon格式
        /// </summary>
        public override ImageAll GrabImageHal()
        {
            g_MtGrabImage.WaitOne();
            ImageAll imageAll = new ImageAll();

            try
            {
                if (!BlOpen)//如果相机打开失败
                {
                    return(null);
                }
#if (SDK)
                try
                {
                    SetTrriggerMode();//设置软触发
                    g_ManagedCameraBase.RetrieveBuffer(g_RawImage);
                }
                catch (Exception ex)
                {
                    Log.L_I.WriteError(NameClass, ex);
                    try
                    {
                        if (g_BaseParCamera.BlUsingTrigger)                       //使用软触发
                        {
                            g_ManagedCameraBase.WriteRegister(0x62C, 0x80000000); //发送软触发指令
                        }
                        g_ManagedCameraBase.RetrieveBuffer(g_RawImage);
                    }
                    catch
                    {
                        if (g_BaseParCamera.BlUsingTrigger)                       //使用软触发
                        {
                            g_ManagedCameraBase.WriteRegister(0x62C, 0x80000000); //发送软触发指令
                        }
                        g_ManagedCameraBase.RetrieveBuffer(g_RawImage);
                    }
                }

                //将图像转换为Halcon格式
                imageAll.Ho_Image     = ConvertHobject();
                imageAll.BitmapSource = null;

                PathDirectory p = new PathDirectory();
                imageAll.Time = p.GetShortTimeName();
#endif
                return(imageAll);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(null);
            }
            finally
            {
                g_MtGrabImage.ReleaseMutex();
            }
        }
        /// <summary>
        /// 图像,加上名称+时间
        /// </summary>
        /// <param name="imageAll"></param>
        /// <param name="nameImage"></param>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public bool SaveImage(ImageAll imageAll, string nameImage, string strPath)
        {
            try
            {
                if (!BlLocalImage ||
                    (BlPIForce && imageAll.Name == "PI"))   //本地图像不保存图像,或者强制截屏不保存
                {
                    // 判断是否存在目录夹
                    if (Directory.Exists(strPath) == false)
                    {
                        //创建文件夹
                        Directory.CreateDirectory(strPath);
                    }

                    //获取时间路径
                    //strPath = Log.CreateHourFile(strPath) + g_PathDirectory.GetTimeName() + "." + g_BaseParCamera.TypeSaveImage;
                    string pathFile = Log.CreateHourFile(strPath) + nameImage + imageAll.Time + "." + TypeSaveImage;
                    string type     = TypeSaveImage;
                    if (imageAll.Name == "PI")//屏幕截图
                    {
                        pathFile = Log.CreateHourFile(strPath) + nameImage + imageAll.Time + "_" + imageAll.Name + "." + "jpg";
                        type     = "jpeg";
                    }
                    else
                    {
                        pathFile = Log.CreateHourFile(strPath) + nameImage + imageAll.Time + "_" + imageAll.Name + "." + TypeSaveImage;
                    }

                    //保存图像
                    if (imageAll == null)
                    {
                        return(false);
                    }
                    if (SaveHoImage(imageAll.Ho_Image, type, pathFile))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
            finally
            {
                if (imageAll != null)
                {
                    if (imageAll.Name == "PI")//屏幕截图
                    {
                        imageAll.Dispose();
                    }
                }
            }
        }
        /// <summary>
        /// 短名称
        /// </summary>
        /// <param name="imageAll"></param>
        /// <param name="nameImage"></param>
        /// <param name="strPath"></param>
        /// <returns></returns>
        public bool SaveImage_Short(ImageAll imageAll, string nameImage, string strPath)
        {
            try
            {
                if (BlLocalImage)//本地图像不保存图像
                {
                    return(true);
                }
                // 判断是否存在目录夹
                if (Directory.Exists(strPath) == false)
                {
                    //创建文件夹
                    Directory.CreateDirectory(strPath);
                }

                //获取时间路径
                string pathFile = Log.CreateHourFile(strPath) + nameImage + imageAll.TimeShort + "." + TypeSaveImage;
                string type     = TypeSaveImage;
                if (imageAll.Name == "PI")//屏幕截图
                {
                    pathFile = Log.CreateHourFile(strPath) + nameImage + imageAll.TimeShort + "_" + imageAll.Name + "." + "jpg";
                    type     = "jpeg";
                }
                else
                {
                    pathFile = Log.CreateHourFile(strPath) + nameImage + imageAll.TimeShort + "_" + imageAll.Name + "." + TypeSaveImage;
                }

                //保存图像
                if (imageAll == null)
                {
                    return(false);
                }
                if (SaveHoImage(imageAll.Ho_Image, type, pathFile))
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
            finally
            {
                if (imageAll != null)
                {
                    if (imageAll.Name == "PI")//屏幕截图
                    {
                        imageAll.Dispose();
                    }
                }
            }
        }
 /// <summary>
 /// 默认路径保存
 /// </summary>
 public bool SaveImageDefaultPath(ImageAll imageAll)
 {
     try
     {
         return(SaveImage(imageAll, PathSaveImage));
     }
     catch (Exception ex)
     {
         Log.L_I.WriteError(NameClass, ex);
         return(false);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 短时间
        /// </summary>
        /// <param name="path"></param>
        protected void DumpWimImageShort_NG(string path)
        {
            try
            {
                ImageAll im = g_UCDisplayCamera.DumpWinImage();//截屏图片

                g_UCDisplayCamera.SaveNGImagePath_Short(im, path);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
            }
        }
 /// <summary>
 /// 短名称
 /// </summary>
 /// <param name="imageAll"></param>
 /// <param name="nameImage"></param>
 /// <param name="nameFolder"></param>
 /// <returns></returns>
 public bool SaveNGImagePath_Short(ImageAll imageAll, string nameImage, string nameFolder)
 {
     try
     {
         string root = PathNGImage + nameFolder + "\\";
         return(SaveImage_Short(imageAll, nameImage, root));
     }
     catch (Exception ex)
     {
         Log.L_I.WriteError(NameClass, ex);
         return(false);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// OK图像,包含新的存储路径,图片名称
        /// </summary>
        protected void DumpWimImage_OK(string name, string path)
        {
            try
            {
                ImageAll im = g_UCDisplayCamera.DumpWinImage();//截屏图片

                g_UCDisplayCamera.SaveOKImagePath(im, name, path);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
            }
        }
 /// <summary>
 /// 保存图片到默认路径
 /// </summary>
 /// <param name="imageAll"></param>
 /// <param name="nameFolder">按照拍照设置的文件夹名称</param>
 /// <returns></returns>
 public bool SaveImageDefaultPath(ImageAll imageAll, string nameFolder)
 {
     try
     {
         string root = PathSaveImage + nameFolder + "\\";
         return(SaveImage(imageAll, root));
     }
     catch (Exception ex)
     {
         Log.L_I.WriteError(NameClass, ex);
         return(false);
     }
 }
        /// <summary>
        /// 自动抓取
        /// 是否是DealGrabImage项目调用
        /// </summary>
        public ImageAll GrabForAuto()
        {
            try
            {
                if (BlRealGrab)
                {
                    BlGrabForAuto = true;
                    int num = 0;
                    while (!BlFinishGrab)//等待抓取到图像
                    {
                        Thread.Sleep(20);
                        num++;
                        if (num > 50)
                        {
                            return null;
                        }
                    }
                    if (BlFinishGrab)
                    {
                        ImageAll im = null;// GrabImageHalForReal();
                        if (ImBitInit != null)
                        {                           
                            ImBitInit.Dispose();//先进行释放
                            ImBitInit = null;
                        }
                        if (Bit != null)
                        {                            
                            Bit.Dispose();//先进行释放
                            Bit = null;
                        }
                        ImBitInit = im;

                        BlGrabForAuto = false;//自动触发结束
                        return im;
                    }
                    return null;
                }
                else
                {
                    return GrabImageHal();
                }
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return null;
            }
        }
        /// <summary>
        /// 将图像添加到哈希表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="im"></param>
        public void AddResultMainShow(string name, ImageAll im)
        {
            try
            {
                if (g_ResultMainShow.HtResultImage.Contains(name))
                {
                    ImageAll imOld = g_ResultMainShow.HtResultImage[name] as ImageAll;
                    imOld.Dispose();
                    g_ResultMainShow.HtResultImage.Remove(name);
                }

                g_ResultMainShow.HtResultImage.Add(name, im);
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 11
0
        //★★★ 相机采集的回调函数
        //相机每次得到图像数据后,会自动调用该函数,给出采集结果:e.GrabResult
        void StreamGrabber_ImageGrabbed(object sender, ImageGrabbedEventArgs e)
        {
            try
            {
                IGrabResult grabResult = e.GrabResult;

                if (grabResult.GrabSucceeded)
                {
                    g_AutoResetEvent.Set();
                }

                //使用触发模式
                if (g_BaseParCamera.BlUsingTrigger)
                {
                    //new Task(new Action(() =>
                    //{
                    ImageAll imTemp = new ImageAll();
                    imTemp.TimeTrigger = PathDirectory.P_I.GetShortTimeName();//获取外触发的时间

                    using (grabResult)
                    {
                        if (grabResult != null && grabResult.GrabSucceeded)
                        {
                            imTemp.Ho_Image     = ConvertHobject(grabResult);
                            imTemp.BitmapSource = null;
                            imTemp.TimeTrigger  = PathDirectory.P_I.GetTimeName();
                            grabResult.Dispose();
                        }
                    }
                    ImageAll_Q.Enqueue(imTemp);//图像加入队列

                    //})).Start();
                }
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
            }
            finally
            {
            }
        }
        /// <summary>
        /// 抓取新的图像进行保存
        /// </summary>
        public bool GrabAndSaveImage(string strPath)
        {
            try
            {
                ImageAll imageAll = GrabImageAll();

                //保存图像
                if (imageAll == null)
                {
                    return(false);
                }
                if (SaveHoImage(imageAll.Ho_Image, strPath))
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
        }
 /// <summary>
 /// 实时状态下进行处理和显示
 /// </summary>
 void RealGrab()
 {
     try
     {               
         while (BlRealGrab)
         {
             Thread.Sleep(2);
             Thread.Sleep(TimeCycForReal);//循环间隔
             try
             {
                 ImageAll im = null;
                 if (!BlGrabForAuto)//非触发状态,如果处于触发状态,则调用GrabForAuto
                 {
                     BlFinishGrab = false;
                     //im = GrabImageHalForReal();
                     BlFinishGrab = true;
                 }
                 //显示图像以及字符
                 if (im != null)
                 {
                     //显示图像
                     DispImage(im);
                     //显示ROI已经结果
                     DispHobject_L();
                 }
             }
             catch (Exception ex)
             {
                 Thread.Sleep(200);
             }
         }
     }
     catch (Exception ex)
     {
         Log.L_I.WriteError(NameClass, ex);
     }
 }
Ejemplo n.º 14
0
        public override ImageAll GrabImageHal()
        {
            g_MtGrabImage.WaitOne();
            ImageAll imageAll = new ImageAll();
            int waitTime = 1000;
            try
            {
                if (BlOpen)//如果相机打开成功
                {
                    if (g_BaseParCamera.BlUsingTrigger
                        && TriggerSource_e != TriggerSourceCamera_enum.Software)//使用软触发
                    {
                        if (ImageAll_Q.Count > 0)
                        {
                            ImageAll im = ImageAll_Q.Peek();
                            ImageAll_Q.Dequeue();//出站
                            if (ImageAll_Q.Count > 20)//认为溢出
                            {
                                ImageAll_Q.Clear();
                            }

                            im.Time = g_PathDirectory.GetTimeName();
                            im.TimeShort = g_PathDirectory.GetShortTimeName();//图像抓取短时间
                            return im;
                        }
                        else
                        {
                            return null;
                        }
                    }
                    else
                    {
#if(SDK)
                        UInt32 nDataLen = 0;
                        IntPtr pData = Marshal.UnsafeAddrOfPinnedArrayElement(g_PBufForDriver, 0);

                        MyCamera.MV_FRAME_OUT_INFO_EX image_grab = new MyCamera.MV_FRAME_OUT_INFO_EX();

                        //获取一帧,超时时间为1秒
                        int nRet = GetOneFrameTimeout(pData, ref nDataLen, g_BufSizeForDriver, ref image_grab, waitTime);

                        imageAll.Ho_Image = ConvertHobject(image_grab, pData);
                        imageAll.BitmapSource = null;

                        imageAll.Time = g_PathDirectory.GetTimeName();
                        imageAll.TimeShort = g_PathDirectory.GetShortTimeName();//图像抓取短时间
#endif
                    }
                }
                return imageAll;
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return null;
            }
            finally
            {
                g_MtGrabImage.ReleaseMutex();
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 抓取相机的图像,输出Halcon格式
        /// </summary>
        public override ImageAll GrabImageHal()
        {
            ImageAll imageAll = new ImageAll();

            try
            {
                if (!BlOpen)
                {
                    return(null);
                }
#if (SDK)
                //★★★ 确保相机当前是采集状态 && 确保相机可以接收软件触发指令
                if (g_Camera != null && g_Camera.IsOpen)
                {
                    if (g_BaseParCamera.BlUsingTrigger)//使用软触发
                    {
                        if (ImageAll_Q.Count > 0)
                        {
                            ImageAll im = ImageAll_Q.Peek();
                            ImageAll_Q.Dequeue();      //出站
                            if (ImageAll_Q.Count > 20) //认为溢出
                            {
                                ImageAll_Q.Clear();
                                Log.L_I.WriteError(NameClass, "图像外触发溢出");
                            }
                            return(im);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        try
                        {
                            g_Camera.StreamGrabber.Start();
                            g_GrabResult = g_Camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
                        }
                        catch (Exception ex)
                        {
                            Log.L_I.WriteError(NameClass, ex);
                        }
                    }
                }

                using (g_GrabResult)
                {
                    if (g_GrabResult != null && g_GrabResult.GrabSucceeded)
                    {
                        imageAll.Ho_Image     = ConvertHobject(g_GrabResult);
                        imageAll.BitmapSource = null;

                        PathDirectory p = new PathDirectory();
                        imageAll.Time      = p.GetTimeName();
                        imageAll.TimeShort = p.GetShortTimeName();
                    }
                }
                g_Camera.StreamGrabber.Stop();
#endif
                return(imageAll);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(null);
            }
        }
        public ResultLinesDotsPosNegInspect DealLinesDotsPosNegInspect(ParLinesDotsPosNegInspect par, Hashtable htResult, Hashtable htResult_Mult)
        {
            #region 定义
            ResultLinesDotsPosNegInspect result = new ResultLinesDotsPosNegInspect();
            HTuple  width               = 0;
            HTuple  height              = 0;
            HObject ho_Image            = null;
            HObject ho_ReduceImage      = null;
            HObject ho_ResultPreprocess = null;
            HObject ho_ROI              = null;
            HObject ho_ROIPreprocess    = null;

            HObject ho_ImageDesReduce    = null;
            HObject ho_MultiChannelImage = null;
            HObject ho_MultiChannelEdges = null;//多通道边缘显示图像

            HOperatorSet.GenEmptyObj(out ho_ResultPreprocess);
            HOperatorSet.GenEmptyObj(out ho_ReduceImage);
            HOperatorSet.GenEmptyObj(out ho_ImageDesReduce);
            HOperatorSet.GenEmptyObj(out ho_MultiChannelImage);
            HOperatorSet.GenEmptyObj(out ho_MultiChannelEdges);

            #endregion 定义

            try
            {
                #region 基础功能调用
                if (BasicImageProcess_MultROI(par, result, htResult, out ho_ROI, out ho_ReduceImage, out ho_Image, out width, out height))
                {
                }
                else
                {
                    return(result);
                }
                #endregion 基础功能调用
                HObject ho_AffineROI = result.g_ResultPreProcess.resultAffineImage.ImageROIAffine.Ho_Image;
                //TODO 获取ROI 预处理之后的ROITrans
                ho_ROIPreprocess = ho_ROI;
                //多相机引用
                int         noCamera        = par.NoCameraMult;
                Hashtable   htResult_Camera = htResult_Mult["HtResult_Cam" + noCamera.ToString()] as Hashtable;
                ResultPhoto photo           = htResult_Camera[par.CellRefImage_Mult.NameCell] as ResultPhoto;
                ImageAll    imMult          = photo.HtResultImage[par.CellRefImage_Mult.NameCell + "FunPhoto.CameraImage"] as ImageAll;

                //获取图像预处理结果--经过投影变换出来的结果
                ho_ResultPreprocess = result.g_ResultPreProcess.ImageResult.Ho_Image;


                //目标相机拍摄的图像也进行区域reduce
                ho_ImageDesReduce.Dispose();

                HOperatorSet.ReduceDomain(imMult.Ho_Image, ho_ROIPreprocess, out ho_ImageDesReduce);
                //求融合图像
                ho_MultiChannelImage.Dispose();
                bool blInspectResult = LinesDotsPosNegInspect(ho_ImageDesReduce, ho_ResultPreprocess, par, result, out ho_MultiChannelImage);
                ho_MultiChannelEdges.Dispose();
                bool blCalibConfirm = CalibConfirm(ho_ROIPreprocess, ho_ImageDesReduce, ho_ResultPreprocess, par, result, width, height, out ho_MultiChannelEdges);

                //求融合图像
                //ho_MultiChannelImage.Dispose();
                //bool blInspectResult = LinesDotsPosNegInspect(imMult.Ho_Image, ho_ResultPreprocess, par, result, out ho_MultiChannelImage);
                //ho_MultiChannelEdges.Dispose();
                //bool blCalibConfirm = CalibConfirm(ho_ROIPreprocess, imMult.Ho_Image, ho_ResultPreprocess, par, result, width, height, out ho_MultiChannelEdges);

                if (blInspectResult)
                {
                    result.LevelError_e       = LevelError_enum.Error;
                    result.TypeErrorProcess_e = TypeErrorProcess_enum.Others;
                    result.Annotation         = par.NameCell.ToString() + ",点线区域求取错误!";
                    return(result);
                }
                //TODO 融合之后的图像赋值

                return(result);
            }
            catch (Exception ex)
            {
                result.LevelError_e       = LevelError_enum.Error;
                result.TypeErrorProcess_e = TypeErrorProcess_enum.Catch;
                result.Annotation         = par.NameCell.ToString() + ",点线区域求取跳转到异常";
                result.SetDefault();
                LogError("FunLinesDotsPosNegInspect", par, ex);
                return(result);
            }
            finally
            {
                //对结果进行综合处理
                SetComprehensiveResult(result, par, htResult, true);
                //校准
                DealCalibResult(par, result, htResult);
                #region 记录时间
                WriteRunTime(stopWatch, NameClass, par, result);
                #endregion 记录时间

                #region 记录
                RecordImage(par, result, NameClass, "ReduceImage", ho_ReduceImage);       //保存图像到哈希表
                RecordImage(par, result, NameClass, "ImageDesReduce", ho_ImageDesReduce); //保存图像到哈希表
                RecordImage_Record(par, result, NameClass, "MultiChannelImage", ho_MultiChannelImage);
                RecordImage_Record(par, result, NameClass, "MultiChannelEdges", ho_MultiChannelEdges);
                #endregion 记录
            }
        }
Ejemplo n.º 17
0
        public ResultFinShell DealFinShell(ParFinShell par, Hashtable htResult)
        {
            #region 定义
            HTuple         num_Obj = 0;
            ResultFinShell result  = new ResultFinShell();

            HTuple width  = null;
            HTuple height = null;

            ImageAll imageAll = null;

            HObject ho_Image             = null;
            HObject ho_RegionReduced     = null;
            HObject ho_ResultPreprocess  = null;
            HObject ho_RegionOuter       = null;
            HObject ho_RegionInnerOuter  = null;
            HObject ho_RegionInner       = null;
            HObject ho_RegionIntersected = null;
            HObject ho_RegionConnected   = null;
            HObject ho_RegionFillUp      = null;
            HObject ho_RegionOpening     = null;
            HObject ho_RegionClosing     = null;

            HObject ho_RegionWidthSelected  = null;
            HObject ho_RegionHeightSelected = null;
            HObject ho_RegionAreaSelected   = null;

            HObject ho_RegionUnion1 = null;
            HObject ho_RegionUnion2 = null;

            HObject ho_RegionFinShell = null;

            //求取沿XLD外形切线方向的外轮廓
            HObject ho_xldToCalHeight                  = null;
            HObject ho_xldToCalWidth                   = null;
            HObject ho_ho_RegionFinShellSelect         = null;
            HObject ho_ho_RegionFinShellSelectContours = null;

            HTuple hv_disMin      = null;
            double HeightCalUpper = 0;

            HTuple WidthCalRow = null, WidthCalCol = null;

            HTuple hv_FinShellIntersectRow = null;
            HTuple hv_FinShellIntersectCol = null;
            HTuple hv_FinShellCircleRadius = null;

            HTuple FinShellWidth = null;

            HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_RegionReduced);
            HOperatorSet.GenEmptyObj(out ho_ResultPreprocess);
            HOperatorSet.GenEmptyObj(out ho_RegionOuter);
            HOperatorSet.GenEmptyObj(out ho_RegionInnerOuter);
            HOperatorSet.GenEmptyObj(out ho_RegionInner);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersected);
            HOperatorSet.GenEmptyObj(out ho_RegionConnected);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing);
            HOperatorSet.GenEmptyObj(out ho_RegionWidthSelected);
            HOperatorSet.GenEmptyObj(out ho_RegionHeightSelected);
            HOperatorSet.GenEmptyObj(out ho_RegionAreaSelected);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion1);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion2);
            HOperatorSet.GenEmptyObj(out ho_RegionFinShell);

            HOperatorSet.GenEmptyObj(out ho_xldToCalHeight);
            HOperatorSet.GenEmptyObj(out ho_xldToCalWidth);
            HOperatorSet.GenEmptyObj(out ho_ho_RegionFinShellSelect);
            HOperatorSet.GenEmptyObj(out ho_ho_RegionFinShellSelectContours);

            HTuple hv_Area      = null;
            HTuple hv_CenterRow = null;
            HTuple hv_CenterCol = null;

            HTuple hv_Row     = null;
            HTuple hv_Column  = null;
            HTuple hv_Row2    = null;
            HTuple hv_Column2 = null;
            HTuple hv_Phi     = null;
            HTuple hv_Width   = null;
            HTuple hv_Height  = null;
            #endregion 定义

            try
            {
                #region 基础功能调用
                //if (BasicImageProcess(par, result, htResult, out ho_RegionReduced, out ho_Image, out width, out height))
                //{

                //}
                //else
                //{
                //    return result;
                //}
                #endregion 基础功能调用

                //获取图像预处理结果,图像是二值化后再进行处理
                ho_ResultPreprocess = result.g_ResultPreProcess.ImageResult.Ho_Image;

                #region 真实轮廓
                //string nameStdEdge = par.NameCellActualEdge;
                string nameStdEdge = "C9";
                /***** 得到当前片的平滑轮廓******/
                ResultRaisedEdge resultRaise = (ResultRaisedEdge)htResult[nameStdEdge];
                if (resultRaise == null)
                {
                    result.LevelError_e = LevelError_enum.OK;
                    result.Annotation   = par.NameCell.ToString() + ",当前片的平滑轮廓获取异常";
                    result.SetDefault();
                    return(result);
                }
                HObject ho_StdEdge = ((ImageAll)resultRaise.HtResultImage["C9FunRaisedEdge.RegionRemainingRemovedSmoothed"]).Ho_Image;

                #endregion 真实轮廓

                //以下为崩缺检查的算法
                //获取图像预处理结果,图像是二值化后再进行处理
                ho_ResultPreprocess = result.g_ResultPreProcess.ImageResult.Ho_Image;
                //通过残留检查平滑后的轮廓获取平行的ROI区域
                ho_RegionOuter.Dispose();
                ho_RegionInner.Dispose();
                ho_RegionInnerOuter.Dispose();
                GenParalRegionFromXld(ho_StdEdge, out ho_RegionOuter, out ho_RegionInnerOuter, out ho_RegionInner, par.Width_Paral, par.OuterStdShift_Paral, par.InnerStdShift_Paral);


                HObject ho_PreRegion = result.g_ResultPreProcess.resultBinary.RegionResult.Ho_Image;
                ho_RegionIntersected.Dispose();
                if (par.WorkingRegion == "Outer")//残留检测,选区为边缘外侧
                {
                    HOperatorSet.Intersection(ho_PreRegion, ho_RegionOuter, out ho_RegionIntersected);
                }
                else if (par.WorkingRegion == "Inner")//崩缺检测,选区为边缘内侧
                {
                    HOperatorSet.Intersection(ho_ResultPreprocess, ho_RegionInner, out ho_RegionIntersected);
                }
                else
                {
                    return(result);
                }
                HOperatorSet.CountObj(ho_RegionIntersected, out num_Obj);
                if (num_Obj == 0)
                {
                    result.LevelError_e = LevelError_enum.OK;
                    result.Annotation   = par.NameCell.ToString() + ",选区内无异常";
                    result.SetDefault();
                    return(result);
                }
                ho_RegionConnected.Dispose();
                HOperatorSet.Connection(ho_RegionIntersected, out ho_RegionConnected);
                ho_RegionFillUp.Dispose();
                HOperatorSet.FillUp(ho_RegionConnected, out ho_RegionFillUp);

                #region 开运算,闭运算
                ho_RegionOpening.Dispose();

                if (par.OpeningCircle != 0)
                {
                    HOperatorSet.OpeningCircle(ho_RegionFillUp, out ho_RegionOpening, par.OpeningCircle);
                }
                else
                {
                    ho_RegionOpening = ho_RegionFillUp.Clone();
                }
                HOperatorSet.CountObj(ho_RegionOpening, out num_Obj);
                if (num_Obj == 0)
                {
                    result.LevelError_e = LevelError_enum.OK;
                    result.Annotation   = par.NameCell.ToString() + ",开运算后异常点消失";
                    result.SetDefault();
                    return(result);
                }

                ho_RegionClosing.Dispose();
                if (par.ClosingCircle != 0)
                {
                    HOperatorSet.ClosingCircle(ho_RegionOpening, out ho_RegionClosing, par.ClosingCircle);
                }
                else
                {
                    ho_RegionClosing = ho_RegionOpening.Clone();
                }
                #endregion 开运算,闭运算

                //把贝壳宽度/高度/面积超出阈值的,都挑选出来
                ho_RegionWidthSelected.Dispose();
                ho_RegionHeightSelected.Dispose();
                ho_RegionAreaSelected.Dispose();
                HOperatorSet.SelectShape(ho_RegionClosing, out ho_RegionWidthSelected, "width", "and", par.MinWidth, par.MaxWidth);
                HOperatorSet.SelectShape(ho_RegionWidthSelected, out ho_RegionHeightSelected, "height", "and", par.MinHeight, par.MaxHeight);
                HOperatorSet.SelectShape(ho_RegionHeightSelected, out ho_RegionAreaSelected, "area", "and", par.MinArea, par.MaxArea);
                ho_RegionUnion1.Dispose();
                //HOperatorSet.Union2(ho_RegionWidthSelected, ho_RegionHeightSelected, out ho_RegionUnion1);
                ho_RegionUnion2.Dispose();
                //HOperatorSet.Union2(ho_RegionUnion1, ho_RegionAreaSelected, out ho_RegionUnion2);
                HOperatorSet.CountObj(ho_RegionAreaSelected, out num_Obj);
                if (num_Obj == 0)
                {
                    result.LevelError_e = LevelError_enum.OK;
                    result.Annotation   = par.NameCell.ToString() + ",区域特征提取后异常点消失";
                    result.SetDefault();
                    return(result);
                }
                //提取到的贝壳(Shell)OR残留(Fin)
                ho_RegionFinShell.Dispose();
                ho_RegionFinShell = ho_RegionAreaSelected.Clone();
                //HOperatorSet.Connection(ho_RegionUnion2, out ho_RegionFinShell);

                //对获取到的残留或者崩缺进行blob分析
                HOperatorSet.AreaCenter(ho_RegionFinShell, out hv_Area, out hv_CenterRow, out hv_CenterCol);
                double[] dblHeightArry = new double[hv_CenterRow.Length];//存放高度值的数组
                double[] dblWidthArry  = new double[hv_CenterRow.Length];

                #region 求取包络
                switch (par.SmallestSurround_e)
                {
                case SmallestSurround_enum.Rect2:
                    HOperatorSet.SmallestRectangle2(ho_RegionFinShell, out hv_Row, out hv_Column, out hv_Phi, out hv_Width, out hv_Height);

                    break;

                case SmallestSurround_enum.Circle:
                    HOperatorSet.SmallestCircle(ho_RegionFinShell, out hv_Row, out hv_Column, out hv_Width);
                    break;

                case SmallestSurround_enum.TanLineRect:
                    if (par.WorkingRegion == "Outer")    //残留检测,选区为边缘外侧
                    {
                        HeightCalUpper = par.OuterStdShift_Paral + par.Width_Paral * 1.5;
                        HOperatorSet.GenParallelContourXld(ho_StdEdge, out ho_xldToCalHeight, "regression_normal", HeightCalUpper);
                        HOperatorSet.GenParallelContourXld(ho_StdEdge, out ho_xldToCalWidth, "regression_normal", par.OuterStdShift_Paral);
                    }
                    else    //崩缺检测,选区为边缘内测
                    {
                        HeightCalUpper = par.InnerStdShift_Paral + par.Width_Paral * 1.5;
                        HOperatorSet.GenParallelContourXld(ho_StdEdge, out ho_xldToCalHeight, "regression_normal", -HeightCalUpper);
                        HOperatorSet.GenParallelContourXld(ho_StdEdge, out ho_xldToCalWidth, "regression_normal", -par.InnerStdShift_Paral);
                    }
                    for (int j = 0; j < hv_CenterRow.Length; j++)
                    {
                        try
                        {
                            HOperatorSet.SelectObj(ho_RegionFinShell, out ho_ho_RegionFinShellSelect, j + 1);
                            HOperatorSet.GenContourRegionXld(ho_ho_RegionFinShellSelect, out ho_ho_RegionFinShellSelectContours, "border");


                            //求残留区域和参考xld平行的XLD
                            //HObject ho_ContoursIntersected = null;
                            //HObject ho_TestImage = null;
                            //HObject ho_TestImageResult = null;
                            //HOperatorSet.GenImageConst(out ho_TestImage, "byte", width, height);
                            //HOperatorSet.PaintXld(ho_xldToCalHeight, ho_TestImage, out ho_TestImageResult, 255);
                            //HOperatorSet.PaintXld(ho_ho_RegionFinShellSelectContours, ho_TestImageResult, out ho_TestImageResult, 255);
                            //HOperatorSet.WriteImage(ho_TestImageResult, "bmp", 128, "E:\\DOC\\德龙\\0427测试\\XKY4.27\\TestImage"+j.ToString());



                            //计算残留高度
                            HOperatorSet.DistanceCcMin(ho_xldToCalHeight, ho_ho_RegionFinShellSelectContours, "fast_point_to_segment", out hv_disMin);
                            dblHeightArry[j] = Math.Round(HeightCalUpper - hv_disMin.D, 1);


                            HOperatorSet.IntersectionContoursXld(ho_xldToCalWidth, ho_ho_RegionFinShellSelectContours, "mutual", out hv_FinShellIntersectRow, out hv_FinShellIntersectCol, out hv_FinShellCircleRadius);

                            double   dblFinShellWidth = 0;
                            HTuple   hv_WidthTemp;
                            double[] IntersectPointRow = hv_FinShellIntersectRow.DArr;
                            double[] IntersectPointCol = hv_FinShellIntersectCol.DArr;
                            //求取边缘上最远的两个点的距离
                            for (int k = 0; k < hv_FinShellIntersectRow.Length - 1; k++)
                            {
                                for (int l = k + 1; l < hv_FinShellIntersectRow.Length; l++)
                                {
                                    HOperatorSet.DistancePp(IntersectPointRow[k], IntersectPointCol[k], IntersectPointRow[l], IntersectPointCol[l], out hv_WidthTemp);
                                    if (hv_WidthTemp.D > dblFinShellWidth)
                                    {
                                        dblFinShellWidth = hv_WidthTemp.D;
                                    }
                                }
                            }

                            //HOperatorSet.GenContourPolygonXld(out ho_ContoursIntersected, hv_FinShellIntersectRow, hv_FinShellIntersectCol);
                            //HOperatorSet.LengthXld(ho_ContoursIntersected, out FinShellWidth);

                            //计算残留宽度
                            dblWidthArry[j] = Math.Round(dblFinShellWidth, 1);
                        }
                        catch
                        {
                        }
                    }
                    break;

                default:    //默认矩形1
                    HOperatorSet.SmallestRectangle1(ho_RegionFinShell, out hv_Row, out hv_Column, out hv_Row2, out hv_Column2);
                    break;
                }



                #endregion 求取包络

                double x = 0;
                double y = 0;

                for (int j = 0; j < hv_CenterRow.Length; j++)
                {
                    #region 输出坐标类型
                    switch (par.TypeOutCoord)
                    {
                    case "面积中心":
                        x = Math.Round(hv_CenterCol.ToDArr()[j], 0);
                        y = Math.Round(hv_CenterRow.ToDArr()[j], 0);
                        break;

                    case "包络中心":
                        if (par.SmallestSurround_e == SmallestSurround_enum.Rect1)
                        {
                            x = Math.Round((hv_Column.ToDArr()[j] + hv_Column2.ToDArr()[j]) / 2, 3);
                            y = Math.Round((hv_Row.ToDArr()[j] + hv_Row2.ToDArr()[j]) / 2, 3);
                        }
                        else
                        {
                            x = Math.Round(hv_Column.ToDArr()[j], 3);
                            y = Math.Round(hv_Row.ToDArr()[j], 3);
                        }
                        break;
                    }
                    #endregion 输出坐标类型


                    result.X_L.Add(x);
                    result.Y_L.Add(y);
                    result.Area_L.Add(hv_Area.IArr[j]);//求取面积
                    result.Rectangularity_L.Add(0);
                    result.Circularity_L.Add(0);
                    #region 求取包络的集合
                    switch (par.SmallestSurround_e)
                    {
                    case SmallestSurround_enum.Rect2:
                        result.R_L.Add(Math.Round(hv_Phi.DArr[j], 5));         //求取角度
                        result.Height_L.Add(Math.Round(hv_Height.DArr[j], 3)); //获取矩形的长宽
                        result.Width_L.Add(Math.Round(hv_Width.DArr[j], 3));
                        result.Radius_L.Add(0);
                        break;

                    case SmallestSurround_enum.Circle:
                        result.Radius_L.Add(Math.Round(hv_Width.DArr[j], 3));
                        result.R_L.Add(0);
                        result.Height_L.Add(0);
                        result.Width_L.Add(0);
                        break;

                    case SmallestSurround_enum.TanLineRect:     //切线矩形,即为方向与xld切线平行方向的矩形
                        result.Radius_L.Add(0);
                        result.R_L.Add(0);
                        result.Height_L.Add(dblHeightArry[j]);
                        result.Width_L.Add(dblWidthArry[j]);
                        break;

                    default:    //默认矩形1
                        result.R_L.Add(0);
                        double rectWidth = (hv_Column2.IArr[j] - hv_Column.IArr[j]) / 2;
                        result.Width_L.Add(Math.Round(rectWidth, 3));
                        double rectHeight = (hv_Row2.IArr[j] - hv_Row.IArr[j]) / 2;
                        result.Height_L.Add(Math.Round(rectHeight, 3));
                        result.Radius_L.Add(0);
                        break;
                    }
                    #endregion 求取包络的集合
                }

                //区域个数
                result.Num = result.X_L.Count;
                if (result.Num == 0)
                {
                    result.LevelError_e = LevelError_enum.OK;
                    result.Annotation   = par.NameCell.ToString() + "FinShell个数为0";
                    result.SetDefault();
                }
                //添加显示
                AddDisplay(par.g_ParOutput, result);

                return(result);
            }
            catch (Exception ex)
            {
                return(result);
            }
            finally
            {
                //对结果进行综合处理
                SetComprehensiveResult(result, par, htResult, false);

                //校准
                DealCalibResult(par, result, htResult);

                #region 记录时间
                WriteRunTime(stopWatch, NameClass, par, result);
                #endregion 记录时间

                #region 记录

                RecordHoject(par, result, NameClass, "RegionReduced", ho_RegionReduced);
                RecordHoject(par, result, NameClass, "RegionInner", ho_RegionInner);
                RecordHoject(par, result, NameClass, "RegionOuter", ho_RegionOuter);
                RecordHoject(par, result, NameClass, "RegionInnerOuter", ho_RegionInnerOuter);

                RecordHoject(par, result, NameClass, "RegionIntersected", ho_RegionIntersected);
                RecordHoject(par, result, NameClass, "RegionConnected", ho_RegionConnected);
                RecordHoject(par, result, NameClass, "RegionFillUp", ho_RegionFillUp);

                RecordHoject(par, result, NameClass, "RegionOpening", ho_RegionOpening);
                RecordHoject(par, result, NameClass, "RegionClosing", ho_RegionClosing);
                RecordHoject(par, result, NameClass, "RegionWidthSelected", ho_RegionWidthSelected);

                RecordHoject(par, result, NameClass, "RegionHeightSelected", ho_RegionHeightSelected);
                RecordHoject(par, result, NameClass, "RegionAreaSelected", ho_RegionAreaSelected);
                RecordHoject(par, result, NameClass, "RegionUnion1", ho_RegionUnion1);

                RecordHoject(par, result, NameClass, "RegionUnion2", ho_RegionUnion2);
                RecordHoject(par, result, NameClass, "RegionFinShell", ho_RegionFinShell);
                #endregion 记录

                ho_xldToCalHeight.Dispose();
                ho_xldToCalWidth.Dispose();
                ho_ho_RegionFinShellSelect.Dispose();
                ho_ho_RegionFinShellSelectContours.Dispose();
            }
        }