예제 #1
0
        public List <video.VideoProg.Cub> getImageColor(List <HSLFiltering> lst)
        {
            UnmanagedImage             tmpCol = null;
            List <video.VideoProg.Cub> tmp    = new List <video.VideoProg.Cub>();

            for (int i = 0; i < lst.Count; i++)
            {
                HSLFiltering Filter = lst[i];
                tmpCol = ImgColor.Clone();
                Filter.ApplyInPlace(tmpCol);

                // create blob counter and configure it
                BlobCounter blobCounter1 = new BlobCounter();
                blobCounter1.MinWidth     = 15;                // set minimum size of
                blobCounter1.MinHeight    = 15;                // objects we look for
                blobCounter1.FilterBlobs  = true;              // filter blobs by size
                blobCounter1.ObjectsOrder = ObjectsOrder.Size; // order found object by size

                blobCounter1.ProcessImage(tmpCol);
                //Rectangle[] rects = DeleteRectInterne( blobCounter1.GetObjectsRectangles());
                Rectangle[] rects = blobCounter1.GetObjectsRectangles();
                // draw rectangle around the biggest blob
                for (int j = 0; j < rects.Length; j++)
                {
                    if (rects[j] == null)
                    {
                        break;
                    }
                    tmp.Add(new video.VideoProg.Cub(rects[j], i));
                }
            }
            ImgColor = tmpCol;
            return(tmp);
        }
예제 #2
0
        private void ProcessFrameByRefindedMethod()
        {
            ++_frameCount;

            UnmanagedImage sourceCopy = _currentUnprocessed.Clone();

            _currentProcessed = _preprocessingFilters.Apply(sourceCopy);

            if (_previousProcessed != null && _featureRegion != null)
            {
                // track the feature
                _featureRegion.TrackFeature(_currentProcessed);

                // update cursor position
                UpdateCursor();

                // draw feature region
                Rectangle rect = new Rectangle(_featureRegion.Location.ToGDIPoint(), _featureRegion.Size);
                if (_featureRegion.IsLost)
                {
                    Drawing.Rectangle(sourceCopy, rect, Color.Red);
                }
                else
                {
                    Drawing.Rectangle(sourceCopy, rect, Color.Green);
                }

                RegionPictureBox.Image          = _featureRegion.FeatureImage.ToManagedImage();
                Invoke(() => AccuracyLabel.Text = string.Format("Last detection accuracy: {0:F4}", _featureRegion.Accuracy));
            }

            _previousProcessed = _currentProcessed;

            ImageBox.Image = sourceCopy.ToManagedImage();
        }
예제 #3
0
        public static UnmanagedImage Lab2Rgb([NotNull] UnmanagedImage image, bool useCopy = true)
        {
            SupportedImages.CheckFormat(image);
            var result = useCopy ? image.Clone() : image;

            Lab2Rgb(image, result);
            return(result);
        }
        protected override void ProcessFilter(UnmanagedImage image)
        {
            UnmanagedImage image2 = image.Clone();

            this.closing.ApplyInPlace(image);
            this.subtract.UnmanagedOverlayImage = image2;
            this.subtract.ApplyInPlace(image);
            image2.Dispose();
        }
예제 #5
0
        protected override void ProcessFilter(UnmanagedImage image)
        {
            UnmanagedImage unmanagedImage = image.Clone();

            closing.ApplyInPlace(image);
            subtract.UnmanagedOverlayImage = unmanagedImage;
            subtract.ApplyInPlace(image);
            unmanagedImage.Dispose();
        }
예제 #6
0
        private void ImageBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (_regionSelectionMode)
            {
                _selectedRegion = new Rectangle(_selectedRegion.Location, new Size(e.X - _selectedRegion.X, e.Y - _selectedRegion.Y));

                UnmanagedImage img = _currentProcessed.Clone();
                Drawing.Rectangle(img, _selectedRegion, Color.White);

                ImageBox.Image = img.ToManagedImage();
            }
        }
예제 #7
0
        public void homographie(List <IntPoint> LimiteTerain, bool imgCol)
        {
            /* AFORGE => OK Mais long
             * UnImgReel = UnmanagedImage.FromManagedImage(imgReel);
             *
             * // Remplacement de l'image par le terain détecte dedans
             * if (LimiteTerain.Count == 4)
             * {
             *   QuadrilateralTransformation quadrilateralTransformation = new QuadrilateralTransformation(LimiteTerain, UnImgReel.Width, UnImgReel.Height);
             *   UnImgReel = quadrilateralTransformation.Apply(UnImgReel);
             * }
             */

            if (LimiteTerain.Count == 4)
            {
                int wid = max(LimiteTerain[0].X, LimiteTerain[1].X, LimiteTerain[2].X, LimiteTerain[3].X) - min(LimiteTerain[0].X, LimiteTerain[1].X, LimiteTerain[2].X, LimiteTerain[3].X);
                int hei = max(LimiteTerain[0].Y, LimiteTerain[1].Y, LimiteTerain[2].Y, LimiteTerain[3].Y) - min(LimiteTerain[0].Y, LimiteTerain[1].Y, LimiteTerain[2].Y, LimiteTerain[3].Y);

                Image <Bgr, Byte> a    = new Image <Bgr, byte>(wid, hei);
                PointF[]          pts1 = new PointF[4];
                PointF[]          pts2 = new PointF[4];

                pts1[0] = new PointF(0, 0);
                pts1[1] = new PointF(wid, 0);
                pts1[3] = new PointF(wid, hei);
                pts1[2] = new PointF(0, hei);

                pts2[0] = new PointF(LimiteTerain[0].X, LimiteTerain[0].Y);
                pts2[1] = new PointF(LimiteTerain[1].X, LimiteTerain[1].Y);
                pts2[3] = new PointF(LimiteTerain[2].X, LimiteTerain[2].Y);
                pts2[2] = new PointF(LimiteTerain[3].X, LimiteTerain[3].Y);

                homography = CameraCalibration.GetPerspectiveTransform(pts2, pts1);
                MCvScalar s = new MCvScalar(0, 0, 0);

                //CvInvoke.cvFindHomography(matSource, matDest, homography, Emgu.CV.CvEnum.HOMOGRAPHY_METHOD.DEFAULT, 3.0, maskMat);
                CvInvoke.cvWarpPerspective(imgRecu, a, homography, (int)Emgu.CV.CvEnum.INTER.CV_INTER_NN, s);
                // CvInvoke.cvWarpAffine(imgRecu, a, homography, (int)Emgu.CV.CvEnum.INTER.CV_INTER_NN, s);

                imgRecu   = a;
                UnImgReel = UnmanagedImage.FromManagedImage(a.ToBitmap());
            }
            else
            {
                UnImgReel = UnmanagedImage.FromManagedImage(imgReel);
            }


            if (imgCol)
            {
                ImgColor = UnImgReel.Clone();
            }
        }
예제 #8
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        ///
        /// <param name="image">Source image data.</param>
        ///
        protected override unsafe void ProcessFilter(UnmanagedImage image)
        {
            // copy source image
            UnmanagedImage sourceImage = image.Clone( );

            // perform closing on the source image
            closing.ApplyInPlace(image);
            // subtract source image from the closed image
            subtract.UnmanagedOverlayImage = sourceImage;
            subtract.ApplyInPlace(image);

            sourceImage.Dispose( );
        }
        /// <summary>
        ///   Process the filter on the specified image.
        /// </summary>
        ///
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        ///
        protected unsafe override void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData)
        {
            int         width     = sourceData.Width;
            int         height    = sourceData.Height;
            PixelFormat format    = sourceData.PixelFormat;
            int         pixelSize = System.Drawing.Bitmap.GetPixelFormatSize(format) / 8;

            sourceData.Clone();

            UnmanagedImage temp = UnmanagedImage.Create(width, height, format);

            int lineWidth = width * pixelSize;

            int srcStride = temp.Stride;
            int srcOffset = srcStride - lineWidth;
            int dstStride = destinationData.Stride;
            int dstOffset = dstStride - lineWidth;

            byte *srcStart = (byte *)temp.ImageData.ToPointer();
            byte *dstStart = (byte *)destinationData.ImageData.ToPointer();


            // first
            Convolution c = new Convolution(masks[0]);

            c.Apply(sourceData, destinationData);

            // others
            for (int i = 1; i < masks.Length; i++)
            {
                c.Kernel = masks[i];
                c.Apply(sourceData, temp);

                byte *src = srcStart;
                byte *dst = dstStart;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < lineWidth; x++, src++, dst++)
                    {
                        if (*src > *dst)
                        {
                            *dst = *src;
                        }
                    }

                    dst += dstOffset;
                    src += srcOffset;
                }
            }
        }
예제 #10
0
        private void ProcessFrame()
        {
            _currentPreprocessedImage = _preprocessingFilters.Apply(_currentSourceImage);

            UnmanagedImage sourceCopy = _currentSourceImage.Clone();
            UnmanagedImage output     = UnmanagedImage.Create(sourceCopy.Width, sourceCopy.Height, sourceCopy.PixelFormat);

            if (_previousPreprocessedImage != null)
            {
                //output = _lucasKanade.ShowDerivative(preprocessed, _previous, LucasKanade.DerivativeComponent.X);

                #region Point tracking
                Point centroid = new Point();
                for (int i = 0; i < _trackingPoints.Count; ++i)
                {
                    Point point    = _trackingPoints[i];
                    Point velocity = _tracker.CalculateVelocity(_currentPreprocessedImage, _previousPreprocessedImage, point.Round());

                    UpdatePointPosition(i, velocity);

                    centroid += _trackingPoints[i] / _trackingPoints.Count;

                    Drawing.Rectangle(sourceCopy, new Rectangle((int)point.X - 2, (int)point.Y - 2, 5, 5), Color.Yellow);
                }

                Drawing.Rectangle(sourceCopy, new Rectangle((int)centroid.X - 3, (int)centroid.Y - 3, 7, 7), Color.Red);
                #endregion

                DrawVelocityMap(output);
            }

            _previousPreprocessedImage = _currentPreprocessedImage;

            SourcePictureBox.Image       = sourceCopy.ToManagedImage();
            PreprocessedPictureBox.Image = _currentPreprocessedImage.ToManagedImage();
            if (output != null)
            {
                OutputPictureBox.Image = output.ToManagedImage();
            }
        }
예제 #11
0
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            UnmanagedImage copy = image.Clone();

            int w = copy.Width;
            int h = copy.Height;

            byte *copyPtr  = (byte *)copy.ImageData.ToPointer();
            byte *imagePtr = (byte *)image.ImageData.ToPointer();

            int stride = copy.Stride;
            int offset = stride - w;

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++, copyPtr++, imagePtr++)
                {
                    if (i == 0 || j == 0 || i == h - 1 || j == w - 1)
                    {
                        continue;
                    }

                    byte up    = *(copyPtr - stride);
                    byte left  = *(copyPtr - 1);
                    byte right = *(copyPtr + 1);
                    byte down  = *(copyPtr + stride);

                    if (up != 0 && left != 0 && right != 0 && down != 0)
                    {
                        *imagePtr = 0;
                    }
                }

                imagePtr += offset;
                copyPtr  += offset;
            }
        }
예제 #12
0
        /// <summary>
        /// Perform color dithering for the specified image.
        /// </summary>
        ///
        /// <param name="sourceImage">Source image to do color dithering for.</param>
        ///
        /// <returns>Returns color dithered image. See <see cref="ColorTable"/> for information about format of
        /// the result image.</returns>
        ///
        /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image. It must 24 or 32 bpp color image.</exception>
        ///
        public Bitmap Apply(UnmanagedImage sourceImage)
        {
            if ((sourceImage.PixelFormat != PixelFormat.Format24bppRgb) &&
                (sourceImage.PixelFormat != PixelFormat.Format32bppRgb) &&
                (sourceImage.PixelFormat != PixelFormat.Format32bppArgb) &&
                (sourceImage.PixelFormat != PixelFormat.Format32bppPArgb))
            {
                throw new UnsupportedImageFormatException("Unsupported pixel format of the source image.");
            }

            cache.Clear( );

            // make a copy of the original image
            UnmanagedImage source = sourceImage.Clone( );

            // get image size
            width     = sourceImage.Width;
            height    = sourceImage.Height;
            stride    = sourceImage.Stride;
            pixelSize = Bitmap.GetPixelFormatSize(sourceImage.PixelFormat) / 8;

            int offset = stride - width * pixelSize;

            // create destination image
            Bitmap destImage = new Bitmap(width, height, (colorTable.Length > 16) ?
                                          PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed);
            // and init its palette
            ColorPalette cp = destImage.Palette;

            for (int i = 0, n = colorTable.Length; i < n; i++)
            {
                cp.Entries[i] = colorTable[i];
            }
            destImage.Palette = cp;

            // lock destination image
            BitmapData destData = destImage.LockBits(new Rectangle(0, 0, width, height),
                                                     ImageLockMode.ReadWrite, destImage.PixelFormat);

            // pixel values
            int r, g, b;

            // do the job
            unsafe
            {
                byte *ptr     = (byte *)source.ImageData.ToPointer( );
                byte *dstBase = (byte *)destData.Scan0.ToPointer( );
                byte  colorIndex;

                bool is8bpp = (colorTable.Length > 16);

                // for each line
                for (y = 0; y < height; y++)
                {
                    byte *dst = dstBase + y * destData.Stride;

                    // for each pixels
                    for (x = 0; x < width; x++, ptr += pixelSize)
                    {
                        r = ptr[RGB.R];
                        g = ptr[RGB.G];
                        b = ptr[RGB.B];

                        // get color from palette, which is the closest to current pixel's value
                        Color closestColor = GetClosestColor(r, g, b, out colorIndex);

                        // do error diffusion
                        Diffuse(r - closestColor.R, g - closestColor.G, b - closestColor.B, ptr);

                        // write color index as pixel's value to destination image
                        if (is8bpp)
                        {
                            *dst = colorIndex;
                            dst++;
                        }
                        else
                        {
                            if (x % 2 == 0)
                            {
                                *dst |= (byte)(colorIndex << 4);
                            }
                            else
                            {
                                *dst |= (colorIndex);
                                dst++;
                            }
                        }
                    }
                    ptr += offset;
                }
            }

            destImage.UnlockBits(destData);
            source.Dispose( );

            return(destImage);
        }
예제 #13
0
        public unsafe Bitmap Apply(UnmanagedImage sourceImage)
        {
            if (((sourceImage.PixelFormat != PixelFormat.Format24bppRgb) && (sourceImage.PixelFormat != PixelFormat.Format32bppRgb)) && ((sourceImage.PixelFormat != PixelFormat.Format32bppArgb) && (sourceImage.PixelFormat != PixelFormat.Format32bppPArgb)))
            {
                throw new UnsupportedImageFormatException("Unsupported pixel format of the source image.");
            }
            this.cache.Clear();
            UnmanagedImage image = sourceImage.Clone();

            this.width     = sourceImage.Width;
            this.height    = sourceImage.Height;
            this.stride    = sourceImage.Stride;
            this.pixelSize = Image.GetPixelFormatSize(sourceImage.PixelFormat) / 8;
            int          num     = this.stride - (this.width * this.pixelSize);
            Bitmap       bitmap  = new Bitmap(this.width, this.height, (this.colorTable.Length > 0x10) ? PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed);
            ColorPalette palette = bitmap.Palette;
            int          index   = 0;
            int          length  = this.colorTable.Length;

            while (index < length)
            {
                palette.Entries[index] = this.colorTable[index];
                index++;
            }
            bitmap.Palette = palette;
            BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, this.width, this.height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            byte *     ptr        = (byte *)image.ImageData.ToPointer();
            byte *     numPtr2    = (byte *)bitmapdata.Scan0.ToPointer();
            bool       flag       = this.colorTable.Length > 0x10;

            this.y = 0;
            while (this.y < this.height)
            {
                byte *numPtr3 = numPtr2 + (this.y * bitmapdata.Stride);
                this.x = 0;
                while (this.x < this.width)
                {
                    byte  num7;
                    int   red   = ptr[2];
                    int   green = ptr[1];
                    int   blue  = ptr[0];
                    Color color = this.GetClosestColor(red, green, blue, out num7);
                    this.Diffuse(red - color.R, green - color.G, blue - color.B, ptr);
                    if (flag)
                    {
                        numPtr3[0] = num7;
                        numPtr3++;
                    }
                    else if ((this.x % 2) == 0)
                    {
                        numPtr3[0] = (byte)(numPtr3[0] | ((byte)(num7 << 4)));
                    }
                    else
                    {
                        numPtr3[0] = (byte)(numPtr3[0] | num7);
                        numPtr3++;
                    }
                    this.x++;
                    ptr += this.pixelSize;
                }
                ptr += num;
                this.y++;
            }
            bitmap.UnlockBits(bitmapdata);
            image.Dispose();
            return(bitmap);
        }
예제 #14
0
        public unsafe Bitmap Apply(UnmanagedImage sourceImage)
        {
            if (sourceImage.PixelFormat != PixelFormat.Format24bppRgb && sourceImage.PixelFormat != PixelFormat.Format32bppRgb && sourceImage.PixelFormat != PixelFormat.Format32bppArgb && sourceImage.PixelFormat != PixelFormat.Format32bppPArgb)
            {
                throw new UnsupportedImageFormatException("Unsupported pixel format of the source image.");
            }
            cache.Clear();
            UnmanagedImage unmanagedImage = sourceImage.Clone();

            width     = sourceImage.Width;
            height    = sourceImage.Height;
            stride    = sourceImage.Stride;
            pixelSize = System.Drawing.Image.GetPixelFormatSize(sourceImage.PixelFormat) / 8;
            int          num     = stride - width * pixelSize;
            Bitmap       bitmap  = new Bitmap(width, height, (colorTable.Length > 16) ? PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed);
            ColorPalette palette = bitmap.Palette;
            int          i       = 0;

            for (int num2 = colorTable.Length; i < num2; i++)
            {
                palette.Entries[i] = colorTable[i];
            }
            bitmap.Palette = palette;
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            byte *     ptr        = (byte *)unmanagedImage.ImageData.ToPointer();
            byte *     ptr2       = (byte *)bitmapData.Scan0.ToPointer();
            bool       flag       = colorTable.Length > 16;

            for (y = 0; y < height; y++)
            {
                byte *ptr3 = ptr2 + (long)y * (long)bitmapData.Stride;
                x = 0;
                while (x < width)
                {
                    int   num3 = ptr[2];
                    int   num4 = ptr[1];
                    int   num5 = *ptr;
                    byte  colorIndex;
                    Color closestColor = GetClosestColor(num3, num4, num5, out colorIndex);
                    Diffuse(num3 - closestColor.R, num4 - closestColor.G, num5 - closestColor.B, ptr);
                    if (flag)
                    {
                        *ptr3 = colorIndex;
                        ptr3++;
                    }
                    else if (x % 2 == 0)
                    {
                        byte *intPtr = ptr3;
                        *     intPtr = (byte)(*intPtr | (byte)(colorIndex << 4));
                    }
                    else
                    {
                        byte *intPtr2 = ptr3;
                        *     intPtr2 = (byte)(*intPtr2 | colorIndex);
                        ptr3++;
                    }
                    x++;
                    ptr += pixelSize;
                }
                ptr += num;
            }
            bitmap.UnlockBits(bitmapData);
            unmanagedImage.Dispose();
            return(bitmap);
        }
        /// <summary>
        /// Perform color dithering for the specified image.
        /// </summary>
        /// 
        /// <param name="sourceImage">Source image to do color dithering for.</param>
        /// 
        /// <returns>Returns color dithered image. See <see cref="ColorTable"/> for information about format of
        /// the result image.</returns>
        /// 
        /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image. It must 24 or 32 bpp color image.</exception>
        /// 
        public Bitmap Apply( UnmanagedImage sourceImage )
        {
            if ( ( sourceImage.PixelFormat != PixelFormat.Format24bppRgb ) &&
                 ( sourceImage.PixelFormat != PixelFormat.Format32bppRgb ) &&
                 ( sourceImage.PixelFormat != PixelFormat.Format32bppArgb ) &&
                 ( sourceImage.PixelFormat != PixelFormat.Format32bppPArgb ) )
            {
                throw new UnsupportedImageFormatException( "Unsupported pixel format of the source image." );
            }

            cache.Clear( );

            // make a copy of the original image
            UnmanagedImage source = sourceImage.Clone( );

            // get image size
            width  = sourceImage.Width;
            height = sourceImage.Height;
            stride = sourceImage.Stride;
            pixelSize = Bitmap.GetPixelFormatSize( sourceImage.PixelFormat ) / 8;

            int offset = stride - width * pixelSize;

            // create destination image
            Bitmap destImage = new Bitmap( width, height, ( colorTable.Length > 16 ) ?
                PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed );
            // and init its palette
            ColorPalette cp = destImage.Palette;
            for ( int i = 0, n = colorTable.Length; i < n; i++ )
            {
                cp.Entries[i] = colorTable[i];
            }
            destImage.Palette = cp;

            // lock destination image
            BitmapData destData = destImage.LockBits( new Rectangle( 0, 0, width, height ),
                ImageLockMode.ReadWrite, destImage.PixelFormat );

            // pixel values
            int r, g, b;

            // do the job
            unsafe
            {
                byte* ptr = (byte*) source.ImageData.ToPointer( );
                byte* dstBase = (byte*) destData.Scan0.ToPointer( );
                byte colorIndex;

                bool is8bpp = ( colorTable.Length > 16 );

                // for each line
                for ( y = 0; y < height; y++ )
                {
                    byte* dst = dstBase + y * destData.Stride;

                    // for each pixels
                    for ( x = 0; x < width; x++, ptr += pixelSize )
                    {
                        r = ptr[RGB.R];
                        g = ptr[RGB.G];
                        b = ptr[RGB.B];

                        // get color from palette, which is the closest to current pixel's value
                        Color closestColor = GetClosestColor( r, g, b, out colorIndex );

                        // do error diffusion
                        Diffuse( r - closestColor.R, g - closestColor.G, b - closestColor.B, ptr );

                        // write color index as pixel's value to destination image
                        if ( is8bpp )
                        {
                            *dst = colorIndex;
                            dst++;
                        }
                        else
                        {
                            if ( x % 2 == 0 )
                            {
                                *dst |= (byte) ( colorIndex << 4 );
                            }
                            else
                            {
                                *dst |= ( colorIndex );
                                dst++;
                            }
                        }
                    }
                    ptr += offset;
                }
            }

            destImage.UnlockBits( destData );
            source.Dispose( );

            return destImage;
        }
예제 #16
0
        private void ProcessFrame()
        {
            UnmanagedImage unpreprocessedCopy = m_currentUnpreprocessed.Clone();

            m_currentPreprocessed = m_preprocessingFilters.Apply(unpreprocessedCopy);

            Bitmap   image    = new Bitmap(m_currentPreprocessed.Width, m_currentPreprocessed.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics graphics = Graphics.FromImage(image);

            if (m_showMode == ShowImageMode.Source)
            {
                graphics.DrawImageUnscaled(m_currentUnpreprocessed.ToManagedImage(), 0, 0);
            }
            else
            {
                graphics.DrawImageUnscaled(m_currentPreprocessed.ToManagedImage(), 0, 0);
            }

            m_blobExtractor.ProcessImage(m_currentPreprocessed);
            var blobs = m_blobExtractor.GetObjects(m_currentPreprocessed, false);

            lock (m_findedContours)
            {
                m_findedContours.Clear();
                foreach (var blob in blobs)
                {
                    Contour contour = m_extractor.Extract(blob.Image);
                    m_findedContours.Add(new FindedContourInfo()
                    {
                        Contour         = contour.BringLength(m_targetContoursLenght),
                        CenterOfGravity = blob.CenterOfGravity,
                        Rect            = blob.Rectangle
                    });
                }

                foreach (var finded in m_findedContours)
                {
                    ContoursMatcher.Match bestMatch = m_matcher.GetMatch(finded.Contour);

                    if (bestMatch != null)
                    {
                        var text         = string.Format("{0}", bestMatch.FamiliarContour.Description, bestMatch.MaxNSP.AbsoluteValue());
                        var textPosition = new PointF(finded.Rect.Left + finded.Rect.Width / 2, finded.Rect.Bottom);

                        graphics.DrawString(text, m_font, m_textBrush, textPosition);

                        if (m_showAngle)
                        {
                            graphics.DrawString(string.Format("{0:F0}°", bestMatch.MaxNSP.ArgumentDegrees()), m_font, m_textBrush, PointF.Add(textPosition, new Size(0, 13)));
                        }

                        if (m_showBoundingRect)
                        {
                            graphics.DrawRectangle(Pens.Green, finded.Rect);
                        }
                    }
                }
            }

            ImageBox.Image       = image;
            BlobsCountLabel.Text = string.Format("blobs count: {0}", blobs.Length);
        }
예제 #17
0
        //eventhandler if new frame is ready
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap img = (Bitmap)eventArgs.Frame.Clone();

            if (counterImg == 10)
            {
                double delaisImage = DateTime.Now.TimeOfDay.TotalMilliseconds - _mill_last_pic;
                _mill_last_pic = DateTime.Now.TimeOfDay.TotalMilliseconds;

                double FPS = 1 / delaisImage * 1000 * counterImg + 1;
                // txt_nb_fps.Text = FPS.ToString() ;


                //txt_resolution.Text = "" + videoSource.DesiredFrameSize.Height + " * " + videoSource.DesiredFrameSize.Width;
                string resolutionTxt = "" + img.Width + " * " + img.Height;
                if (this != null && (!this.IsDisposed))
                {
                    try
                    {
                        this.Invoke((ProcessNewFPS)UpdateNewFPS, FPS);
                        this.Invoke((ProcessNewResolution)UpdateNewResolution, resolutionTxt);
                    }
                    catch (ObjectDisposedException) // La fenetre était en train de se fermée
                    {
                    }
                }
                counterImg = 0;
            }
            counterImg++;

            //Rectangle rect = new Rectangle(0,0,eventArgs.Frame.Width,eventArgs.Frame.Height);



            // 1 - grayscaling
            UnmanagedImage image      = UnmanagedImage.FromManagedImage(img);
            UnmanagedImage imageRouge = image.Clone();
            UnmanagedImage imageBleu  = image.Clone();
            UnmanagedImage imageVert  = image.Clone();
            UnmanagedImage grayImage  = null;

            Color colorPoint = image.GetPixel(posX, posY);

            this.Invoke((ProcessLalbelText)ChangeLabelText, new object[] { colorPoint.GetHue().ToString(), lbl_hue });
            this.Invoke((ProcessLalbelText)ChangeLabelText, new object[] { colorPoint.GetBrightness().ToString(), lbl_lum });
            this.Invoke((ProcessLalbelText)ChangeLabelText, new object[] { colorPoint.GetSaturation().ToString(), lbl_sat });

            if (image.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                grayImage = image;
            }
            else
            {
                grayImage = UnmanagedImage.Create(image.Width, image.Height,
                                                  PixelFormat.Format8bppIndexed);
                Grayscale.CommonAlgorithms.BT709.Apply(image, grayImage);
            }

            // 2 - Edge detection
            DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector();
            UnmanagedImage         edgesImage   = edgeDetector.Apply(grayImage);

            // 3 - Threshold edges
            Threshold thresholdFilterGlyph   = new Threshold((short)numericUpDown3.Value);
            Threshold thresholdFilterCouleur = new Threshold((short)numericUpDown2.Value);

            thresholdFilterGlyph.ApplyInPlace(edgesImage);

            /*
             *
             * Bitmap image = (Bitmap)eventArgs.Frame.Clone();
             *
             * //Reference : http://www.aforgenet.com/framework/docs/html/743311a9-6c27-972d-39d2-ddc383dd1dd4.htm
             *
             *  private HSLFiltering filter = new HSLFiltering();
             * // set color ranges to keep red-orange
             * filter.Hue = new IntRange(0, 20);
             * filter.Saturation = new DoubleRange(0.5, 1);
             *
             * // apply the filter
             * filter.ApplyInPlace(image);
             * */
            /*RGB colorRed = new RGB(215, 30, 30);
             * RGB colorBlue = new RGB(10, 10, 215);
             * RGB colorVert = new RGB(30, 215, 30);
             * RGB colorBlanc = new RGB(225, 219, 160);*/

            HSLFiltering filter = new HSLFiltering();

            // create filter
            // EuclideanColorFiltering filter = new EuclideanColorFiltering();
            //filter.Radius = (short)numericUpDown1.Value;
            filter.Hue        = new IntRange(40, 140);
            filter.Saturation = new Range(0.5f, 1.0f);
            filter.Luminance  = new Range(0.2f, 1.0f);

            //filter.CenterColor = colorRed;
            filter.ApplyInPlace(imageRouge);

            filter.Hue = new IntRange(100, 180);
            //filter.CenterColor = colorBlanc;
            filter.ApplyInPlace(imageVert);

            filter.Hue = new IntRange(0, 40);
            //filter.CenterColor = colorBlue;
            filter.ApplyInPlace(imageBleu);



            Grayscale filterRouge = new Grayscale(0.800, 0.200, 0.200);
            Grayscale filterVert  = new Grayscale(0.200, 0.800, 0.200);
            Grayscale filterBleu  = new Grayscale(0.200, 0.200, 0.800);

            UnmanagedImage grayRougeImage = filterRouge.Apply(imageRouge);
            UnmanagedImage grayBleuImage  = filterBleu.Apply(imageBleu);


            UnmanagedImage edgesRougeImage = edgeDetector.Apply(grayRougeImage);
            UnmanagedImage edgesBleuImage  = edgeDetector.Apply(grayBleuImage);

            thresholdFilterCouleur.ApplyInPlace(edgesRougeImage);
            thresholdFilterCouleur.ApplyInPlace(edgesBleuImage);
            // All the image processing is done here...

            // pictureBox1.Image = image.ToManagedImage();
            if (this != null && (!this.IsDisposed)) // Si on est pas en train de suppirmer la fenetre
            {
                try
                {
                    this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { image, pic_ImageNormal });
                    this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { edgesImage, pic_ImageEdge });

                    this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { imageRouge, pic_ImageRouge });

                    this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { imageBleu, pic_ImageBleu });
                    this.Invoke((ProcessNewImage)DisplayNewImage, new object[] { imageVert, pic_ImageVert });
                }
                catch (ObjectDisposedException) // La fenetre était en train de se fermée
                {
                }
            }

            /*pictureBox2.Image = grayImage.ToManagedImage();
             * pictureBox3.Image = edgesImage.ToManagedImage();
             * pictureBox4.Image = imageRouge.ToManagedImage();*/
        }
예제 #18
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image )
        {
            // copy source image
            UnmanagedImage sourceImage = image.Clone( );
            // perform closing on the source image
            closing.ApplyInPlace( image );
            // subtract source image from the closed image
            subtract.UnmanagedOverlayImage = sourceImage;
            subtract.ApplyInPlace( image );

            sourceImage.Dispose( );
        }