Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not reading 2d CODE_128 barcodes from camera #394

Closed
lormar71 opened this issue Jan 14, 2021 · 11 comments · Fixed by #574
Closed

Not reading 2d CODE_128 barcodes from camera #394

lormar71 opened this issue Jan 14, 2021 · 11 comments · Fixed by #574
Labels

Comments

@lormar71
Copy link

Hi.
I am trying to develop a web application that reads barcodes by using camera.
With two-dimensional codes of type DATA_MATRIX I have no problem.
But when my script tries to scan one-dimensional barcodes of type UCC-128 / CODE_128 [such as: (91)91792429(37)5760] it fails to decode it.
I am using the following code reader:
codeReader = new ZXing.BrowserMultiFormatReader();
Why does this happen?

Thank you!

Best regards,
Lorenzo

@lormar71 lormar71 added the bug label Jan 14, 2021
@ymzuiku
Copy link

ymzuiku commented Jan 20, 2021

I have same issue

@odahcam
Copy link
Member

odahcam commented Feb 5, 2021

Plase provide an example of your code or a demo so I can reproduce your issue.

@lormar71
Copy link
Author

lormar71 commented Feb 8, 2021

Here is my code:

$scope.camera = {};
$scope.camera.chkitem = chkitem;
$scope.camera.result = null;

let selectedDeviceId;

/*
const hints = new Map();
hints.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, [
													ZXing.BarcodeFormat.DATA_MATRIX,
													ZXing.BarcodeFormat.CODE_128
												 ]);
const codeReader = new ZXing.BrowserMultiFormatReader(hints);
*/

const codeReader = new ZXing.BrowserMultiFormatReader();

$scope.camera.running = false;

codeReader.listVideoInputDevices().then((videoInputDevices) => {
	
	const sourceSelect = document.getElementById('sourceSelect');
	selectedDeviceId = videoInputDevices[0].deviceId;
	
	if (videoInputDevices.length >= 1) {
		
		videoInputDevices.forEach((element) => {
			const sourceOption = document.createElement('option');
			sourceOption.text = element.label;
			sourceOption.value = element.deviceId;
			sourceSelect.appendChild(sourceOption);
		})

		sourceSelect.onchange = () => {
			selectedDeviceId = sourceSelect.value;
		};

		const sourceSelectPanel = document.getElementById('sourceSelectPanel');
		sourceSelectPanel.style.display = 'block';
	}

});

// Start
$scope.camera.start = function() {

	if(!$scope.camera.running) {

		$scope.camera.running = true;

		codeReader.decodeFromVideoDevice(selectedDeviceId, 'video', (result, err) => {

			if (result) {

				$scope.camera.result = result.text;
				document.getElementById('result').textContent = $scope.camera.result;

				$timeout(function () {
					$scope.camera.chkitem.measured_value = $scope.camera.result;
					$scope.modal.checkThisItem($scope.camera.chkitem);
					$scope.camera.reset();
					$scope.camera.close();
				}, 250);

			}

			if (err && !(err instanceof ZXing.NotFoundException)) {
				$scope.camera.result = null;
				document.getElementById('result').textContent = err;
				$scope.camera.chkitem.measured_value = null;
				$scope.modal.checkThisItem($scope.camera.chkitem);
			}
			
		});

	}
	
};

// Reset
$scope.camera.reset = function() {
	codeReader.reset();
	$scope.camera.running = false;
	$scope.camera.result = null;
	document.getElementById('result').textContent = '';
};

I need to acquire both DATA_MATRIX and CODE_128 barcodes.

I have also tried to narrow it down to only these two types of barcodes (see commented lines with Hints), but nothing changes. DATA_MATRIX are encoded correclty, CODE_128 are not acquired (nothing is returned).

Thanks,
Lorenzo

@odahcam
Copy link
Member

odahcam commented Feb 10, 2021

Understood, are you encoding your own codes? Could you provide some examples?

@lormar71
Copy link
Author

Here is an example of barcode that my software should be able to read:
barcode (1)

@lormar71
Copy link
Author

lormar71 commented Feb 11, 2021

The format of this barcode is "CODE_128" (type: "TEXT"). And it is correclty decoded by the ZXing Android app "Barcode scanner".

@NicoP-S
Copy link

NicoP-S commented Dec 8, 2021

I have a similar problem. a valid code_128 barcode which is decoded by the app fast can't be decoded in zxing-js port.
@odahcam have you any idea why this is not working?
I tried to compare the Code128Reader.ts with the original zxing (java) reader but cant't find any difference.

@mark99i
Copy link

mark99i commented Nov 9, 2022

I have same issue

@jumafuse
Copy link

Same issue here

@jumafuse
Copy link

An update on this problem would be appreciated, a bounty can be offered.

@teckel12
Copy link

I believe I know what the problem is (if you're using a mobile phone to scan). Phones almost always have multiple cameras these days. And the code is just picking the first camera device (which for me was a camera with manual focus only and no torch):

videoInputDevices[0].deviceId

Instead, you should be selecting the most approprate camera for barcode scanning (which includes auto focus and torch). I forked a Vue library and added new features to select the correct camera for barcode scanning, and allow the user to turn on the torch (flash) as well as control the zoom, manual focus, and landscape mode. All of these features are designed to result in a much higher scanning ability. For example, with my library, I can easily scan the barcode shown above.

Here's a link to a demo of my Vue library (which uses zxing-js library for scanning). Visit the link from your phone (Android/Chrome supports all features, iOS/Safari will have a reduct functionally as they don't allow the user to get info on camera devices nor control the camera.

https://pcyvsp-5173.csb.app/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants