How to use the command zbarcam (with examples)

How to use the command zbarcam (with examples)

The zbarcam command is used to scan and decode barcodes (and QR codes) from a video device. It continuously captures video from the device and prints the decoded information to the standard output (stdout). It is a handy tool for barcode scanning applications.

Use case 1: Continuously read barcodes and print them to stdout

Code:

zbarcam

Motivation: This use case is useful when you want to continuously scan and read barcodes from a video device and print the decoded information. It eliminates the need for manually triggering barcode scanning for each code.

Explanation: When the zbarcam command is executed without any arguments, it starts capturing video from the default video device (typically the webcam) and continuously scans for barcodes. Once a barcode is detected, it decodes the information and prints it to the stdout.

Example output:

UPC-E: 012345678905
QR-Code: https://example.com/product/1234

Use case 2: Disable output video window while scanning

Code:

zbarcam --nodisplay

Motivation: In some scenarios, you may not need the video window to be displayed while scanning barcodes. Disabling the output video window can improve performance, especially in headless environments or when the QR codes are not needed to be visually examined.

Explanation: The --nodisplay option is used to disable the output video window of zbarcam. When used, the actual video frames are not displayed to the screen, but the command continues to function normally by decoding the barcodes and printing them to stdout.

Example output:

EAN-13: 5901234123457
Code128: ABCD1234

Use case 3: Print barcodes without type information

Code:

zbarcam --raw

Motivation: In some cases, you may only be interested in the actual barcode value and do not require the type information (EAN, QR, etc.). By using the --raw option, you can print the barcode values without any type information, making the output more focused and concise.

Explanation: The --raw option instructs zbarcam to print the barcode values without any type prefix (EAN, QR, etc.) in the output.

Example output:

012345678905
https://example.com/product/1234

Use case 4: Define capture device

Code:

zbarcam /dev/video_device

Motivation: This use case is useful when you want to explicitly define the video device from which zbarcam should capture video. By specifying the device path, you can ensure that the correct video device is used for barcode scanning.

Explanation: The /dev/video_device argument is used to specify the video device for zbarcam. You need to replace /dev/video_device with the actual path of the video device on your system (such as /dev/video0). This ensures that zbarcam captures video from the specified device.

Example output:

Code39: ABC123
EAN-8: 01234567

Conclusion:

The zbarcam command is a handy tool for barcode scanning applications. It allows you to easily scan and decode barcodes from a video device. Whether you need continuous barcode scanning or want to customize the output, zbarcam provides various options to meet your requirements. By following the examples provided in this article, you can make efficient use of the zbarcam command in your barcode scanning projects.

Related Posts

Using airdecap-ng (with examples)

Using airdecap-ng (with examples)

Example 1: Remove wireless headers from an open network capture file and use the access point’s MAC address to filter airdecap-ng -b ap_mac path/to/capture.

Read More
How to use the command 'egrep' (with examples)

How to use the command 'egrep' (with examples)

The ’egrep’ command is a Linux utility used to search for patterns within files using extended regular expressions.

Read More
How to use the command 'docker swarm' (with examples)

How to use the command 'docker swarm' (with examples)

Docker Swarm is a container orchestration tool that allows you to create a swarm of Docker nodes and deploy services across them.

Read More