You wired a USB camera into an OCR step in LabVIEW, the print is crisp to your eye, and the run dies with Error -1074395989 at IMAQ OCR Read File: Unable to read data — or the VI runs clean and hands back an empty string. Both symptoms come from the same place: the character set. One command loads a trained set from disk; another performs recognition on the image. When the loader sits where the recognition belongs, or no trained set exists, OCR cannot return text. This page separates the two failures, gives the wiring order that works, walks through training X and O in the OCR training application, and sets the pixel, focus and light conditions that make a trained set read reliably at runtime.
Separate the two failures first
Both symptoms trace to the character set — the trained data an OCR session reads glyphs with — but they fail at different steps, and the fixes differ. Diagnose before you touch code.
| Symptom | What the wired step actually is | Test | Fix |
|---|---|---|---|
| Error -1074395989, "Unable to read data", at IMAQ OCR Read File | The loader: it reads trained set data from disk into the session | Does the path point to a set file, and does that file hold trained glyphs? | Load a real trained set with the read character set file command; recognize with the read string command |
| No error, empty string on clearly legible characters | Recognition runs, but nothing usable sits behind it | Open the set file in the OCR training application: was anything ever trained and saved? | Train the glyphs on runtime-like images, save the set, load it before reading |
The error names a file read because that is what the failing call does: it reads character-set data from a file. The read string command is the step that inspects the image and returns text. Fixing the wiring takes a minute and removes the error — and uncovers the second failure, because a set that was never trained cannot return text either.
Wire the OCR chain in this order
The chain runs in one direction: acquire, prepare, load, restrict, recognize.
- Acquire one frame from the USB camera into an image buffer, under the lighting you will run with.
- Prepare the image exactly as you will at runtime: same grayscale conversion, same threshold. A threshold that differs between training and reading is the most common silent failure.
- Load the set. The read character set file step — the IMAQ OCR Read Character Set File VI — pulls the trained set from disk into the session. Wire error out of each node into error in of the next, so a bad path stops the chain visibly instead of flowing on; the VI's own help window in LabVIEW documents the connector names.
- Restrict the alphabet. With the session loaded, the IMAQ OCR Set Valid Characters VI limits what the reader may return: for a starting-player check, X and O and nothing else, so H and 0 stop being legal answers.
- Recognize. Run the read string command on the prepared image with the loaded session — the step the loader was standing in for.
- Check the error cluster last. A stop at step 3 means the set file; a clean run with an empty string means training data or image quality, and the next section handles that.
Train the set the read string command expects
An empty result is a data problem before it is a tuning problem: if no glyph was ever trained, there is nothing to match. The set comes from the OCR training application that ships with the vision software.
- Create a new character set and name it for what it reads: "XO marker, printed, 4 mm" beats "set1".
- Train on images captured exactly as runtime — same USB camera, same distance, same light, same threshold. A set trained on screenshots from a different camera reads nothing at runtime.
- Train every glyph the task needs: X and O now, digits and symbols the moment the task grows.
- Give several samples per glyph, shifted and tilted by a few degrees, so small placement variation does not break the match.
- Save the set file, then test inside the training tool on an image the trainer never saw. When that read returns X or O, the set is ready for the VI.
If a set exists and still reads poorly at runtime, walk every parameter the runtime must repeat: OCR trains but fails at runtime: set every parameter lists them one by one.
Give the characters enough pixels
Characters can be perfectly legible to you and still be untrainable. Two bands decide it. Keep characters at least 20 pixels tall — 30 to 40 reads more reliably — and strokes 2 to 6 pixels wide. The basis is what the trainer can see: it needs roughly two pixels across a stroke to separate stroke from background, and below about 20 pixels of height, look-alike glyphs such as O and 0 start collapsing into each other, the confusion covered in OCR confusing similar characters: fix resolution and contrast. The height floor itself is developed in Minimum font size for OCR: why small text fails and how to fix it.
Worked example: 4 mm marks, one camera, two distances
Take a 640 × 480 USB camera reading printed X and O marks 4 mm tall with 0.5 mm strokes; square pixels assumed, which a 4:3 sensor over a 4:3 field of view preserves.
- Close: 64 mm field of view. s = 640 / 64 = 10 px/mm. Height h = 4 mm × 10 px/mm = 40 px. Stroke w = 0.5 mm × 10 px/mm = 5 px. Both inside the bands — train and read at this geometry.
- Far: 160 mm field of view. s = 640 / 160 = 4 px/mm. h = 4 × 4 = 16 px, w = 0.5 × 4 = 2 px. Height under the 20 px floor: expect empty reads and confused glyphs.
- Far, 1280 pixel camera: s = 1280 / 160 = 8 px/mm. h = 4 × 8 = 32 px, w = 0.5 × 8 = 4 px. Back inside the bands without moving the rig.
Two inputs move the number, both linearly: field of view and sensor width. Halve the field of view and px/mm doubles; double the pixels at the same field of view and px/mm doubles. Run your own numbers here:
Light, focus and threshold: why legible print still fails
- Focus at the pixel level, not by eye. Zoom the live image to 100 %: a 5 px stroke smeared into a 10 px soft band is out of focus, and the trainer will read the blur as a different glyph.
- Set the threshold from the histogram. A printed mark gives two peaks — strokes and background — so put the threshold in the valley between them and use that same value in the OCR training application and in the VI.
- Keep the light fixed between training and reading. The threshold is a statement about contrast; move the desk lamp and the histogram moves out from under it.
- Kill glare before it reaches the sensor. Glossy ink and laminated cards mirror the room's lights into the strokes; angle or diffuse the source.
- Exploit color for contrast: illuminate in a color the ink absorbs. A red mark on white paper goes dark under blue light while the paper stays bright — instant stroke separation.
That last dial is what a built-in multi-color light source buys on an industrial camera: the MV-SC6050C-08M-XBN smart camera pairs a 5 MP color sensor with a multi-color light source behind an 8 mm M12-mount lens, so illumination color becomes a contrast control you turn until the strokes separate.
- Interface
- GigE
- Resolution
- 5 MP
- Sensor format
- 1/1.45"
- Shutter
- Global
One more camera note: most USB webcams use a rolling shutter, which is fine for a static board and wrong for anything moving past the frame. Pick a global shutter model once parts move.
Keep OCR, or read a code instead: the decision per case
OCR earns its training cost when the text itself carries the information: a date code, a serial number, a name. When the job is only "which of two states?", glyph matching is overhead — any unique, robustly detectable mark does it better. A 2D code printed on the same card decodes with built-in error correction, tolerates rotation and needs no font training; that is fixed code readers territory, and OCR on a fixed code reader: multiple text strings in one image shows readers reading text too.
The decision, per case:
- Lab bench, static board, printed glyphs: keep the USB camera and the OCR chain above. It works once the set is trained and the geometry holds 20-40 px characters.
- The same check moving onto a line: move it onto a smart camera and drop the PC. The LS-SMC-0017 runs the inspection on an X86 platform with a global shutter, a C-mount lens and a USB connection, so the lens becomes a replaceable part.
- Any unique marker acceptable and cycle time matters: print a 2D code and read it with a reader instead of training a font.
- Interface
- USB 2.0
- Resolution
- 6-10 MP
- Sensor format
- 1"
- Shutter
- Global
The code-reader alternative in one line: the MV-ID813M-05S-WBN-SR carries its own white light, a 1.3 MP sensor and a 4.9 mm lens at an M10 mount, while the compact LS-CRD-0047 reads over USB 2.0 at a 60-120 mm reading distance, keeping the USB cabling you already run.
- Interface
- GigE
- Resolution
- Up to 3 MP
- Lens mount
- M10
- Resolution
- Up to 3 MP
- Shutter
- Global
- Interface
- USB
Get the string out without breaking it
The string is only useful when it arrives whole. On a smart camera the result leaves over TCP: Smart camera OCR string output over TCP: how to send it shows the send, and Smart camera LabVIEW integration: use inspection results as data shows LabVIEW consuming results as data. Downstream, framing is the classic failure: extra characters break equality checks in PLC string compares, a pattern documented in RSLogix 5000 OCR string comparison: detecting extra characters, and a receiver waiting for a terminator can hold everything after the first character, as in USB barcode scanner sends only one character to an HMI. Fix the width and the terminator on both ends before blaming the reader.
Checks before you call it solved
- The set file exists, holds trained glyphs, and loads without error before the read string step runs.
- The error cluster is wired through every vision node, so the failing step names itself.
- Valid characters are restricted to the glyphs you trained.
- A live frame at the running distance shows 20-40 px character height and 2-6 px strokes.
- The threshold sits in the histogram valley, identical in training and runtime, with the light untouched.
- Ten consecutive correct reads on images the trainer never saw, including one slightly tilted board and one slightly shifted.
- The result string carries the width and terminator the receiver expects.
Bottom line: load before you recognize, train X and O in the OCR training application under runtime conditions, and hold 20-40 px characters under a fixed light — then the USB-camera OCR returns X or O every time the board is in focus. When the check outgrows the bench, size the hardware in the camera finder, browse more character-reading fixes on the code reading topic page, or write to us through the contact page with the symptom, the trained set and one saved frame.
The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.
Questions
Why does the OCR error mention reading a file when I want to read characters?
Error -1074395989 at IMAQ OCR Read File comes from the loading side of OCR: that step reads the trained character set from disk into the session before any recognition happens. It fails with Unable to read data when the path holds no trained set, or when it sits in the slot where the read string command should run. Check that a trained set file exists, put the load before the read, and chain the error cluster so the failing step names itself.
Does a 1920 x 1080 USB camera fix small characters automatically?
No. Pixels per millimeter is the number that matters, not the sensor headline. Over the same 160 mm field of view, a 1280 pixel camera gives 8 px/mm and a 4 mm character lands at 32 pixels tall; a 1920 pixel camera gives 12 px/mm and 48 pixels. Both clear the 20 pixel floor, but neither repairs missed focus or a shifted threshold. Change distance, resolution and light together, then retrain.
How many training samples does each character need?
Plan on five to ten samples per glyph, captured at slight position shifts and a few degrees of tilt, all under the runtime lighting and threshold. Add more for pairs your application confuses, such as O and 0. Quality beats quantity: ten samples from the same camera, distance and light outperform fifty collected from other sources.
It reads O but returns nothing for X - is the character set broken?
More likely the X samples, not the set. Check three things: the X strokes are at least 2 pixels wide at runtime scale, the X training images were shot under the same threshold as the O ones, and the valid characters list includes X. Then add a few more X samples with small shifts. A one-sided failure almost always lives in the one-sided glyph's data.
Will an industrial smart camera replace this LabVIEW setup?
On a production line, yes, and it removes the PC: a smart camera runs the inspection on the device and publishes the result string over TCP. Keep the LabVIEW and USB-camera bench when the task is a project, a prototype or a graded build, where its flexibility pays. The rig you trained on is the rig that reads; move the hardware only when the check itself moves.



