1

ZBarSDK 对普通 QRCode 图像工作正常,白色背景上的黑色代码,但它没有检测到深色背景上白色代码的 QRCode 图像?

4

2 回答 2

0

这可以通过使用 Zxing Lib 对 GreyscaleLuminanceSource 文件的 getMatrix() 方法进行以下更改来实现。

替换下面的方法。

ArrayRef<char> GreyscaleLuminanceSource::getMatrix() const {
  int size = getWidth() * getHeight();
  ArrayRef<char> result (size);
  if (left_ == 0 && top_ == 0 && dataWidth_ == getWidth() && dataHeight_ == getHeight()) {
    memcpy(&result[0], &greyData_[0], size);
  } 
else {
    for (int row = 0; row < getHeight(); row++) {
      memcpy(&result[row * getWidth()], &greyData_[(top_ + row) * dataWidth_ + left_], getWidth());
    }
  }
    for (int i = 0; i < size; i++)
    {
        int val = static_cast<int>(result[i]);
        unsigned char cz = (255 -  val);
        result[i] = cz;
    }
  return result;
}

现在它只能读取非白色背景上的倒置二维码图像白色代码。

更多说明: 反转像素 - zxing

于 2013-07-09T04:37:22.253 回答
0

只需对 ZBarCaptureReader.m 进行一些更改,您就可以使用 ZBarSDK 读取常规和反向二维码:

unsigned int frameCounter = 0; // ADD THIS (only invert every few frames)

@implementation ZBarCaptureReader

// ... in this function ...
- (void)  captureOutput: (AVCaptureOutput*) output
  didOutputSampleBuffer: (CMSampleBufferRef) samp
         fromConnection: (AVCaptureConnection*) conn {

    // ...around line 300...
    //void *data = CVPixelBufferGetBaseAddressOfPlane(buf, 0);
    unsigned char *data = CVPixelBufferGetBaseAddressOfPlane(buf, 0);

    if (data) {

        // AND ADD THIS
        if (frameCounter++ % 3 == 0) {
            unsigned long size = w * h;
            for (unsigned long i = 0; i < size; i++) {
                data[i] = ~data[i];
            }
        }

而已。到目前为止效果很好。

于 2013-07-25T01:45:18.333 回答