Scripts to calculate percentage of blackarea in checkmarkfield area

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.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
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.

Was this article helpful?

1 out of 1 found this helpful



  • Avatar

    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

    Dan Ayo
  • Avatar
    Feri Santosa
    Hi Dan Ayo,

    imports is not relevan , because you can always use full path for windows file system. Import drawing will be sufficient

  • Avatar
    Andrew Zyuzin
    Thank you for sharing the script. Still, ABBYY FlexiCapture has check marks of Auto type: for such checkmarks the amount of black in region captured at image will be compared with the region of same checkmark at the template picture (that necessarily should be clean) to make a decision if checkmark is true or false. Have you tried this? Does this work for you?

Please sign in to leave a comment.