# Advice for creating first node

**URL:** <https://discourse.nodered.org/t/advice-for-creating-first-node/79375>\
**Category:** Developing Nodes\
**Created:** [23 June 2023 14:23 UTC](https://discourse.nodered.org/t/advice-for-creating-first-node/79375 "2023-06-23T14:23:48Z")\
**Posts on this page:** 5\
**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:** [23 June 2023 14:23 UTC](https://discourse.nodered.org/t/advice-for-creating-first-node/79375/1 "2023-06-23T14:23:48Z")

</div>

Happy Friday everyone.

Based on [my success](https://discourse.nodered.org/t/help-with-simple-ocr-of-two-digit-numbers/79339/5) with using a simple open source program called [SSOCR](https://www.unix-ag.uni-kl.de/~auerswal/ssocr/) to do very accurate optical character recognition of seven segment numerical digits, I thought it would be good opportunity to create my first node. The instructions for creating nodes are clear enough and I can probably get through them. My question though is if there might be an 'optimal' way to approach this. Here is what I know from the above SSOCR page:

- _ssocr_ is available as _C_ source code
- _ssocr_ runs on Linux, Mac (requires a library), FreeBSD, and Windows (using Cygwin)
- _ssocr_ runs on command line with the syntax ssocr [OPTION]... [COMMAND]... IMAGE where there are dozens of options and dozens of commands. I envision these are parameters that one could set in the node's settings.
- The image that SSOCR reads is a file (.png, .jpg, and perhaps others) on a storage location that can be accessed by the program, but when run in Node-RED, I envision the image coming via a flow as an input to the node.

Here's where I am wading into deep waters.... Can a program like the above can be run in a 'wrapper' (if that's the right term) within Node-RED and never require the user to install SSOCR?

Does anyone who has created nodes see any issues with a plan like this?

- inputs to the node: image or buffer

- parameters to adjust (just a few of the many)  
-T, --iter-threshold use iterative thresholding method  
-n, --number-pixels=# number of pixels needed to recognize a segment  
-N, --min-segment=SIZE minimum width and height of a segment  
-i, --ignore-pixels=# number of pixels ignored when searching digit  
boundaries  
-M, --min-char-dims=WxH minimum width and height of a character/digit  
-d, --number-digits=RNG number of digits in image (-1 for auto,  
positive number, or positive range)  
-r, --one-ratio=# height/width ratio to recognize a 'one'  
-m, --minus-ratio=# width/height ratio to recognize a minus sign

- commands to send (only a few of many)  
remove\_isolated --\> remove isolated pixels  
make\_mono --\> make image monochrome  
grayscale --\> transform image to grayscale  
invert --\> make inverted monochrome image  
gray\_stretch T1 T2 --\> stretch luminance values from [T1,T2] to [0,255] (use --adjust-gray for percentages)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [23 June 2023 15:07 UTC](https://discourse.nodered.org/t/advice-for-creating-first-node/79375/2 "2023-06-23T15:07:44Z")

</div>

> [@grant1](#):
>
> Here's where I am wading into deep waters.... Can a program like the above can be run in a 'wrapper' (if that's the right term) within Node-RED and never require the user to install SSOCR?

The clear and concise answer is .... maybe.

A command-line app might be amenable to change to allow it to be compiled to a library that can be called by node.js code which is what you need to do.

But I suspect (having never actually done it), that it is far from trivial.

The configuration parameters are probably fairly straight-forwards to deal with if you can get your head around the first part. But I'm afraid I'd only have the very vaguest of ideas about how to get started, especially not being a C person.

---

<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:** [23 June 2023 19:07 UTC](https://discourse.nodered.org/t/advice-for-creating-first-node/79375/3 "2023-06-23T19:07:34Z")

</div>

> [@grant1](#):
>
> Here's where I am wading into deep waters.... Can a program like the above can be run in a 'wrapper' (if that's the right term) within Node-RED and never require the user to install SSOCR?

You could install `SSOCR` for the user as part of the installation of your nodes package. This ensures as well that you have (e.g.) the required version and the path to look for `SSOCR` _under control_.

`node.js` is able to execute command line programs - synch or async. Refer to the [child\_process](https://nodejs.org/api/child_process.html) documentation for further details.

Discussing functionality, the parameters to configure the recognition process could be made definable via a nice property page. Some of the commands (e.g. `invert image`) could go there as well - perhaps labeled as `image preprocessing options`.  
Looking at things from a user perspective, I'd yet be interested in the result rather than different commands to run. Thus you should abstract all the heavy lifting & focus on creating a node that's simple to use...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 June 2023 19:50 UTC](https://discourse.nodered.org/t/advice-for-creating-first-node/79375/4 "2023-06-23T19:50:32Z")

</div>

I think this might be a good candidate for [wasm](https://openhome.cc/eGossip/WebAssembly/C2Wasm.html).

Please write up what you do so we can all learn and benefit from your impending headache 😂

---

<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:** [22 August 2023 19:51 UTC](https://discourse.nodered.org/t/advice-for-creating-first-node/79375/5 "2023-08-22T19:51:08Z")

</div>

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