title: Unable to extract Qr code from a pdf file in Python , Opencv
body: <p>i am new in Python and Opencv,
  i wrote code for a simple app that converts pdf to image PNG and then by using opencv extracting the Qr code . it worked for some pdf files that i have done , but i have a specific document pdf that i want to extract the Qr code from it. after the conversion is done i got a message that says no Qr code found!</p>
  <p>well this is the only pdf file that is refusing to extract qr code from.</p>
  <p>my goal is to find a solution to extract the qr code from that specific pdf file and decode it</p>
  <p>here a screen capture for how cv2 selects the qr code after image convertion:</p>
  <p><a href="https://i.stack.imgur.com/VXyR6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VXyR6.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/VXyR6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VXyR6.png" alt="enter image description here" /></a></p>
  <p>what i have tried in Python</p>
  <pre><code>import cv2
  import os
  from wand.image import Image as wi
  PDFfile = wi(filename=&quot;Sources/certificatFaresBenslamaAr.pdf&quot;,resolution=400)
  Images = PDFfile.convert('png')
  ImageSequence = 1
  
  for img in PDFfile.sequence:
      Image = wi(image = img)
      Image.save(filename=&quot;Image&quot;+str(ImageSequence)+&quot;.png&quot;)
      ImageSequence += 1
  
      # read the QRCODE image
  image = cv2.imread(&quot;image1.png&quot;)
  # initialize the cv2 QRCode detector
  qrCodeDetector = cv2.QRCodeDetector()
  # detect and decode
  decodedText, points, straight_qrcode = qrCodeDetector.detectAndDecode(image)
  #points is the output array of vertices of the found QR code quadrangle
  #straight qrcode
  # if there is a QR code
  if points is not None:
      # QR Code detected handling code
  
      print('Decoded data: ' + decodedText)
      nrOfPoints = len(points)
      print('Number of points:  ' + str(nrOfPoints))
      points = points[0]
      for i in range(len(points)):
          pt1 = [int(val) for val in points[i]]
          pt2 = [int(val) for val in points[(i + 1) % 4]]
          cv2.line(image, pt1, pt2, color=(255, 0, 0), thickness=3)
    
      print('Successfully saved')
      cv2.imshow('Detected QR code', image)
      cv2.imwrite('Generated/extractedQrcode.png', image)
      cv2.waitKey(0)
      cv2.destroyAllWindows()
  else:
      print(&quot;QR code not detected&quot;)
      # display the image with lines
      # length of bounding box
  </code></pre>
  <p>My code worked very nice with an other pdf example but my goal is only to extract the pdf that i mentionned above.</p>
  <p>Here an example of a pdf that worked fine with my code:</p>
  <p><a href="https://i.stack.imgur.com/TMUwd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TMUwd.png" alt="enter image description here" /></a></p>
  <p>Note: I have noticed that the pdf file im scanning contains a selectable qrcode</p>
  <p><a href="https://i.stack.imgur.com/oXODV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oXODV.png" alt="enter image description here" /></a></p>