# How to TextRecognize a screenshot of code?

Are there any specific tricks or options to help TextRecognize work on a screenshot of an InputCell or code in general? For example, here's a screenshot that mixed Mathematica and C++:

Here's the output, it gets the lines but really garbles the characters badly:

i = Import["https://i.imgur.com/mCVtdHh.png", "PNG"];
res = TextRecognize[i, "Line", "BoundingBox"];
HighlightImage[i, {"Boundary", res}]
TextRecognize[i, RecognitionPrior -> "SparseText", Masking -> res]


There are no would-be helpful options such as: Language->Mathematica, RecognitionThreshold, PerformanceGoal, FontPrior.

• Any idea if external programs (tesseract) do have those options or could handle code? I'm wondering if this is an OCR problem or Mathematica's version of OCR problem. – bobthechemist Dec 17 '18 at 21:55
• It uses machine learning, was trained on a dataset and the documentation suggests that it is optimized for natural languages and not code. The font type will also play a role. Looking at your example, I guess we can agree that it is of excellent quality and cannot be compared to scanned printouts that are sometimes OCRed with much better results. In fact, I tried changing the font of a natural text example and the results are horrifying. – halirutan Dec 18 '18 at 1:53