Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 = 400;
- XYCoord leftTop = new XYCoord();
- XYCoord rightTop = new XYCoord();
- XYCoord leftBottom = new XYCoord();
- XYCoord rightBottom = new XYCoord();
- Int32Image nieuw = new Int32Image();
- VisionLab.Closing(binaryPlateImage, nieuw, new Mask_Int32(6, 6, 1));
- VisionLab.Dilation(nieuw, binaryPlateImage, new Mask_Int32(3, 3, 1));
- VisionLab.Dilation(binaryPlateImage, nieuw, new Mask_Int32(3, 3, 1));
- VisionLab.Closing(nieuw, binaryPlateImage, new Mask_Int32(6, 6, 1));
- VisionLab.FillHoles(binaryPlateImage, Connected.FourConnected);
- //VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 30000, Int16.MaxValue);
- VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_FormFactor, 0, 0.30);
- //VisionLab.RemoveBlobs(nieuw, Connected.EightConnected, BlobAnalyse.BA_HeightWidthRatio, 1, 99);
- //Find licenseplate
- if (!VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom))
- {
- VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, 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)
- {
- FindPlate(plateImage, ref binaryPlateImage);
- VisionLab.Closing(binaryPlateImage, nieuw, new Mask_Int32(6, 6, 1));
- VisionLab.Dilation(nieuw, binaryPlateImage, new Mask_Int32(3, 3, 1));
- VisionLab.Dilation(binaryPlateImage, nieuw, new Mask_Int32(3, 3, 1));
- VisionLab.Closing(nieuw, binaryPlateImage, new Mask_Int32(6, 6, 1));
- VisionLab.FillHoles(binaryPlateImage, Connected.FourConnected);
- //VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 30000, Int16.MaxValue);
- VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_FormFactor, 0, 0.30);
- //VisionLab.RemoveBlobs(nieuw, Connected.EightConnected, BlobAnalyse.BA_HeightWidthRatio, 1, 99);
- //Find licenseplate
- if (!VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom))
- {
- VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, leftTop, rightTop, leftBottom, rightBottom);
- }
- 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)
- {
- FindPlate(plateImage, ref binaryPlateImage);
- VisionLab.Closing(binaryPlateImage, nieuw, new Mask_Int32(6, 6, 1));
- VisionLab.Dilation(nieuw, binaryPlateImage, new Mask_Int32(3, 3, 1));
- VisionLab.Dilation(binaryPlateImage, nieuw, new Mask_Int32(3, 3, 1));
- VisionLab.Closing(nieuw, binaryPlateImage, new Mask_Int32(6, 6, 1));
- VisionLab.FillHoles(binaryPlateImage, Connected.FourConnected);
- //VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 30000, Int16.MaxValue);
- VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_FormFactor, 0, 0.30);
- //VisionLab.RemoveBlobs(nieuw, Connected.EightConnected, BlobAnalyse.BA_HeightWidthRatio, 1, 99);
- //Find licenseplate
- if (!VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom))
- {
- VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, leftTop, rightTop, leftBottom, rightBottom);
- }
- 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)
- {
- return false;
- }
- }
- }
- plateImageGray.Dispose();
- //*******************************//
- //** Exercise: **//
- //** adjust licenseplate **//
- //** segmentation **//
- //*******************************//
- //Find dark text on bright licenseplate using ThresholdISOData
- if (VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject) != 1)
- {
- VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.BrightObject);
- }
- //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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement