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

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

Scan a QR code and decode it using p:photoCam

问题

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

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

有人有什么建议吗?

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

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

  1. /**
  2. *
  3. * @param filePath
  4. * @param charset
  5. * @param hintMap
  6. *
  7. * @return QR码的值
  8. *
  9. * @throws FileNotFoundException
  10. * @throws IOException
  11. * @throws NotFoundException
  12. */
  13. public static String readQRCode(String filePath, String charset, Map hintMap)
  14. throws FileNotFoundException, IOException, NotFoundException {
  15. BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
  16. new BufferedImageLuminanceSource(
  17. ImageIO.read(new FileInputStream(filePath)))));
  18. Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap);
  19. return qrCodeResult.getText();
  20. }

请注意,这是一个用于读取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:

  1. /**
  2. *
  3. * @param filePath
  4. * @param charset
  5. * @param hintMap
  6. *
  7. * @return Qr Code value
  8. *
  9. * @throws FileNotFoundException
  10. * @throws IOException
  11. * @throws NotFoundException
  12. */
  13. public static String readQRCode(String filePath, String charset, Map hintMap)
  14. throws FileNotFoundException, IOException, NotFoundException {
  15. BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
  16. new BufferedImageLuminanceSource(
  17. ImageIO.read(new FileInputStream(filePath)))));
  18. Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap);
  19. return qrCodeResult.getText();
  20. }
  21. }

答案1

得分: 3

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

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

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

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

源代码: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 -->

  1. &lt;pe:codeScanner width=&quot;600&quot;
  2. height=&quot;400&quot;&gt;
  3. &lt;p:ajax event=&quot;codeScanned&quot;
  4. listener=&quot;#{codeScannerController.onCodeScanned}&quot;/&gt;
  5. &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 -->

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

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:

确定