Пример #1
0
        public unsafe List<Rectangle> GetLabels()
        {
            //List<Rectangle> results = new List<Rectangle>();
            results = new List<Rectangle>();

            BitmapData sourceData = sourceImage.LockBits(new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            BitmapData processData = processImage.LockBits(new Rectangle(0, 0, processImage.Width, processImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            // set pointers
            uint* sourceP = (uint*)sourceData.Scan0;
            uint* processP = (uint*)processData.Scan0;

            CopyImage(processP, sourceP, size);

            SobelFilter sobel = new SobelFilter();
            sobel.SobelValue = 50;
            sobel.Process(sourceP, processP, size);

            PixelExtractionFilter pixelExtraction = new PixelExtractionFilter();
            pixelExtraction.Process(sourceP, processP, size);

            // save image for debugging
            processImage.Save(@"C:\Temp\labels_0.png");

            DrawBlackBorder(processP, size);

            // override source bitmap with filtered bitmap
            CopyImage(processP, sourceP, size);

            // detect the labels
            LabelDetection detection = new LabelDetection();
            detection.Ratio = new KeyValuePair<double, double>(3, 5);
            results = detection.Process(sourceP, processP, size);

            sourceImage.UnlockBits(sourceData);
            processImage.UnlockBits(processData);

            // save image for debugging
            sourceImage.Save(@"C:\Temp\labels_1.png");

            return results;
        }
Пример #2
0
        /// <summary>
        /// Detects the labels in the Bitmap
        /// </summary>
        /// <param name="source">Source Bitmap where the labels should be found</param>
        /// <returns>List of found labels</returns>
        public unsafe List<Rectangle> GetLabels(Bitmap source)
        {
            List<Rectangle> results = new List<Rectangle>();
            Size size = new Size(source.Width, source.Height);  // size of the image

            sourceImage = new Bitmap(source);   // normal image
            processImage = new Bitmap(source);  // image for detection

            BitmapData sourceData = sourceImage.LockBits(new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            BitmapData processData = processImage.LockBits(new Rectangle(0, 0, processImage.Width, processImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            // set pointers
            uint* sourceP = (uint*)sourceData.Scan0;
            uint* processP = (uint*)processData.Scan0;

            // filter the image
            ContrastStretchingFilter stretch = new ContrastStretchingFilter();
            stretch.Process(sourceP, processP, size);
            processImage.Save(@"C:\Temp\labels_stretch.png");

            CopyImage(processP, sourceP, size);

            SobelFilter sobel = new SobelFilter();
            sobel.SobelValue = sobelValue;
            sobel.Process(sourceP, processP, size);

            PixelExtractionFilter pixelExtraction = new PixelExtractionFilter();
            pixelExtraction.Process(sourceP, processP, size);

            // save image for debugging
            processImage.Save(@"C:\Temp\labels_0.png");

            DrawBlackBorder(processP, size);

            // override source bitmap with filtered bitmap
            CopyImage(processP, sourceP, size);

            // detect the labels
            LabelDetection detection = new LabelDetection();
            detection.Ratio = legalRatio;
            results = detection.Process(sourceP, processP, size);

            sourceImage.UnlockBits(sourceData);
            processImage.UnlockBits(processData);

            // save image for debugging
            sourceImage.Save(@"C:\Temp\labels_1.png");

            return results;
        }