question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add the horizonal red line and yellow dots during codeReader.decodeFromVideoDevice

See original GitHub issue

Hi, Is there away to add features to help user to better orient the phone in front of the barcode? I am thinking about the horizontal red line and the yellow dots, like in the android app. or CornerDetector

here a running example to use for.

Thanks

<script
type="text/javascript" src="https://unpkg.com/@zxing/library@latest"></script>

<!--
<script type="text/javascript" src="xzing.js"></script>
-->

  <script type="text/javascript">

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

       // https://github.com/zxing-js/library/issues/374
       // enable TRY_HARDER using hints
        const hints = new Map(); // hints is a JS Map Object
        hints.set(ZXing.DecodeHintType.TRY_HARDER, true);
        // the code reader will enable try harder once it reads this

      // you gotta pass hints to the code reader to enable TRY_HARDER
      const codeReader = new ZXing.BrowserMultiFormatReader(
      // I broke this in new lines so I can comment and give you tips
            null,  // first param is a delay between scans
            hints // this allows you to customize code reader
        );


      console.log('ZXing code reader initialized')
      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', () => {
            var audio = new Audio('beep.mp3');
            codeReader.decodeFromVideoDevice(selectedDeviceId, 'video', (result, err) => {
              if (result) {
                audio.play();
                console.log(result)
                document.getElementById('result').textContent = result.text
                //Shiny.onInputChange("send_serialNumber_id",  result.text);
                Shiny.setInputValue("send_serialNumber_id",  result.text, {priority: "event"});
              }
              if (err && !(err instanceof ZXing.NotFoundException)) {
                console.error(err)
                document.getElementById('result').textContent = err
              }
            })
            console.log(`Started continous decode from camera with id ${selectedDeviceId}`)
          });

          document.getElementById('resetButton').addEventListener('click', () => {
            codeReader.reset()
            document.getElementById('result').textContent = '';
            console.log('Reset.')
          });

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
odahcamcommented, Feb 5, 2021

Transfering this issue to the browser repository. Once the main features are estabilished I can try to create such feature. Thanks.

1reaction
fydeliocommented, Jan 29, 2021

@kmezhoud, basically all you need to do is use the code provided and adapt for your needs. Bellows will give you a red horizontal line (not yet very stylish, but with some more css it’s easily improved). For dots basically just add further DIV elements with position: absolute and style them accordingly.

<div style="position: relative; width: 100%">
    <div style="position: absolute; height: 5px; background-color: red; top: 50%; left: 25%; right: 25%">
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ubuntu Manpage: ffplay - FFplay media player
FFplay is a very simple and portable media player using the FFmpeg libraries and the SDL library. It is mostly used as a...
Read more >
Control of Double Inverted Pendulum First Approach
An Inverted double pendulum is a combination of two individual pendulums which represents an example of a nonlinear and unstable dynamic system and...
Read more >
ffmpeg Documentation
The decoder produces uncompressed frames (raw video/PCM audio/. ... For example to enable repeated log output, add the level prefix, and set loglevel...
Read more >
Table of Contents - AUTEL
Put blocks in front of the drive wheels and never leave the vehicle ... Keep the scan tool dry, clean, free from oil/water...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found