Advice for creating first node

Happy Friday everyone.

Based on my success with using a simple open source program called 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)

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.

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 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...

1 Like

I think this might be a good candidate for wasm.

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

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