Example #1
0
        private void ProcessDevice(Device device, Image <Rgb, byte> colorImage, Image <Gray, byte> grayscaleImage, int width, int height, ref Image <Rgb, byte> debugImage)
        {
            var deviceRoi = CalculateRoiFromNormalizedBounds(device.Area, colorImage);

            deviceRoi = deviceRoi.GetInflatedBy(RoiExpandFactor, colorImage.ROI);

            var imageRoi = colorImage.ROI;

            colorImage.ROI = deviceRoi;
            List <Point[]> quadrilaterals;
            var            markers = GetMarkers(ref colorImage, deviceRoi, width, height, ref debugImage, out quadrilaterals);

            colorImage.ROI = imageRoi;

            var grayscaleImageRoi = grayscaleImage.ROI;

            grayscaleImage.ROI = deviceRoi;

            var i = 0;

            foreach (var marker in markers)
            {
                grayscaleImage.FillConvexPoly(quadrilaterals[i], Grays.White);

                var display = FindDisplayInImage(ref grayscaleImage, deviceRoi, width, height, marker, ref debugImage);

                if (display != null)
                {
                    if (IsRenderContent && IsFindDisplayContiuously)
                    {
                        var debugImageRoi = debugImage.ROI;
                        debugImage.ROI = deviceRoi;

                        var enclosingRectangle = display.EnclosingRectangle;
                        DrawEdge(ref debugImage, enclosingRectangle.LongEdge, Rgbs.Red);
                        DrawEdge(ref debugImage, enclosingRectangle.ShortEdge, Rgbs.Green);

                        debugImage.ROI = debugImageRoi;
                    }

                    DisplaySample displaySample;
                    if (_blobFoundInRgbImage.ContainsKey(device.BlobId))
                    {
                        displaySample = _blobFoundInRgbImage[device.BlobId];
                    }
                    else
                    {
                        displaySample = new DisplaySample();
                        _blobFoundInRgbImage.Add(device.BlobId, displaySample);
                    }

                    if (displaySample.NeedsSample())
                    {
                        displaySample.Sample(display.EnclosingRectangle);
                    }
                    else
                    {
                        _blobFoundInRgbImage.Remove(device.BlobId);
                        display.EnclosingRectangle = displaySample.GetBestSample();

                        Stage(display);
                    }

                    //Stage(display);
                }

                i++;
            }

            grayscaleImage.ROI = grayscaleImageRoi;
        }
Example #2
0
        private void ProcessDevice(Device device, Image<Rgb, byte> colorImage, Image<Gray, byte> grayscaleImage, int width, int height, ref Image<Rgb, byte> debugImage)
        {
            var deviceRoi = CalculateRoiFromNormalizedBounds(device.Area, colorImage);
            deviceRoi = deviceRoi.GetInflatedBy(RoiExpandFactor, colorImage.ROI);

            var imageRoi = colorImage.ROI;
            colorImage.ROI = deviceRoi;
            List<Point[]> quadrilaterals;
            var markers = GetMarkers(ref colorImage, deviceRoi, width, height, ref debugImage, out quadrilaterals);
            colorImage.ROI = imageRoi;

            var grayscaleImageRoi = grayscaleImage.ROI;
            grayscaleImage.ROI = deviceRoi;

            var i = 0;
            foreach (var marker in markers)
            {
                grayscaleImage.FillConvexPoly(quadrilaterals[i], Grays.White);

                var display = FindDisplayInImage(ref grayscaleImage, deviceRoi, width, height, marker, ref debugImage);

                if (display != null)
                {
                    if (IsRenderContent && IsFindDisplayContiuously)
                    {
                        var debugImageRoi = debugImage.ROI;
                        debugImage.ROI = deviceRoi;

                        var enclosingRectangle = display.EnclosingRectangle;
                        DrawEdge(ref debugImage, enclosingRectangle.LongEdge, Rgbs.Red);
                        DrawEdge(ref debugImage, enclosingRectangle.ShortEdge, Rgbs.Green);

                        debugImage.ROI = debugImageRoi;
                    }

                    DisplaySample displaySample;
                    if (_blobFoundInRgbImage.ContainsKey(device.BlobId))
                    {
                        displaySample = _blobFoundInRgbImage[device.BlobId];
                    }
                    else
                    {
                        displaySample = new DisplaySample();
                        _blobFoundInRgbImage.Add(device.BlobId, displaySample);
                    }

                    if (displaySample.NeedsSample())
                    {
                        displaySample.Sample(display.EnclosingRectangle);
                    }
                    else
                    {
                        _blobFoundInRgbImage.Remove(device.BlobId);
                        display.EnclosingRectangle = displaySample.GetBestSample();

                        Stage(display);
                    }

                    //Stage(display);
                }

                i++;
            }

            grayscaleImage.ROI = grayscaleImageRoi;
        }