Using C#, I'm trying to detect whether a document (Invoice to be more specific) is handwritten or printed.

Edited: I don't have to convert handwritting to actual words. Just have to know that handwritting is existing in the scanned document.

Tried OCR method by checking the percentage of meaningless character exceed certain threshold but often gave wrong result due unexpected behavior such as a line drawn across the printed words which cause OCR to capture wrong result.

Any other recommendation on how can I detect a document is handwritten or printed?

Printed Document enter image description here
Example of Printed Document / Example of Handwritten Document

Not really specific to c# only as what I'm looking for is a tool to help in identifying handwritting existence in a scanned document. C# is what I'm using primarily now thus mentioned it.

  • 2
    Would a printed invoice that was signed by hand count? How about one with PAID written across it? Aug 4, 2017 at 7:28
  • 1
    @SteveBarnes In optimal case, I want to consider printed document with minimal handwritting (Eg.: PAID, signature, random drawn image like star as bookmark) as printed document not handwritten.
    – JamesYTL
    Aug 4, 2017 at 7:49

1 Answer 1


One possible differentiation might be on the number of different colours present in multiple areas of the image. Printed invoices, with the exception of the letter head, generally only have 2 colours, (paper colour & printing colour), while hand written invoices will have at least 3 distinct colours over a significant number of areas, (paper, printing and the ink used for handwriting), the ink colour in pens rarely matches that of printing.

I would suggest testing using the ImageMagick, possibly histogram, from the command line to see if this will work for you. If it looks like it will then Magick.Net should give your application ImageMagick functionality.

You could also look at the percentage of each colour that is aligned with the paper boundaries, printed items & text mostly align well with paper boundaries while handwritten text tends to have a range of alignments - for this sort of analysis you are likely to need to use OpenCV - there are possible C# interfaces. Of course if you are making use of OpenCV 3.3 or later you could also try the deep learning classifiers.

  • Sorry for late reply. Differentiating through color is not really an option for me as we scan documents in grayscale for future OCR purpose.
    – JamesYTL
    Aug 11, 2017 at 7:58
  • @JamesYTL You are potentially throwing away some other useful information by doing so, admittedly while reducing storage requirements somewhat. Logo's, etc., often don't convert to grey scale too well. Aug 11, 2017 at 15:33
  • 2
    Apologize for late reply (again). Will try to persuade and get colored image instead. Will update if I somehow got this to work *finger crossed. Thanks for the suggestion
    – JamesYTL
    Aug 29, 2017 at 2:58
  • Still waiting for that update ... :-) Jan 3, 2018 at 10:40
  • 1
    @Mawg Currently we weren't focusing on this project anymore so there will be no updates so soon
    – JamesYTL
    Feb 14, 2018 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.