Nodes/comfyui_cv/CV Barcode Detect
ComfyUI Node

CV Barcode Detect

Detects and decodes 1-D product barcodes (EAN-8, EAN-13, UPC-A, UPC-E) with cv2.barcode.BarcodeDetector - the linear-barcode counterpart of 'CV QR Detect', and another cv2 CLASS the auto-generated wrappers cannot reach. It locates the bar region by its dense parallel gradients, rectifies it and reads the bar widths, so it copes with rotation, perspective and the curve of a bottle label. Outputs mirror the QR node - DATA only: 'bboxes' to the core 'Draw BBoxes', 'corners' + 'connections' to 'CV Draw Connections' for the exact quad, 'corners' + 'labels' to 'CV Draw Labels', 'text' to 'Preview as Text'. Zero barcodes is a valid result (empty outputs, found=false), never an error. Processes a single image (the first frame of a batch). NOTE: unlike QR there is no encoder in OpenCV - this node only reads.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Barcode Detect
  • image
  • found
  • barcode_count
  • text
  • bboxes
  • corners
  • connections
  • texts
  • formats
  • labels
gradient_threshold64
downsampling_threshold512
detector_scales0.01, 0.03, 0.06, 0.08
Categoryimage/CV/codes

Inputs (4)

NameTypeDefaultDescription
imageNPARRAY,IMAGEImage to scan. An IMAGE batch uses its first frame; an NPARRAY (gray/BGR, any dtype) is treated as one frame. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
gradient_thresholdFLOAT640–255Minimum gradient magnitude for a pixel to count towards a bar region. LOWER it for faint, low-contrast or out-of-focus barcodes; raise it to reject busy background texture that looks like bars.
downsampling_thresholdoptFLOAT51264–8192Images larger than this (in pixels, on the shorter side) are downsampled before the SEARCH - decoding still happens at full resolution. Raise it when a small barcode in a big photo is missed.
detector_scalesoptSTRING0.01, 0.03, 0.06, 0.08Comma-separated relative scales the detector searches at, as a fraction of the image size. Add a larger value (e.g. 0.2) when the barcode fills much of the frame, a smaller one when it is tiny. Blank = OpenCV's defaults.

Outputs (9)

NameTypeDescription
foundBOOLEANTrue when at least one barcode was located. Feed a 'Basic data handling: IfElse' to branch instead of gating a node with a boolean widget.
barcode_countINTNumber of barcodes located.
textSTRINGEvery decoded payload, one per line - wire into the core 'Preview as Text' (PreviewAny) node. Empty when nothing decoded.
bboxesBOUNDING_BOXOne {x, y, width, height, score, label} dict per barcode (axis-aligned box around its 4 corners, label = decoded digits) - feed the core 'Draw BBoxes' node.
cornersNPARRAY(N*4, 2) float32: the 4 corner points of every barcode, in order. Feed 'CV Draw Points', or 'CV Draw Connections'/'Draw Labels' with the matching outputs. Empty (0, 2) when nothing is found.
connectionsNPARRAY(N*4, 2) int32 edge index-pairs closing each barcode's quad, indexed into 'corners' - feed 'CV Draw Connections' to outline the rotated region exactly.
textsNPARRAY(N,) string array of the decoded payloads, one per barcode. An empty entry means the barcode was located but could not be read.
formatsNPARRAY(N,) string array of the symbology per barcode ('EAN_13', 'EAN_8', 'UPC_A', 'UPC_E', or 'NONE' when only located).
labelsNPARRAY(N*4,) string array aligned row-for-row with 'corners': each barcode's text on its FIRST corner, blank on the other three. Feed 'corners' + this to 'CV Draw Labels' to write the digits once per barcode.