lubo / zxinglight

A simple wrapper for ZXing C++
MIT License
8 stars 3 forks source link

I can not detect pdf417 #2

Closed alejotima closed 7 years ago

alejotima commented 7 years ago

Hi lubo, I am using your library to detect pdf417 barcode, but it does not detect it. zxing::ReaderException: No code detected this is the code I am using

import numpy as np
import cv2
from PIL import Image
from zxinglight import read_codes, BarcodeType

cap = cv2.VideoCapture(0)

while (True):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame', gray)
    pil = Image.fromarray(gray)
    width, height = pil.size
    raw = pil.tobytes()
    code = read_codes(pil, barcode_type=BarcodeType.NONE)
    for x in code:
        print(x)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
lubo commented 7 years ago

Hi, this is not zxinglight-specific behavior, it's just ZXing. First of all, try playing with try_harder and hybrid parameters. If that does not help, you should try different methods of thresholding. For instance, we at @devinsolutions have had much success using Otsu's method for thresholding images containing QR codes on large white background with plenty of text (legal documents, basically :smile:). We've improved ZXing QR code detection from 50% to pretty much 100% success rate using Otsu's. If any of that does not help, it might a be bug in ZXing itself or your images need different preprocessing methods.

P.S.: Please, close #1 if you've managed to make it work.