Esempio n. 1
0
        /*  Description:
         *      Locates the characters of the license plate
         *              - Warp image (Rectify)
         *              - Segment characters
         *              - Remove blobs which are to small (Lines between characters)
         *  Input:
         *          //Original image
         *          RGB888Image plateImage
         *          //Segmented license plate
         *          Int32Image binaryPlateImage
         *  Output:
         *          //Image containing binary six characters
         *          ref Int32Image binaryCharacterImage
         *  Return:
         *          //Function executed successfully
         *          bool
         */
        public static bool FindCharacters(RGB888Image plateImage, Int32Image binaryPlateImage, ref Int32Image binaryCharacterImage)
        {
            //Constants
            const int c_height           = 100;
            const int c_width            = 470;
            const int c_remove_blobs_min = 1;
            const int c_remove_blobs_max = 400;

            XYCoord leftTop     = new XYCoord();
            XYCoord rightTop    = new XYCoord();
            XYCoord leftBottom  = new XYCoord();
            XYCoord rightBottom = new XYCoord();


            //Find licenseplate
            VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom);

            Int32Image plateImageGray = new Int32Image();

            VisionLab.Convert(plateImage, plateImageGray);

            try
            {
                //Rectify plate
                VisionLab.Warp(plateImageGray, binaryCharacterImage, TransformDirection.ForwardT, new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom), c_height, c_width, 0);
            }
            catch (Exception)
            {
                //Warp, 3 coords on one line
                return(false);
            }
            plateImageGray.Dispose();

            //*******************************//
            //** Exercise:                 **//
            //**   adjust licenseplate     **//
            //**   segmentation            **//
            //*******************************//

            //Find dark text on bright licenseplate using ThresholdISOData
            VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject);

            //Remove blobs connected to the border
            VisionLab.RemoveBorderBlobs(binaryCharacterImage, Connected.EightConnected, Border.AllBorders);
            //Remove small blobs
            VisionLab.RemoveBlobs(binaryCharacterImage, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

            leftTop.Dispose();
            rightTop.Dispose();
            leftBottom.Dispose();
            rightBottom.Dispose();
            //GC.Collect();
            return(true);
        }
        /*
         *  Description:
         *      Locates the characters of the license plate
         *      - Warp image (Rectify)
         *      - Segment characters
         *      - Remove blobs which are to small (Lines between characters)
         *  Input:
         *      //Original image
         *      RGB888Image plateImage
         *      //Segmented license plate
         *      Int32Image binaryPlateImage
         *      Output:
         *      //Image containing binary six characters
         *      ref Int32Image binaryCharacterImage
         *  Return:
         *      //Function executed successfully
         *      bool
         */
        public static bool FindCharacters(RGB888Image plateImage, Int32Image binaryPlateImage, ref Int32Image binaryCharacterImage)
        {
            try
            {
                //Constants
                const int c_height           = 100;
                const int c_width            = 470;
                const int c_remove_blobs_min = 1;
                const int c_remove_blobs_max = 450;

                XYCoord leftTop     = new XYCoord();
                XYCoord rightTop    = new XYCoord();
                XYCoord leftBottom  = new XYCoord();
                XYCoord rightBottom = new XYCoord();


                //Find licenseplate
                VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom);
                if (!VisionLab.WarpCoordsValid(new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom)))
                {
                    VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, leftTop, rightTop, leftBottom, rightBottom);
                    if (!VisionLab.WarpCoordsValid(new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom)))
                    {
                        return(false);
                    }
                }

                Int32Image plateImageGray = new Int32Image();
                VisionLab.Convert(plateImage, plateImageGray);

                //Rectify plate
                VisionLab.Warp(plateImageGray, binaryCharacterImage, TransformDirection.ForwardT, new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom), c_height, c_width, 0);


                plateImageGray.Dispose();

                //*******************************//
                //** Exercise:                 **//
                //**   adjust licenseplate     **//
                //**   segmentation            **//
                //*******************************//


                //Find dark text on bright licenseplate using ThresholdISOData
                VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject);

                //Remove small blobs and noise
                Int32Image binaryCharacterImageCopy = new Int32Image(binaryCharacterImage);
                VisionLab.Opening(binaryCharacterImageCopy, binaryCharacterImage, new Mask_Int32(5, 1, 1));

                //Remove blobs connected to the border
                VisionLab.RemoveBorderBlobs(binaryCharacterImage, Connected.EightConnected, Border.AllBorders);
                //Remove small blobs
                VisionLab.RemoveBlobs(binaryCharacterImage, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

                leftTop.Dispose();
                rightTop.Dispose();
                leftBottom.Dispose();
                rightBottom.Dispose();

                return(true);
            }
            catch (System.Exception ex)
            {
                throw new Exception("FindCharacters: " + ex.Message);
            }
        }
        /*  Description:
                Locates the characters of the license plate
	                - Warp image (Rectify)
	                - Segment characters
	                - Remove blobs which are to small (Lines between characters)
            Input:
	            //Original image
	            RGB888Image plateImage
	            //Segmented license plate
	            Int16Image binaryPlateImage
            Output:
	            //Image containing binary six characters	
	            ref Int16Image binaryCharacterImage 
            Return:
	            //Function executed successfully
	            bool
        */
        public static bool FindCharacters(RGB888Image plateImage, Int16Image binaryPlateImage, ref Int16Image binaryCharacterImage)
        {
            //Constants
            const int c_height = 100;
            const int c_width = 470;
            const int c_remove_blobs_min = 0;
            const int c_remove_blobs_max = 400;

            XYCoord leftTop = new XYCoord();
            XYCoord rightTop = new XYCoord();
            XYCoord leftBottom = new XYCoord();
            XYCoord rightBottom = new XYCoord();

            // 2de set coordinaten:
            // NIEUW
            XYCoord leftTop2 = new XYCoord();
            XYCoord rightTop2 = new XYCoord();
            XYCoord leftBottom2 = new XYCoord();
            XYCoord rightBottom2 = new XYCoord();

            //Find licenseplate
            Int32Image binaryPlateImage32 = new Int32Image();
            VisionLab.Convert(binaryPlateImage, binaryPlateImage32);
            
            VisionLab.FindCornersRectangle(
                binaryPlateImage32, 
                Connected.EightConnected, 
                0.5, 
                Orientation.Landscape, 
                leftTop, 
                rightTop, 
                leftBottom, 
                rightBottom
            );

            // NIEUW
            // Coordinaten bepalen voor deze functie
            VisionLab.FindCornersRectangleSq(
                    binaryPlateImage32,
                    Connected.EightConnected,
                    leftTop2,
                    rightTop2,
                    leftBottom2,
                    rightBottom2
                );

            binaryPlateImage32.Dispose();

            Int16Image plateImageGray = new Int16Image();

            VisionLab.Convert(plateImage, plateImageGray);
            binaryCharacterImage.Assign_Op(plateImageGray);
            
            // Eerst de standaard wrap proberen
            try
            {
                //Rectify plate
                VisionLab.Warp(
                    plateImageGray, 
                    binaryCharacterImage, 
                    TransformDirection.ForwardT, 
                    new Coord2D(leftTop), 
                    new Coord2D(rightTop), 
                    new Coord2D(leftBottom), 
                    new Coord2D(rightBottom), 
                    c_height, 
                    c_width, 
                    0
                );
            }
            catch (Exception )
            {
                // NIEUW
                // Als dat mislukt dan de andere gebruiken
                try
                {
                    VisionLab.Warp(plateImageGray,
                        binaryCharacterImage,
                        TransformDirection.ForwardT,
                        new Coord2D(leftTop2),
                        new Coord2D(rightTop2),
                        new Coord2D(leftBottom2),
                        new Coord2D(rightBottom2),
                        c_height,
                        c_width,
                        0
                    );
                }
                catch (Exception)
                {
                    return false;
                }                
            }

            plateImageGray.Dispose();

            //*******************************//
            //** Exercise:                 **//
            //**   adjust licenseplate     **//
            //**   segmentation            **//
            //*******************************//
            // NIEUW
            Int16Image MaxMin = new Int16Image();
            Int16Image MaxMin2 = new Int16Image();

            // NIEUW
            //2 x max rondje ding
            //dan 2 x min rondje ding
            //dan van elkaar aftrekken
            //(zoeken op heldere object)
            Mask_Int32 mask = new Mask_Int32(11, 11, 5, 5);
            VisionLab.MaximumFilter(binaryCharacterImage, MaxMin, FixEdge.EdgeExtend, mask);
            VisionLab.MaximumFilter(MaxMin, MaxMin2, FixEdge.EdgeExtend, mask);

            VisionLab.MinimumFilter(MaxMin2, MaxMin, FixEdge.EdgeExtend, mask);
            VisionLab.MinimumFilter(MaxMin, MaxMin2, FixEdge.EdgeExtend, mask);
            // Maxmin2 holds the result now of the filter oparations
            // Get the difference between both
            VisionLab.Subtract(binaryCharacterImage, MaxMin2);

            MaxMin2.Dispose();
            MaxMin.Dispose();

            //Find dark text on bright licenseplate using ThresholdISOData
            VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject);

            Int16Image bin = new Int16Image();
            
            // NIEUW
            // Recreate images that are corralated / deformed
            VisionLab.Opening(binaryCharacterImage, bin, new Mask_Int32(2, 2, 1));
            
            
            // Convert to a 32 bit format 
            Int32Image binaryCharacterImage32 = new Int32Image();
            // Int32Image binCharImg32 = new Int32Image();
            VisionLab.Convert(bin, binaryCharacterImage32);
            bin.Dispose();
            // Remove blobs connected to the border
            VisionLab.RemoveBorderBlobs(binaryCharacterImage32, Connected.EightConnected, Border.AllBorders);
            // Remove small blobs
            VisionLab.RemoveBlobs(binaryCharacterImage32, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

            //Convert to a 16 bit format             
            VisionLab.Convert(binaryCharacterImage32, binaryCharacterImage);

            binaryCharacterImage32.Dispose();
            leftTop.Dispose();
            rightTop.Dispose();
            leftBottom.Dispose();
            rightBottom.Dispose();
            GC.Collect();
            // NIEUW
            // Check if 6 characters/blobs have been found and label image.
            if (VisionLab.LabelBlobs(binaryCharacterImage, Connected.EightConnected) != 6)
                return false;
            return true;
        }
        /*  Description:
         *      Locates the characters of the license plate
         *              - Warp image (Rectify)
         *              - Segment characters
         *              - Remove blobs which are to small (Lines between characters)
         *  Input:
         *          //Original image
         *          RGB888Image plateImage
         *          //Segmented license plate
         *          Int16Image binaryPlateImage
         *  Output:
         *          //Image containing binary six characters
         *          ref Int16Image binaryCharacterImage
         *  Return:
         *          //Function executed successfully
         *          bool
         */
        public static bool FindCharacters(RGB888Image plateImage, Int16Image binaryPlateImage, ref Int16Image binaryCharacterImage)
        {
            //Constants
            const int c_height           = 100;
            const int c_width            = 470;
            const int c_remove_blobs_min = 0;
            const int c_remove_blobs_max = 400;

            XYCoord leftTop     = new XYCoord();
            XYCoord rightTop    = new XYCoord();
            XYCoord leftBottom  = new XYCoord();
            XYCoord rightBottom = new XYCoord();

            // 2de set coordinaten:
            // NIEUW
            XYCoord leftTop2     = new XYCoord();
            XYCoord rightTop2    = new XYCoord();
            XYCoord leftBottom2  = new XYCoord();
            XYCoord rightBottom2 = new XYCoord();

            //Find licenseplate
            Int32Image binaryPlateImage32 = new Int32Image();

            VisionLab.Convert(binaryPlateImage, binaryPlateImage32);

            VisionLab.FindCornersRectangle(
                binaryPlateImage32,
                Connected.EightConnected,
                0.5,
                Orientation.Landscape,
                leftTop,
                rightTop,
                leftBottom,
                rightBottom
                );

            // NIEUW
            // Coordinaten bepalen voor deze functie
            VisionLab.FindCornersRectangleSq(
                binaryPlateImage32,
                Connected.EightConnected,
                leftTop2,
                rightTop2,
                leftBottom2,
                rightBottom2
                );

            binaryPlateImage32.Dispose();

            Int16Image plateImageGray = new Int16Image();

            VisionLab.Convert(plateImage, plateImageGray);
            binaryCharacterImage.Assign_Op(plateImageGray);

            // Eerst de standaard wrap proberen
            try
            {
                //Rectify plate
                VisionLab.Warp(
                    plateImageGray,
                    binaryCharacterImage,
                    TransformDirection.ForwardT,
                    new Coord2D(leftTop),
                    new Coord2D(rightTop),
                    new Coord2D(leftBottom),
                    new Coord2D(rightBottom),
                    c_height,
                    c_width,
                    0
                    );
            }
            catch (Exception)
            {
                // NIEUW
                // Als dat mislukt dan de andere gebruiken
                try
                {
                    VisionLab.Warp(plateImageGray,
                                   binaryCharacterImage,
                                   TransformDirection.ForwardT,
                                   new Coord2D(leftTop2),
                                   new Coord2D(rightTop2),
                                   new Coord2D(leftBottom2),
                                   new Coord2D(rightBottom2),
                                   c_height,
                                   c_width,
                                   0
                                   );
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            plateImageGray.Dispose();

            //*******************************//
            //** Exercise:                 **//
            //**   adjust licenseplate     **//
            //**   segmentation            **//
            //*******************************//
            // NIEUW
            Int16Image MaxMin  = new Int16Image();
            Int16Image MaxMin2 = new Int16Image();

            // NIEUW
            //2 x max rondje ding
            //dan 2 x min rondje ding
            //dan van elkaar aftrekken
            //(zoeken op heldere object)
            Mask_Int32 mask = new Mask_Int32(11, 11, 5, 5);

            VisionLab.MaximumFilter(binaryCharacterImage, MaxMin, FixEdge.EdgeExtend, mask);
            VisionLab.MaximumFilter(MaxMin, MaxMin2, FixEdge.EdgeExtend, mask);

            VisionLab.MinimumFilter(MaxMin2, MaxMin, FixEdge.EdgeExtend, mask);
            VisionLab.MinimumFilter(MaxMin, MaxMin2, FixEdge.EdgeExtend, mask);
            // Maxmin2 holds the result now of the filter oparations
            // Get the difference between both
            VisionLab.Subtract(binaryCharacterImage, MaxMin2);

            MaxMin2.Dispose();
            MaxMin.Dispose();

            //Find dark text on bright licenseplate using ThresholdISOData
            VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject);

            Int16Image bin = new Int16Image();

            // NIEUW
            // Recreate images that are corralated / deformed
            VisionLab.Opening(binaryCharacterImage, bin, new Mask_Int32(2, 2, 1));


            // Convert to a 32 bit format
            Int32Image binaryCharacterImage32 = new Int32Image();

            // Int32Image binCharImg32 = new Int32Image();
            VisionLab.Convert(bin, binaryCharacterImage32);
            bin.Dispose();
            // Remove blobs connected to the border
            VisionLab.RemoveBorderBlobs(binaryCharacterImage32, Connected.EightConnected, Border.AllBorders);
            // Remove small blobs
            VisionLab.RemoveBlobs(binaryCharacterImage32, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);

            //Convert to a 16 bit format
            VisionLab.Convert(binaryCharacterImage32, binaryCharacterImage);

            binaryCharacterImage32.Dispose();
            leftTop.Dispose();
            rightTop.Dispose();
            leftBottom.Dispose();
            rightBottom.Dispose();
            GC.Collect();
            // NIEUW
            // Check if 6 characters/blobs have been found and label image.
            if (VisionLab.LabelBlobs(binaryCharacterImage, Connected.EightConnected) != 6)
            {
                return(false);
            }
            return(true);
        }