title: Preprocessing images for QR detection in python
body: <p>I used Zbar and OpenCV to read the QR code in the image below but both failed to detect it. For ZBar, I use pyzbar library as the python wrapper. There are images that QR is detected correctly and images really similar to the successful ones that fail. My phone camera can read the QR code in the uploaded image which means it is a valid one. Below is the code snippet:</p>
  
  <pre><code>from pyzbar.pyzbar import decode
  from pyzbar.pyzbar import ZBarSymbol
  import cv2
  
  # zbar    
  results = decode(cv2.imread(image_path), symbols=[ZBarSymbol.QRCODE])
  print(results) 
  
  # opencv
  qr_decoder = cv2.QRCodeDetector()
  data, bbox, rectified_image = qr_decoder.detectAndDecode(cv2.imread(image_path))
  print(data, bbox)
  </code></pre>
  
  <p>What type of pre-processing will help to increase the rate of success for detecting QR codes?</p>
  
  <p><a href="https://i.stack.imgur.com/92iKG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/92iKG.jpg" alt="the image attached"></a></p>