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++:

enter image description here

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]

enter image description here

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

  • $\begingroup$ 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. $\endgroup$ – bobthechemist Dec 17 '18 at 21:55
  • $\begingroup$ 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. $\endgroup$ – halirutan Dec 18 '18 at 1:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.