Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 getUserMedia camera focus

I've created a simple mobile application which shows the camera and decodes QRCodes with https://github.com/LazarSoft/jsqrcode

Because my camera is blurry, this works for big QRCodes. Is there a way to focus the camera with Javascript? So this also works for smaller images or is there another solution?

EDIT I've noticed that if I use the Android App (instead of the HTML5 version), it can handle way more color difference and can scan my codes, while jsqrcode cannot. Am I using the wrong library?

Using ZXING

My working code:

public void scan() {
    IntentIntegrator integrator = new IntentIntegrator(this);
    integrator.initiateScan();
}

 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
     // On Scan result we get get to this part
     try {
          IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
          if (scanResult != null) {
            // CODE

          }
     } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Also needed to add the import com.google.zxing.integration.android package to my project.

like image 704
Niels Avatar asked Nov 26 '13 14:11

Niels


1 Answers

Is the HTML5 version even working on your phone at all? CanIUse suggests that it shouldn't work on any mobile device except blackberry... but they are sometimes not up-to-date.

Either way - doubtful there's a one-size-fits-all solution with such a new API. Can you see about using the app (native code) version on phones and the flash-enabled version for desktops. You will have to perform your own device sniffing:

if( user_has_flash ) {
    // Load an HTML5/Flash solution
} else if( is_mobile_device) {
    // defer to the native code
    // zxing has a phonegap plugin - https://github.com/wildabeast/BarcodeScanner
} else {
    alert("Your device does not have scanning capabilities");
}
like image 110
Ryan Wheale Avatar answered Nov 13 '22 05:11

Ryan Wheale