library icon indicating copy to clipboard operation
library copied to clipboard

read only pdf417 barcode

Open amdawadi22 opened this issue 3 years ago • 3 comments

@odahcam I have driver's license and there is more then one different type of barcode on card. but, I want to scan and decode only pdf417 barcode via video streaming in pure JavaScript. I added hints also to scan and decode only pdf417 barcode but it's not working properly for all card. I also attached my code. Anyone suggest me if any change need to be require in my code.

window.addEventListener('load', function () {
      
      let selectedDeviceId;

      const hints = new Map();
      const formats = [ZXing.BarcodeFormat.PDF_417];
      const CHARSET = 'utf-8';
      hints.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, formats);
      hints.set(ZXing.DecodeHintType.CHARACTER_SET, CHARSET);
      hints.set(ZXing.DecodeHintType.TRY_HARDER, true);
      hints.set(ZXing.DecodeHintType.PURE_BARCODE, true);

      const codeReader = new ZXing.BrowserMultiFormatReader(hints);
      
      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'
              }

              document.getElementById('startButton').addEventListener('click', () => {
                  codeReader.decodeFromVideoDevice(selectedDeviceId, 'video', (result, err) => {
                      if (result) {
                          document.getElementById('result').textContent = result.text
                          console.log(result)
                      }
                      if (err && !(err instanceof ZXing.NotFoundException)) {
                           debugger;
                           console.error(err)
                      }
                  })
                  console.log(`Started continous decode from camera with id ${selectedDeviceId}`)
              })

          })
          .catch((err) => {
              console.error(err)
          })
  })
</script>

I attached two card. the first one decode properly but in second card I didn't get any result.

please suggest me. what i need to change or tell me if any problem with Zxing.js

card2

card1

amdawadi22 avatar Apr 13 '21 08:04 amdawadi22

+1

tomasmendesr avatar May 05 '21 12:05 tomasmendesr

You can use: const codeReader = new ZXing.BrowserPDF417Reader(); instead of multi reader

Serginho avatar Jul 02 '21 12:07 Serginho

Stale issue message

github-actions[bot] avatar Apr 29 '24 13:04 github-actions[bot]