When I deal with alot of checkmark bubbles for examination / questionairre , I need to ensure that each of the checkmark filled with black area at least in certain percentage (i.e. more than 70%)
In this script I am using the feature of creating Ipicture Interface from ABBYY Flexicapture object, and evaluate the pixel, if the pixel color is black then it would add more area of black and vice versa.
To use this feature I need to import system.drawing into ABBYY Flexicapture .Net Reference.
Put this script on script modules rule : ( I am using VB.Net)
'\---------------------------------------------------------------------------------
Imports system.io
Imports system.drawing
Public Module Calculate
Public Function CalculatePercentageofBlack(ByVal b As Bitmap) As Double
Dim x as integer
Dim blackarea As Integer = 0
Dim eva As New Bitmap(b.Width, b.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArg b)
For y As Integer = 0 To eva.Height - 1
For x = 0 To eva.Width - 1
Dim cw As New Color
cw = Color.Black
Dim curPixColor As Color = b.GetPixel(x, y)
If curPixColor.ToArgb() = cw.ToArgb() Then
blackarea = blackarea + 1
End If
Next
Next
Dim totalarea As Integer = b.Width * b.Height
CalculatePercentageofBlack = blackarea / totalarea
End Function
End Module
'\------------------------------------------------------------------------------------------------
And I finally use this function on each bubbles to evaluate the percentage of blackcolor pixel inside the checkmark area
Imports system.drawing
DIm fieldnya as IFieldRegion
fieldnya = context.Field("Company Business Group").Regions(0)
Dim picturelogo as IPictureObject
picturelogo = fieldnya.Picture
Dim mybitmap as bitmap = System.Drawing.Image.FromHbitmap(picturelogo.handl e)
context.Field("Percentage").Value = CalculatePercentageofBlack(mybitmap)
\-----------------------------------------------------------------------------------------------------------------------------
I am using Field Percentage to show the percentage of area just for my evaluation.
For futher development , we also could force the value of the field to become true or false based on percentage of black area calculation.
Hope this experience could be helpful to ABBYY Flexicapture users who is dealing with the same case.
In this script I am using the feature of creating Ipicture Interface from ABBYY Flexicapture object, and evaluate the pixel, if the pixel color is black then it would add more area of black and vice versa.
To use this feature I need to import system.drawing into ABBYY Flexicapture .Net Reference.
Put this script on script modules rule : ( I am using VB.Net)
'\---------------------------------------------------------------------------------
Imports system.io
Imports system.drawing
Public Module Calculate
Public Function CalculatePercentageofBlack(ByVal b As Bitmap) As Double
Dim x as integer
Dim blackarea As Integer = 0
Dim eva As New Bitmap(b.Width, b.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArg b)
For y As Integer = 0 To eva.Height - 1
For x = 0 To eva.Width - 1
Dim cw As New Color
cw = Color.Black
Dim curPixColor As Color = b.GetPixel(x, y)
If curPixColor.ToArgb() = cw.ToArgb() Then
blackarea = blackarea + 1
End If
Next
Next
Dim totalarea As Integer = b.Width * b.Height
CalculatePercentageofBlack = blackarea / totalarea
End Function
End Module
'\------------------------------------------------------------------------------------------------
And I finally use this function on each bubbles to evaluate the percentage of blackcolor pixel inside the checkmark area
Imports system.drawing
DIm fieldnya as IFieldRegion
fieldnya = context.Field("Company Business Group").Regions(0)
Dim picturelogo as IPictureObject
picturelogo = fieldnya.Picture
Dim mybitmap as bitmap = System.Drawing.Image.FromHbitmap(picturelogo.handl e)
context.Field("Percentage").Value = CalculatePercentageofBlack(mybitmap)
\-----------------------------------------------------------------------------------------------------------------------------
I am using Field Percentage to show the percentage of area just for my evaluation.
For futher development , we also could force the value of the field to become true or false based on percentage of black area calculation.
Hope this experience could be helpful to ABBYY Flexicapture users who is dealing with the same case.
Comments
3 comments
Thanks for script ScanAddited. I am very interested in implementing this.
I can import the System.Drawing, but I am unable to import System.IO. I am presently using Version 2.0.0.0
Dan Ayo
imports system.io is not relevan , because you can always use full path for windows file system. Import drawing will be sufficient
Please sign in to leave a comment.