Nodes/ComfyUI CV/CV Text To Array
ComfyUI Node

CV Text To Array

Type a List of Labels, Get an Array Your Nodes Will Actually Accept

By bmad4ever·Created 4 months ago·Updated 14 days ago· 1
CV Text To Array
    • nparray
    • count
    ◄text►
    ◄separatorone per line►
    ◄keep_emptyfalse►

    Several nodes in this pack want an array of strings, not one string: CV Draw Labels takes .labels as (N,) of text, QR and barcode detectors hand you a texts output in the same shape, and CV Load Labels reads a file into it. That's fine when the array came from a detector. It's annoying when you just want to annotate four points by hand.

    This node is the manual entry point: type your entries into a text box, get back an (N,) numpy string array in exactly the shape those inputs expect.

    How it works

    text is the content, one entry per line by default. Blank lines are dropped, so a trailing newline won't give you an empty label, and each entry gets trimmed. Empty text returns an empty array - no error, which is the right behaviour for a field you're mid-way through filling in.

    separator offers one per line, comma, semicolon and whitespace. Pick carefully, because the trade-off is real: one per line is the only option that lets an entry contain both spaces and commas, which is why it's the default for captions. Use comma when you've pasted a CSV header, whitespace for single-word tokens.

    keep_empty (default off) decides what happens to entries that are empty after trimming - the blank-line case above. Leaving it off is what you want when a human typed the text. Turn it on when the entries have to stay aligned with a fixed-length list and a blank line means "no caption for this one" rather than "skip me".

    Two outputs: nparray - the (N,) numpy array of strings, wire it into CV Draw Labels.labels or anywhere a detector's texts goes - and count, how many entries came out.

    The output worth checking

    count exists for a specific class of bug. Every consumer of a label array assumes the entries line up one-for-one with whatever it's labelling, and the pack's drawing nodes reject a mismatch rather than silently labelling the wrong points. So when you're annotating N detected features with N names, comparing count against the number of points is a five-second check that catches the entire family of "I added a blank line and now everything is shifted by one" mistakes.

    Related nodes, if you're doing this at a different scale: CV Numbers To Array parses the same text into floats or ints (the numeric counterpart), and CV Array To Text is the inverse - formatting an array back into a text table, which is handy for measurements you want to eyeball. CV Load Labels gets you from a file instead of a text box.

    Install

    ComfyUI Manager → search ComfyUI CV (publisher bmad4ever), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/bmad4ever/comfyui_cv
    pip install "opencv-contrib-python-headless~=5.0.0.93"
    

    Restart after. Python ≥ 3.12 and a recent ComfyUI on the V3 node API. Keep the contrib wheel: installing a plain opencv-python over it shares site-packages/cv2, empties the contrib submodules, and breaks other nodes in the pack. tools/repair_opencv_contrib.py --check / --apply exists for that.

    The annotation workflows - 63_ar_model_annotation.json, 45_annotate_quad_warp.json - use this node's output type; 01_install_example_inputs.json installs the sample media (run once, then reload the page).

    Where it bites

    Entry order is the contract. There's nothing here that ties entry 3 to point 3 except your own care, and a reordered list gives you confidently mislabelled output - the worst kind of wrong, because it looks deliberate.

    The other small trap is separator drift: switch from one per line to comma while your text still has line breaks, and you'll get one giant entry rather than an error. If count is 1 and you expected 5, that's what happened.

    Standard pack disclaimer applies, and it's mild at this level: bmad4ever's README describes a personal, heavily LLM-assisted project with no support promised. A text-splitting node is not where that risk lives.

    Categoryimage/CV/low-level

    Inputs (3)

    NameTypeDefaultDescription
    textSTRINGThe entries to split, one per line by default. Blank lines are dropped, so a trailing newline is harmless; surrounding whitespace on each entry is trimmed. Empty text gives an empty array, not an error.
    separatorCOMBOone per lineHow to cut the text into entries. 'one per line' is the safest for captions - it is the only option that lets an entry contain spaces AND commas. Pick 'comma' for a list pasted from a CSV header, 'whitespace' for single-word tokens.
    keep_emptyoptBOOLEANfalseKeep entries that are empty after trimming. Off drops them, which is what you want when the text was typed by hand. Turn it ON when the entries must stay aligned with a fixed-length list and a blank line means 'no caption for this one'.

    Outputs (2)

    NameTypeDescription
    nparrayNPARRAY(N,) numpy array of strings (dtype '<U'). Wire it into 'CV Draw Labels'.labels, or anywhere a detector's `texts` output would go.
    countINTHow many entries were produced. Check it against the number of points you are labelling - the drawing nodes reject a mismatch rather than silently labelling the wrong ones.