|
| 1 | +# Command-Line Barcode & QR Code Reader (C++) |
| 2 | + |
| 3 | +This example shows how to build and run a C++ command-line app that reads barcodes/QR codes from: |
| 4 | + |
| 5 | +- A single image/PDF/TIFF file |
| 6 | +- A directory (processed recursively) |
| 7 | +- Multiple paths passed in one command |
| 8 | + |
| 9 | +The app is implemented in [`main.cpp`](./main.cpp) and uses **Dynamsoft Capture Vision Router** with the `PT_READ_BARCODES` preset template. |
| 10 | + |
| 11 | +## Supported input formats |
| 12 | + |
| 13 | +The sample accepts these file extensions: |
| 14 | + |
| 15 | +- `.jpg`, `.jpeg`, `.png`, `.bmp`, `.gif` |
| 16 | +- `.tif`, `.tiff` |
| 17 | +- `.pdf` |
| 18 | + |
| 19 | +## Build |
| 20 | + |
| 21 | +From this folder (`examples/command-line`): |
| 22 | + |
| 23 | +```bash |
| 24 | +mkdir -p build |
| 25 | +cd build |
| 26 | +cmake .. |
| 27 | +cmake --build . --config Release |
| 28 | +``` |
| 29 | + |
| 30 | +After building, the executable is generated in `build/`: |
| 31 | + |
| 32 | +- Linux/macOS: `./main` |
| 33 | +- Windows: `./Release/main.exe` (or `./main.exe` depending on generator) |
| 34 | + |
| 35 | +> During post-build steps, required Dynamsoft libraries, `Templates/`, and `Models/` are copied next to the executable automatically. |
| 36 | +
|
| 37 | +## Run |
| 38 | + |
| 39 | +### 1) Process a single file |
| 40 | + |
| 41 | +```bash |
| 42 | +./main ../single_page.tif |
| 43 | +``` |
| 44 | + |
| 45 | +### 2) Process a directory recursively |
| 46 | + |
| 47 | +```bash |
| 48 | +./main ../../images |
| 49 | +``` |
| 50 | + |
| 51 | +### 3) Process multiple paths in one command |
| 52 | + |
| 53 | +```bash |
| 54 | +./main ../single_page.tif ../multi_page.tif ../../images |
| 55 | +``` |
| 56 | + |
| 57 | +### 4) Interactive mode |
| 58 | + |
| 59 | +If no arguments are provided, the app enters interactive mode: |
| 60 | + |
| 61 | +```bash |
| 62 | +./main |
| 63 | +``` |
| 64 | + |
| 65 | +Then type a full file or directory path. Enter `q` to quit. |
| 66 | + |
| 67 | +## Output behavior |
| 68 | + |
| 69 | +- **Single file**: prints detailed results (format, text, and quadrilateral points per barcode). |
| 70 | +- **Directory**: prints per-file summary and directory statistics. |
| 71 | +- **Multiple inputs**: prints per-input results and an overall summary. |
| 72 | + |
| 73 | +## License key |
| 74 | + |
| 75 | +The demo initializes a trial license in source code. For production use, replace it with your own key in `main.cpp`: |
| 76 | + |
| 77 | +```cpp |
| 78 | +CLicenseManager::InitLicense("LICENSE-KEY", szErrorMsg, 256); |
| 79 | +``` |
| 80 | +
|
| 81 | +Get a trial license here: |
| 82 | +
|
| 83 | +- https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform |
| 84 | +
|
| 85 | +## Sample files in this folder |
| 86 | +
|
| 87 | +- `single_page.tif` |
| 88 | +- `multi_page.tif` |
| 89 | +- `multi_page.pdf` |
| 90 | +- `test.pdf` |
| 91 | +
|
| 92 | +You can use these files to quickly validate decoding. |
0 commit comments