【问题标题】:How to read multiple barcode reader?如何读取多个条码阅读器?
【发布时间】:2020-10-28 10:46:28
【问题描述】:

我想扫描图像中的所有一维条形码。 我正在使用@zxingjs/library,我可以扫描 1 个条形码,但不是全部。 我怎么能用nodejs做到这一点? 我知道有一个接口 MUltipleBarcodeReader 有 2 个方法,但我不知道如何在我的原型中使用它。

这是MultipleBarcodeReader

import BinaryBitmap from '../BinaryBitmap';
import DecodeHintType from '../DecodeHintType';
import Result from '../Result';
/**
 * Implementation of this interface attempt to read several barcodes from one image.
 *
 * @see com.google.zxing.Reader
 * @author Sean Owen
 */
export default interface MultipleBarcodeReader {
    /**
     * @throws NotFoundException
     */
    decodeMultiple(image: BinaryBitmap): Result[];
    /**
     * @throws NotFoundException
     */
    decodeMultiple(image: BinaryBitmap, hints: Map<DecodeHintType, any>): Result[];
}

这是我的原型:

const {MultipleBarcodeReader} = require('@zxing/library/esm/core/multi/MultipleBarcodeReader');

//I read image with fs and decode it
//hints

const multipleBarcodeReader = new MultipleBarcodeReader();
multipleBarcodeReader.setHints(hints);
const multipleResult = multipleBarcodeReader.decodeMultiple(binaryBitmap)

当我运行我的原型时,它给了我这个错误:

const multipleBarcodeReader = new MultipleBarcodeReader();
                              ^

TypeError: MultipleBarcodeReader is not a constructor
    at Object.<anonymous> (C:\Users\awais.ahmed\Desktop\ZXing\index.js:27:31)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

谢谢

【问题讨论】:

  • 您提供了很多信息,很有帮助!但是,如果您在 Google 上搜索“javascript 不是构造函数”,您可能会节省一些时间。结果包括 MDN 的页面 TypeError: "x" is not a constructor
  • 好的,谢谢。 MultipleBarcodeReader 是一个接口,那么我如何在我的原型中访问这个接口和他的方法?

标签: node.js zxing zxing-js


【解决方案1】:

在他们的 github Multiple Codes in one image #346 上,无法根据这个问题解码多个一维条码。该问题是最近的问题,因此请考虑在该问题中使用竖起大拇指的表情符号做出反应,以表明您想要该功能。我认为你发现的那种 TS 类型表明他们计划在某个时候实施它。

但是,您可以使用该库解码多个 PDF417 代码:

【讨论】:

    猜你喜欢
    • 2012-01-27
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多