Ios ZBARDK未读取非白色背景的二维码

Ios ZBARDK未读取非白色背景的二维码,ios,xcode,qr-code,zxing,zbar-sdk,Ios,Xcode,Qr Code,Zxing,Zbar Sdk,ZBarSDK对正常QRCode图像、白色背景上的黑色代码工作正常,但对黑色背景上的白色代码的QRCode图像检测不到?这可以通过使用Zxing Lib在GreyscaleLuminanceSource文件的getMatrix()方法中进行以下更改来实现 替换以下方法 ArrayRef<char> GreyscaleLuminanceSource::getMatrix() const { int size = getWidth() * getHeight(); ArrayRe

ZBarSDK对正常QRCode图像、白色背景上的黑色代码工作正常,但对黑色背景上的白色代码的QRCode图像检测不到?

这可以通过使用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;
}
ArrayRef GreyscaleLuminanceSource::getMatrix()常量{
int size=getWidth()*getHeight();
ArrayRef结果(大小);
如果(左&&top&&dataWidth&&getWidth()&&dataHeight&=getHeight()){
memcpy(&result[0],&greyData[0],size);
} 
否则{
对于(int row=0;row
现在它只能在非白色背景上读取倒置的二维码图像和白色代码

如需进一步澄清:

只需对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];
            }
        }
unsigned int frameCounter=0;//添加此项(仅每隔几帧反转一次)
@实现ZBarCaptureReader
// ... 在这个函数中。。。
-(void)captureOutput:(AVCaptureOutput*)输出
didOutputSampleBuffer:(CMSampleBufferRef)samp
fromConnection:(AVCaptureConnection*)连接{
//…在300线附近。。。
//void*data=CVPixelBufferGetBaseAddressOfPlane(buf,0);
unsigned char*data=CVPixelBufferGetBaseAddressOfPlane(buf,0);
如果(数据){
//再加上这个
如果(帧计数器+++%3==0){
无符号长尺寸=w*h;
for(无符号长i=0;i

就是这样。到目前为止效果很好。

您使用的是哪个版本的ZBar?这个版本的ZBar目前不进行黑白扫描。如果您要扫描的QR码总是黑白相间的,您可以尝试在ZBar处理前反转实时图像。您能解释一下,如何操作吗?或者可以建议其他任何有帮助的库我出去..也许这会有助于找到另一个图书馆: