예제 #1
0
        /// <summary>
        /// LDH, 2017.06.04
        /// 현재 Display된 Image 저장하기
        /// </summary>
        public void SaveDisplayImage(string _DirectoryPath)
        {
            DateTime dateTime        = DateTime.Now;
            string   ImageSaveFolder = _DirectoryPath;

            if (false == Directory.Exists(ImageSaveFolder))
            {
                Directory.CreateDirectory(ImageSaveFolder);
            }
            ImageSaveFolder = String.Format("{0}\\{1:D4}\\{2:D2}\\{3:D2}", ImageSaveFolder, dateTime.Year, dateTime.Month, dateTime.Day);
            if (false == Directory.Exists(ImageSaveFolder))
            {
                Directory.CreateDirectory(ImageSaveFolder);
            }

            string ImageSaveFile;

            ImageSaveFile = String.Format("{0}\\{1:D2}{2:D2}{3:D2}{4:D3}.bmp", ImageSaveFolder, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond);

            try
            {
                ICogImage    _CogSaveImage = kCogDisplay.Image;
                CogImageFile _CogImageFile = new CogImageFile();

                if (_CogSaveImage == null)
                {
                    //MessageBox.Show(new Form{TopMost = true}, "영상이 없습니다.");
                }
                else
                {
                    _CogImageFile.Open(ImageSaveFile, CogImageFileModeConstants.Write);
                    _CogImageFile.Append(_CogSaveImage);
                    _CogImageFile.Close();
                }
            }
            catch
            {
                CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.ERR, "SetDisplayImage(string) Exception!!", CLogManager.LOG_LEVEL.LOW);
            }
        }
예제 #2
0
        private void ThreadProcess()
        {
            while (true)
            {
                if (runStart && processEndStatus)
                {
                    processEndStatus = false;
                    try
                    {
                        visionResult           = new VisionResult();
                        visionResult.StartTime = DateTime.Now;

                        //程序运行
                        acqFifoTool.Run();

                        if (acqFifoTool.OutputImage != null)
                        {
                            visionResult.InputImage = acqFifoTool.OutputImage;

                            processToolBlock.Inputs[0].Value = visionResult.InputImage;
                            processToolBlock.Run();

                            if (processToolBlock.RunStatus.Result == CogToolResultConstants.Accept)
                            {
                                CogCalibCheckerboardTool checkerboardTool = (CogCalibCheckerboardTool)processToolBlock.Tools[0];
                                visionResult.OutputImage   = checkerboardTool.OutputImage;
                                visionResult.cogRecord     = processToolBlock.CreateLastRunRecord();
                                visionResult.width1        = (double)processToolBlock.Outputs[0].Value;
                                visionResult.width2        = (double)processToolBlock.Outputs[1].Value;
                                visionResult.CoordX        = (double)processToolBlock.Outputs[4].Value;
                                visionResult.RunStatus     = true;
                                visionResult.RunStatusText = "OK";


                                //判断是否重复
                                if (Math.Abs(visionResult.CoordX - lastCoordX) < 0.05)
                                {
                                    recurCount++;
                                    if (recurCount > 9)
                                    {
                                        toolStrip1.Invoke(new Action(delegate
                                        {
                                            tsbStart_Click(null, null);
                                            MessageBox.Show(string.Format("检测到产品未移动,次数{0},自动停止运行,请适当挪动产品", recurCount));
                                        }));
                                    }
                                }
                                else
                                {
                                    recurCount = 0;
                                }
                                lastCoordX = visionResult.CoordX;


                                //判断处理
                                visionResult.ExamineStatus = true;
                            }
                            else
                            {
                                visionResult.OutputImage   = visionResult.InputImage;
                                visionResult.cogRecord     = null;
                                visionResult.RunStatusText = "未识别";
                                visionResult.RunStatus     = false;
                                visionResult.width1        = 999;
                                visionResult.width2        = 999;
                                visionResult.CoordX        = 0;
                            }



                            //保存原图图片
                            if (isSaveImage && visionResult.RunStatus)
                            {
                                visionResult.ImagePath = string.Format("{0}\\{2}\\{1}", imageSavePath, visionResult.ExamineStatus ? "OK" : "NG", visionResult.StartTime.ToString("yyMMdd"));
                                if (!Directory.Exists(visionResult.ImagePath))
                                {
                                    Directory.CreateDirectory(visionResult.ImagePath);
                                }
                                CogImageFile cogImageFile = new CogImageFile();
                                cogImageFile.Open(visionResult.ImagePath + "\\" + visionResult.StartTime.ToString("HHmmssfff") + ".bmp", CogImageFileModeConstants.Write);
                                cogImageFile.Append(visionResult.InputImage);
                                cogImageFile.Close();
                            }

                            crdResultImage.Invoke(new Action(delegate
                            {
                                crdResultImage.InteractiveGraphics.Clear();
                                crdResultImage.StaticGraphics.Clear();
                                crdResultImage.Image   = null;
                                crdResultImage.Image   = visionResult.OutputImage;
                                crdResultImage.Record  = visionResult.cogRecord;
                                lblRunStatus.Text      = visionResult.RunStatusText;
                                lblRunStatus.ForeColor = visionResult.RunStatus ? Color.Green : Color.Red;
                                lblWidth1.Text         = visionResult.width1.ToString("0.000");
                                lblWidth2.Text         = visionResult.width2.ToString("0.000");

                                //保存画线图
                                if (isSaveImage && visionResult.RunStatus && !visionResult.ExamineStatus)
                                {
                                    Bitmap crdImage = (Bitmap)crdResultImage.CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Image);
                                    crdImage.Save(visionResult.ImagePath + "\\crd_" + visionResult.StartTime.ToString("HHmmssfff") + ".jpeg", ImageFormat.Jpeg);
                                }
                            }));
                        }
                        else
                        {
                            CognexAreaCamera_CameraStatusChange(1, false);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("图片处理异常:" + ex);
                        tsbStart_Click(null, null);
                    }
                    processEndStatus = true;
                }
                if (!cameraStatus)
                {
                    acqFifoTool.Run();
                    if (acqFifoTool.RunStatus.Result == CogToolResultConstants.Accept)
                    {
                        CognexAreaCamera_CameraStatusChange(1, true);
                    }
                }

                Thread.Sleep(1);
            }
        }