使用p:photoCam扫描二维码并解码。

huangapple go评论80阅读模式
英文:

Scan a QR code and decode it using p:photoCam

问题

我需要在摄像头捕获图像的同时捕获和读取QR码,在一个JSF应用程序中完成这个任务。

我已经成功地从照片中读取了QR码,但现在我需要使它在摄像头捕获的图像中"活跃"起来。

有人有什么建议吗?

我正在尝试使用PrimeFaces的p:photoCam组件。

以下是使用Zxing来读取QR码的方法:

/**
 * 
 * @param filePath
 * @param charset
 * @param hintMap
 * 
 * @return QR码的值 
 * 
 * @throws FileNotFoundException
 * @throws IOException
 * @throws NotFoundException
 */
public static String readQRCode(String filePath, String charset, Map hintMap)
    throws FileNotFoundException, IOException, NotFoundException {
  BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
      new BufferedImageLuminanceSource(
          ImageIO.read(new FileInputStream(filePath)))));
  Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap);
  return qrCodeResult.getText();
}

请注意,这是一个用于读取QR码的Java方法。

英文:

I need to capture and read a QR Code while the camera is capturing, all of this in a JSF Application.

I have already read a QR Code in a photo, but for now I have to make it "alive".

Anyone has any suggestion?

I'm trying to use the p:photoCam of PrimeFaces.

This is the method, using Zxing to read the QR code:

 /**
   * 
   * @param filePath
   * @param charset
   * @param hintMap
   * 
   * @return Qr Code value 
   * 
   * @throws FileNotFoundException
   * @throws IOException
   * @throws NotFoundException
   */
  public static String readQRCode(String filePath, String charset, Map hintMap)
      throws FileNotFoundException, IOException, NotFoundException {
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
        new BufferedImageLuminanceSource(
            ImageIO.read(new FileInputStream(filePath)))));
    Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap);
    return qrCodeResult.getText();
  }
}

答案1

得分: 3

PrimeFaces Extensions 10将拥有一个pe:codeScanner组件,用于从设备摄像头扫描条形码和QR码。

<!-- language: xhtml -->
<pe:codeScanner width="600"
                height="400">
  <p:ajax event="codeScanned"
          listener="#{codeScannerController.onCodeScanned}"/>
</pe:codeScanner>

源代码:https://github.com/primefaces-extensions/primefaces-extensions/blob/master/showcase/src/main/webapp/sections/codeScanner/example-basicUsage.xhtml

<!-- language: java -->
public void onCodeScanned(final SelectEvent<Code> event) {
    final Code code = event.getObject();
    FacesContext.getCurrentInstance().addMessage(
                null,
                new FacesMessage(FacesMessage.SEVERITY_INFO,
                            String.format("Scanned: %s (%s)", code.getValue(), code.getFormat()),
                            null));
}

源代码:https://github.com/primefaces-extensions/primefaces-extensions/blob/master/showcase/src/main/java/org/primefaces/extensions/showcase/controller/codescanner/CodeScannerController.java

英文:

PrimeFaces Extensions 10 will have a pe:codeScanner component to scan bar and QR codes from a device camera.

<!-- language: xhtml -->

&lt;pe:codeScanner width=&quot;600&quot;
                height=&quot;400&quot;&gt;
  &lt;p:ajax event=&quot;codeScanned&quot;
          listener=&quot;#{codeScannerController.onCodeScanned}&quot;/&gt;
&lt;/pe:codeScanner&gt;

Source: https://github.com/primefaces-extensions/primefaces-extensions/blob/master/showcase/src/main/webapp/sections/codeScanner/example-basicUsage.xhtml

<!-- language: java -->

public void onCodeScanned(final SelectEvent&lt;Code&gt; event) {
    final Code code = event.getObject();
    FacesContext.getCurrentInstance().addMessage(
                null,
                new FacesMessage(FacesMessage.SEVERITY_INFO,
                            String.format(&quot;Scanned: %s (%s)&quot;, code.getValue(), code.getFormat()),
                            null));
}

Source: https://github.com/primefaces-extensions/primefaces-extensions/blob/master/showcase/src/main/java/org/primefaces/extensions/showcase/controller/codescanner/CodeScannerController.java

huangapple
  • 本文由 发表于 2020年7月30日 21:19:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63174091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定