Я пытался создать компонент сканера штрих-кода в Angular 14. Не получаю точных результатов или сканирование занимает слишком много времени. Я пробовал сканировать штрих-коды EAN 13 и CODE 128. Ниже приведен код, который я пробовал с Quagga JS версии 0.12.1.
scanner.comComponent.html:
import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
// @ts-ignore
import Quagga from 'quagga';
@Component({
selector: 'app-scanner',
templateUrl: './scanner.component.html',
styleUrls: ['./scanner.component.css'],
})
export class ScannerComponent implements OnInit, OnDestroy {
barcodeResult: string = ''; // Variable to hold the scanned barcode value
constructor(private el: ElementRef) {}
ngOnInit(): void {
this.startScanner();
}
// Start the scanner
startScanner() {
this.barcodeResult = '';
// Set up QuaggaJS to start scanning from the webcam
navigator.mediaDevices
.getUserMedia({ video: { facingMode: 'environment' } })
.then((stream) = {
console.log('Camera access granted');
// Optional: You can also display the stream to the user for debugging
const videoElement = document.querySelector('video');
videoElement.srcObject = stream;
})
.catch((err) = {
console.error('Camera access denied:', err);
});
Quagga.init(
{
inputStream: {
name: 'Live',
type: 'LiveStream',
target: this.el.nativeElement.querySelector('#scanner-container'), // Target the video container
constraints: {
facingMode: 'environment', // Use the environment camera (back camera on mobile)
width: { ideal: 640 }, // Reduce the width of the video
height: { ideal: 480 }, // Reduce the height of the video
},
},
decoder: {
readers: ['code_128_reader', 'ean_reader', 'upc_reader', 'ean_13'], // Barcode types to scan
},
},
(err: any) = {
if (err) {
console.error('Error initializing Quagga', err);
return;
}
// Start the scanner once it's initialized
console.log('Quagga initialized successfully');
Quagga.start();
}
);
// Listen for the result of a scan
Quagga.onDetected((data: any) => {
console.log('Detection callback:', data);
if (data && data.codeResult && data.codeResult.code) {
this.barcodeResult = data.codeResult.code; // Update the scanned result
console.log('Scanned Barcode:', this.barcodeResult);
// Optionally, you can stop scanning after a successful scan:
Quagga.stop();
}
});
}
// Clean up when the component is destroyed
ngOnDestroy(): void {
Quagga.stop();
}
}
Я пытался создать компонент сканера штрих-кода в Angular 14. Не получаю точных результатов или сканирование занимает слишком много времени. Я пробовал сканировать штрих-коды EAN 13 и CODE 128. Ниже приведен код, который я пробовал с Quagga JS версии 0.12.1. scanner.comComponent.html: [code]
Scanned Barcode: {{ barcodeResult }}
Restart Scanner [/code] scanner.comComponent.ts: [code]import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; // @ts-ignore import Quagga from 'quagga';
@Component({ selector: 'app-scanner', templateUrl: './scanner.component.html', styleUrls: ['./scanner.component.css'], }) export class ScannerComponent implements OnInit, OnDestroy { barcodeResult: string = ''; // Variable to hold the scanned barcode value
constructor(private el: ElementRef) {}
ngOnInit(): void { this.startScanner(); }
// Start the scanner startScanner() { this.barcodeResult = ''; // Set up QuaggaJS to start scanning from the webcam navigator.mediaDevices .getUserMedia({ video: { facingMode: 'environment' } }) .then((stream) = { console.log('Camera access granted'); // Optional: You can also display the stream to the user for debugging const videoElement = document.querySelector('video'); videoElement.srcObject = stream; }) .catch((err) = { console.error('Camera access denied:', err); }); Quagga.init( { inputStream: { name: 'Live', type: 'LiveStream', target: this.el.nativeElement.querySelector('#scanner-container'), // Target the video container constraints: { facingMode: 'environment', // Use the environment camera (back camera on mobile) width: { ideal: 640 }, // Reduce the width of the video height: { ideal: 480 }, // Reduce the height of the video }, }, decoder: { readers: ['code_128_reader', 'ean_reader', 'upc_reader', 'ean_13'], // Barcode types to scan }, }, (err: any) = { if (err) { console.error('Error initializing Quagga', err); return; } // Start the scanner once it's initialized console.log('Quagga initialized successfully'); Quagga.start(); } );
// Listen for the result of a scan Quagga.onDetected((data: any) => { console.log('Detection callback:', data); if (data && data.codeResult && data.codeResult.code) { this.barcodeResult = data.codeResult.code; // Update the scanned result console.log('Scanned Barcode:', this.barcodeResult); // Optionally, you can stop scanning after a successful scan: Quagga.stop(); } });
}
// Clean up when the component is destroyed ngOnDestroy(): void { Quagga.stop(); } } [/code] scanner.comComponent.css: [code]#scanner-container { width: 100%; height: 600px; margin: 0 auto; }
Я пытался создать компонент сканера штрих-кода в Angular 14. Пробовал несколько библиотек, таких как ngx-barcode-scanner, zxing-js/ngx-scanner, Quagga JS и т. д. Но ни одна из них не дает точных результатов. p>
Пожалуйста, предложите библиотеку,...
Я использую Zen Barcode Rendering Framework для создания штрих-кодов в приложении формы Windows C#. У меня есть два текстовых поля (одно для самого штрих-кода и одно для соответствующего текста, который я хочу напечатать на этикетке со штрих-кодом)....
Я работаю с Android Google Vision API и создал стандартное средство чтения штрих-кодов, но хочу определить, какой тип/формат штрих-кода считывается , т. е. CODE 39,
CODE 128 , QR-код.... и т. д.
Я работаю с Android Google Vision API и создал стандартное средство чтения штрих-кодов, но хочу определить, какой тип/формат штрих-кода считывается , т. е. CODE 39,
CODE 128 , QR-код.... и т. д.
Мне нужна помощь в чтении чисел под штрих-кодом (не полос) из PDF-файла. Моя идея заключалась в том, чтобы преобразовать страницу в изображение и затем прочитать его.
Это пример штрих-кода, который расположен в верхней правой части PDF-документа....