public HRegion Process(HRegion region)
        {
            if (Width < 1 || Height < 1)
            {
                return(region.MoveRegion(0, 0));
            }

            var dilation = region.ErosionRectangle1(Width, Height);

            return(dilation);
        }
Ejemplo n.º 2
0
        public void ProcessStep(HImage imageGrabbed)
        {
            try
            {
                HTuple startTime = null;
                HTuple endTime   = null;
                HOperatorSet.CountSeconds(out startTime);
                int imageChannels = imageGrabbed.CountChannels();

                HImage rImg = null, gImg = null, bImg = null, rgbImg = null, irImg = null;

                if (imageChannels == 6)
                {
                    rImg   = imageGrabbed.Decompose4(out gImg, out bImg, out irImg);
                    rgbImg = rImg.Compose3(gImg, bImg);
                }

                HImage grayImage = new HImage();
                if (rgbImg == null)
                {
                    return;
                }

                imageGrabbed = rgbImg.CopyImage();

                int presentImageNoOfChannels = imageGrabbed.CountChannels();

                if (presentImageNoOfChannels == Properties.Settings.Default.NumberOfChannelsInColorImage)
                {
                    lock (this.ImageToBeSaved)
                    {
                        this.ImageToBeSaved = imageGrabbed.CopyImage();
                    }
                    if (whitebalancingStarted)
                    {
                        wbIterationCompletedEvent.Reset();
                    }
                    imageGrabbedEvent.Set();

                    HImage ho_R;
                    HImage ho_G;
                    HImage ho_B;

                    ho_R = imageGrabbed.Decompose3(out ho_G, out ho_B);

                    HTuple RAOIGrayVals  = Globals.GetGrayValuesOfLine(ho_R);
                    HTuple GAOIGrayVals  = Globals.GetGrayValuesOfLine(ho_G);
                    HTuple BAOIGrayVals  = Globals.GetGrayValuesOfLine(ho_B);
                    HTuple IRAOIGrayVals = Globals.GetGrayValuesOfLine(irImg);

                    currentWBData.Image = imageGrabbed;
                    currentWBData.GrayValues.RPlaneVals = RAOIGrayVals.ToDArr();
                    currentWBData.GrayValues.GPlaneVals = GAOIGrayVals.ToDArr();
                    currentWBData.GrayValues.BPlaneVals = BAOIGrayVals.ToDArr();
                    currentWBData.GrayValues.MPlaneVals = IRAOIGrayVals.ToDArr();

                    HImage ho_GrayImage;
                    ho_GrayImage = imageGrabbed.Rgb1ToGray();

                    HRegion whiteRegion = ho_GrayImage.Threshold(
                        Properties.Settings.Default.MinThresholdInDeterminingGain,
                        Properties.Settings.Default.MaxThresholdInDeterminingGain);
                    whiteRegion = whiteRegion.FillUp();
                    whiteRegion = whiteRegion.ErosionRectangle1(20, 20);

                    double rClipValue = 15.0;
                    double gClipValue = 15.0;
                    double bClipValue = 15.0;
                    //CalculateOptimumClipValue(whiteRegion, ho_R, out rClipValue);
                    //CalculateOptimumClipValue(whiteRegion, ho_G, out gClipValue);
                    //CalculateOptimumClipValue(whiteRegion, ho_B, out bClipValue);

                    double rMin, rMax, rRange;
                    double gMin, gMax, gRange;
                    double bMin, bMax, bRange;

                    ho_R.MinMaxGray(whiteRegion, rClipValue, out rMin, out rMax,
                                    out rRange);
                    ho_G.MinMaxGray(whiteRegion, gClipValue, out gMin, out gMax,
                                    out gRange);
                    ho_B.MinMaxGray(whiteRegion, bClipValue, out bMin, out bMax,
                                    out bRange);

                    double RGDiff = rMax - gMax;
                    double GBDiff = gMax - bMax;
                    double BRDiff = bMax - rMax;

                    currentWBData.ErrorLevel = (Math.Max(RGDiff, Math.Max(GBDiff, BRDiff)) / this.CameraAcquisition.CurrentCameraProperties.BrightRegionReferenceGrayLevel) * 100;
                    currentWBData.RedMax     = rMax;
                    currentWBData.GreenMax   = gMax;
                    currentWBData.BlueMax    = bMax;


                    HOperatorSet.CountSeconds(out endTime);
                    currentWBData.TimeTaken = (endTime - startTime).D;

                    UpdateControlUI();

                    wbIterationCompletedEvent.WaitOne();
                }
            }
            catch (Exception ex)
            {
                string errorMessage = "Exception occurred during white balancing step. ";
                errorMessage = errorMessage + " Error Message: " + ex.Message;
                MessageBox.Show(errorMessage, "Camera Setup Tool", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }