# Help with simple OCR of two-digit numbers

**URL:** <https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339>\
**Category:** General\
**Created:** [21 June 2023 17:20 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339 "2023-06-21T17:20:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [21 June 2023 17:20 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/1 "2023-06-21T17:20:13Z")

</div>

Hello and thanks in advance for anyone's help here...

See these 3 photos of my setup and flow: [https://photos.app.goo.gl/g8XBTwsx5xYe1NXc6](https://photos.app.goo.gl/g8XBTwsx5xYe1NXc6)

I have set up [this OCR node](https://flows.nodered.org/node/@martip/node-red-ocr) to read a two-digit value via a webcam. I convert it to grayscale and change the contrast, but after about 15 seconds of the yellow dot "processing", the OCR node "stalls out" whereby I get the red message as shown ("Lost connection to server, reconnecting...") and I never get the output of the node.

My understanding is the OCR node goes online and uses the tesseract library.

Is there a better way to approach this problem? FWIW, the digits that I am reading are always ranging from about 25 to 55.

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [21 June 2023 17:27 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/2 "2023-06-21T17:27:32Z")

</div>

> [@grant1](#):
>
> "Lost connection to server, reconnecting..."

This could indicate that this node raised an error that lead to a termination of the Node-RED (client or) server.  
Have you checked the two consoles (in your browser & of the server) for any issues?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [21 June 2023 17:38 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/3 "2023-06-21T17:38:04Z")

</div>

Thanks for the tip. There are indeed a host of errors being thrown by that node. It seems the help file for the node did not mention any of these parameters as being required inputs.

(sorry for the screenshot instead of the error code copied/pasted)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/90667da57090768087fcf0ee7377991ce0e61199.jpeg)

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [21 June 2023 18:09 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/4 "2023-06-21T18:09:14Z")

</div>

> [@grant1](#):
>
> node did not mention any of these parameters as being required inputs

Looking at the [Tesseract repo](https://github.com/naptha/tesseract.js), no additional parameters should be necessary for a successful recognition.

There's a [relevant remark](https://github.com/naptha/tesseract.js/blob/master/docs/image-format.md) regarding supported image format / data types:

> Note: images must be a supported image format **and** a supported data type. For example, a buffer containing a png image is supported. A buffer containing raw pixel data is not supported.

You could check that your image data buffer fulfills this demand...

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [21 June 2023 18:34 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/5 "2023-06-21T18:34:52Z")

</div>

Thank you @ralphwetzel

I changed to PNG with output as buffer and it works. Will continue testing / tweaking to make sure I can cover all the two-digit combinations.

[![Google Photos](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/30840737606d8509a8c62f708f94ee76d21981e8.jpeg "New item by Grant Pinkos") ](https://photos.app.goo.gl/iQwk9912gTHXqZkj7)

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [23 June 2023 02:38 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/6 "2023-06-23T02:38:22Z")

</div>

After a few days of experimenting, the ability of the Tesseract.js to correctly perform seven segment optical character recognition is not reliable or repeatable. So I went back to searching and found some interesting [attempts](https://discourse.nodered.org/t/extract-numbers-from-image/43529/3) & technologies, but the best was a standalone [program](https://github.com/auerswal/ssocr) called [SSOCR](https://www.unix-ag.uni-kl.de/~auerswal/ssocr/) (seven segment optical character recognition). After using the standard image cleanup tools available, it has done a very nice job of interpreting the numbers. My test flow is shown below, where you can see I needed to trim the output and convert from string to number. I will incorporate this into the overall flow whereby the image is grabbed via the webcam, cleaned up, saved to the hard drive, and then read by SSOCR via the Exec node.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9d012dd5584f9ce09e050c9b6bf60a25a35d2e5.png)

---

<div class="post-metadata">

**Author:** ![syoma755](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syoma755/32/14687_2.png) [@syoma755](https://discourse.nodered.org/u/syoma755)\
**Post date:** [23 June 2023 04:51 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/7 "2023-06-23T04:51:13Z")

</div>

You probably could use some AI-based image recognition node, which you should train on your 7-segment indicator images. You don't have so many combinations, so this shall be possible. Basically AI will just compare webcam picture with stored image.  
See [Image analysis and comparison - #5 by Jotarod](https://discourse.nodered.org/t/image-analysis-and-comparison/20698/5)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 July 2023 04:52 UTC](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/8 "2023-07-07T04:52:02Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
