//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HLRun(System.Drawing.Bitmap bipmapImage, out CResultData objResultData)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try
                {
                    m_objImageProcess.InputImage = new CogImage8Grey(bipmapImage);
                    m_objImageProcess.Run();
                    CogImage8Grey objResultImage = ( CogImage8Grey )m_objImageProcess.OutputImage;
                    objResultData.bitmapResultImage = objResultImage.ToBitmap();
                }
                catch (System.Exception ex)
                {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    MakeErrorMessage("HLRun", 5505, ex.Message);
                    break;
                }

                bReturn = true;
            } while(false);

            objResultData.bitmapInputImage = null;//bipmapImage;
            objResultData.bResult          = bReturn;
            objResultData.eLibrary         = CResultData.enumLibrary.IMAGEPROCESS;
            m_objResultData = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
Exemplo n.º 2
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //수정 :
        //목적 : Run
        //설명 :
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override bool HLRun(System.Drawing.Bitmap bipmapImage, out CResultData objResultData)
        {
            objResultData = new CResultData();
            bool bReturn = false;

            do
            {
                try
                {
                    m_objCalibration.InputImage = new CogImage8Grey(bipmapImage);
                    m_objCalibration.Run();
                    CogImage8Grey objResultImage = ( CogImage8Grey )m_objCalibration.OutputImage;
                    if (null == objResultImage)
                    {
                        objResultData.bitmapResultImage = (System.Drawing.Bitmap)bipmapImage.Clone();
                        //break;
                    }
                    else
                    {
                        objResultData.bitmapResultImage = objResultImage.ToBitmap();
                    }
                }
                catch (System.Exception ex)
                {
                    Trace.Write(ex.Message + "-> " + ex.StackTrace);
                    MakeErrorMessage("HLRun", 5505, ex.Message);
                    break;
                }

                bReturn = true;
            } while(false);

            if (null != bipmapImage)
            {
                objResultData.bitmapInputImage = null;// bipmapImage;
            }
            objResultData.bResult  = bReturn;
            objResultData.eLibrary = CResultData.enumLibrary.CALIBRATION;;
            m_objResultData        = ( CResultData )objResultData.Clone();
            return(bReturn);
        }
Exemplo n.º 3
0
        public bool GrabManualWithFile(string fileName)
        {
            bool status = GrabManual(true);

            if (status)
            {
                try
                {
                    GrabTime = DateTime.Now;
                    Bitmap bitmap = new Bitmap(grabImage.ToBitmap());

                    int  retryCnt = 0;
                    bool done     = false;
                    while (!done)
                    {
                        try
                        {
                            bitmap.Save(fileName);
                            done = true;
                        }
                        catch
                        {
                            Thread.Sleep(1);
                            retryCnt++;
                            if (retryCnt > 5)
                            {
                                throw;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not save image to disk. Original error: " + ex.Message);
                    status = false;
                }
            }

            return(status);
        }
Exemplo n.º 4
0
        public void MainTaskThread()
        {
            int count = 0;

            double constX = 0;
            double constY = 0;

            while (flag)
            {
                CogImage8Grey image = new CogImage8Grey();
                image = camControl.CamGrab();

                if (image == null)
                {
                    continue;
                }

                blob.InputImage = image;
                blob.Run();
                double xxx = 0;
                double yyy = 0;
                if (blob.Results.GetBlobs().Count != 0)
                {
                    xxx = blob.Results.GetBlobs()[0].CenterOfMassX;
                    yyy = blob.Results.GetBlobs()[0].CenterOfMassY;
                }

                CogRecord record = new CogRecord();
                record.SubRecords.Add(blob.CreateLastRunRecord().SubRecords[0]);

                if (count < 10)
                {
                    constX += xxx;
                    constY += yyy;

                    Dispatcher.Invoke(new Action(() =>
                    {
                        MinX_textBox.Text = xxx.ToString();
                        MaxX_textBox.Text = xxx.ToString();
                        MinY_textBox.Text = yyy.ToString();
                        MaxY_textBox.Text = yyy.ToString();
                    }));
                }
                else if (count == 10)
                {
                    constX = constX / 10;
                    constY = constY / 10;

                    Dispatcher.Invoke(new Action(() =>
                    {
                        StdX_textBox.Text = constX.ToString();
                        StdY_textBox.Text = constY.ToString();
                        MinX_textBox.Text = xxx.ToString();
                        MaxX_textBox.Text = xxx.ToString();
                        MinY_textBox.Text = yyy.ToString();
                        MaxY_textBox.Text = yyy.ToString();
                    }));
                }
                else if (count % 60 == 0)
                {
                    var bmp8bpp = Grayscale.CommonAlgorithms.BT709.Apply(image.ToBitmap());
                    bmp8bpp.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SavedImages\Routine_SavedImage-" + DateTime.Now.ToString("yyyy_MM_dd-HH_mm_ss") + ".bmp", ImageFormat.Bmp);

                    Dispatcher.Invoke(new Action(() => {
                        double minx = double.Parse(MinX_textBox.Text);
                        double miny = double.Parse(MinY_textBox.Text);
                        double maxx = double.Parse(MaxX_textBox.Text);
                        double maxy = double.Parse(MaxY_textBox.Text);

                        if (xxx < minx)
                        {
                            MinX_textBox.Text = xxx.ToString();
                        }
                        if (yyy < miny)
                        {
                            MinY_textBox.Text = yyy.ToString();
                        }
                        if (xxx > maxx)
                        {
                            MaxX_textBox.Text = xxx.ToString();
                        }
                        if (yyy > maxy)
                        {
                            MaxY_textBox.Text = yyy.ToString();
                        }
                    }));
                }
                else
                {
                    Dispatcher.Invoke(new Action(() => {
                        if (Math.Abs(constX - xxx) >= 0.5 || Math.Abs(constY - yyy) >= 0.5)
                        {
                            int a = (int.Parse(AbnormalCount_textBox.Text) + 1);
                            AbnormalCount_textBox.Text = a.ToString();
                        }
                        var bmp8bpp = Grayscale.CommonAlgorithms.BT709.Apply(image.ToBitmap());
                        bmp8bpp.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SavedImages\NG_SavedImage-" + DateTime.Now.ToString("yyyy_MM_dd-HH_mm_ss") + ".bmp", ImageFormat.Bmp);

                        double minx = double.Parse(MinX_textBox.Text);
                        double miny = double.Parse(MinY_textBox.Text);
                        double maxx = double.Parse(MaxX_textBox.Text);
                        double maxy = double.Parse(MaxY_textBox.Text);

                        if (xxx < minx)
                        {
                            MinX_textBox.Text = xxx.ToString();
                        }
                        if (yyy < miny)
                        {
                            MinY_textBox.Text = yyy.ToString();
                        }
                        if (xxx > maxx)
                        {
                            MaxX_textBox.Text = xxx.ToString();
                        }
                        if (yyy > maxy)
                        {
                            MaxY_textBox.Text = yyy.ToString();
                        }
                    }));
                }

                count++;
                Dispatcher.Invoke(new Action(() => {
                    TotalCount_textBox.Text = count.ToString();
                    display.Image           = image;
                    display.Record          = record;
                    display.Fit();
                }));

                TextWriter tw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\SavedLog.csv", true);
                tw.WriteLine(count + "," + xxx + "," + yyy + "," + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss"));
                tw.Close();
                Thread.Sleep(900);
            }
        }