Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.62 KB | None | 0 0
  1. public static bool FindCharacters(RGB888Image plateImage, Int32Image binaryPlateImage, ref Int32Image binaryCharacterImage)
  2. {
  3. try
  4. {
  5. //Constants
  6. const int c_height = 100;
  7. const int c_width = 470;
  8. const int c_remove_blobs_min = 1;
  9. const int c_remove_blobs_max = 400;
  10.  
  11. XYCoord leftTop = new XYCoord();
  12. XYCoord rightTop = new XYCoord();
  13. XYCoord leftBottom = new XYCoord();
  14. XYCoord rightBottom = new XYCoord();
  15.  
  16. Int32Image nieuw = new Int32Image();
  17. VisionLab.Closing(binaryPlateImage, nieuw, new Mask_Int32(6, 6, 1));
  18. VisionLab.Dilation(nieuw, binaryPlateImage, new Mask_Int32(3, 3, 1));
  19. VisionLab.Dilation(binaryPlateImage, nieuw, new Mask_Int32(3, 3, 1));
  20. VisionLab.Closing(nieuw, binaryPlateImage, new Mask_Int32(6, 6, 1));
  21. VisionLab.FillHoles(binaryPlateImage, Connected.FourConnected);
  22. //VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 30000, Int16.MaxValue);
  23. VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_FormFactor, 0, 0.30);
  24. //VisionLab.RemoveBlobs(nieuw, Connected.EightConnected, BlobAnalyse.BA_HeightWidthRatio, 1, 99);
  25.  
  26. //Find licenseplate
  27. if (!VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom))
  28. {
  29. VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, leftTop, rightTop, leftBottom, rightBottom);
  30. }
  31.  
  32. Int32Image plateImageGray = new Int32Image();
  33. VisionLab.Convert(plateImage, plateImageGray);
  34.  
  35. try
  36. {
  37. //Rectify plate
  38. VisionLab.Warp(plateImageGray, binaryCharacterImage, TransformDirection.ForwardT, new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom), c_height, c_width, 0);
  39. }
  40. catch (Exception)
  41. {
  42. FindPlate(plateImage, ref binaryPlateImage);
  43.  
  44. VisionLab.Closing(binaryPlateImage, nieuw, new Mask_Int32(6, 6, 1));
  45. VisionLab.Dilation(nieuw, binaryPlateImage, new Mask_Int32(3, 3, 1));
  46. VisionLab.Dilation(binaryPlateImage, nieuw, new Mask_Int32(3, 3, 1));
  47. VisionLab.Closing(nieuw, binaryPlateImage, new Mask_Int32(6, 6, 1));
  48. VisionLab.FillHoles(binaryPlateImage, Connected.FourConnected);
  49. //VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 30000, Int16.MaxValue);
  50. VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_FormFactor, 0, 0.30);
  51. //VisionLab.RemoveBlobs(nieuw, Connected.EightConnected, BlobAnalyse.BA_HeightWidthRatio, 1, 99);
  52.  
  53. //Find licenseplate
  54. if (!VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom))
  55. {
  56. VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, leftTop, rightTop, leftBottom, rightBottom);
  57. }
  58.  
  59. plateImageGray = new Int32Image();
  60. VisionLab.Convert(plateImage, plateImageGray);
  61.  
  62. try
  63. {
  64. //Rectify plate
  65. VisionLab.Warp(plateImageGray, binaryCharacterImage, TransformDirection.ForwardT, new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom), c_height, c_width, 0);
  66. }
  67. catch (Exception)
  68. {
  69. FindPlate(plateImage, ref binaryPlateImage);
  70.  
  71. VisionLab.Closing(binaryPlateImage, nieuw, new Mask_Int32(6, 6, 1));
  72. VisionLab.Dilation(nieuw, binaryPlateImage, new Mask_Int32(3, 3, 1));
  73. VisionLab.Dilation(binaryPlateImage, nieuw, new Mask_Int32(3, 3, 1));
  74. VisionLab.Closing(nieuw, binaryPlateImage, new Mask_Int32(6, 6, 1));
  75. VisionLab.FillHoles(binaryPlateImage, Connected.FourConnected);
  76. //VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_Area, 30000, Int16.MaxValue);
  77. VisionLab.RemoveBlobs(binaryPlateImage, Connected.EightConnected, BlobAnalyse.BA_FormFactor, 0, 0.30);
  78. //VisionLab.RemoveBlobs(nieuw, Connected.EightConnected, BlobAnalyse.BA_HeightWidthRatio, 1, 99);
  79.  
  80. //Find licenseplate
  81. if (!VisionLab.FindCornersRectangle(binaryPlateImage, Connected.EightConnected, 0.5, Orientation.Landscape, leftTop, rightTop, leftBottom, rightBottom))
  82. {
  83. VisionLab.FindCornersRectangleSq(binaryPlateImage, Connected.EightConnected, leftTop, rightTop, leftBottom, rightBottom);
  84. }
  85.  
  86. plateImageGray = new Int32Image();
  87. VisionLab.Convert(plateImage, plateImageGray);
  88.  
  89. try
  90. {
  91. //Rectify plate
  92. VisionLab.Warp(plateImageGray, binaryCharacterImage, TransformDirection.ForwardT, new Coord2D(leftTop), new Coord2D(rightTop), new Coord2D(leftBottom), new Coord2D(rightBottom), c_height, c_width, 0);
  93. }
  94. catch (Exception)
  95. {
  96. return false;
  97. }
  98. }
  99. }
  100. plateImageGray.Dispose();
  101.  
  102. //*******************************//
  103. //** Exercise: **//
  104. //** adjust licenseplate **//
  105. //** segmentation **//
  106. //*******************************//
  107.  
  108. //Find dark text on bright licenseplate using ThresholdISOData
  109. if (VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.DarkObject) != 1)
  110. {
  111. VisionLab.ThresholdIsoData(binaryCharacterImage, ObjectBrightness.BrightObject);
  112. }
  113. //Remove small blobs and noise
  114. Int32Image binaryCharacterImageCopy = new Int32Image(binaryCharacterImage);
  115. VisionLab.Opening(binaryCharacterImageCopy, binaryCharacterImage, new Mask_Int32(5, 1, 1));
  116.  
  117. //Remove blobs connected to the border
  118. VisionLab.RemoveBorderBlobs(binaryCharacterImage, Connected.EightConnected, Border.AllBorders);
  119. //Remove small blobs
  120. VisionLab.RemoveBlobs(binaryCharacterImage, Connected.EightConnected, BlobAnalyse.BA_Area, c_remove_blobs_min, c_remove_blobs_max);
  121.  
  122. leftTop.Dispose();
  123. rightTop.Dispose();
  124. leftBottom.Dispose();
  125. rightBottom.Dispose();
  126.  
  127. return true;
  128. }
  129. catch (System.Exception ex)
  130. {
  131. throw new Exception("FindCharacters: " + ex.Message);
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement