title: PyTesseract works great with this code, but not my code (with minimal differences)
body: <p>I'm trying to use <a href="https://www.pyimagesearch.com/2020/05/25/tesseract-ocr-text-localization-and-detection/" rel="nofollow noreferrer">this tutorial</a> to have PyTesseract OCR my desktop. It works when I run that script, as you can see by this image:</p>
  <p><a href="https://i.stack.imgur.com/rgwEJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rgwEJ.png" alt="this image" /></a>,</p>
  <p>The code from the <strong>tutorial</strong>:</p>
  <pre><code>#Construct arg parser and parse arg's
  ap = argparse.ArgumentParser()
  ap.add_argument(&quot;-i&quot;, &quot;--image&quot;, required=True, help=&quot;path to input image to be OCR'd&quot;)
          # '--image' refers to the path of the input image that will be OCR'd
  
  ap.add_argument(&quot;-c&quot;, &quot;--min-conf&quot;, type=int, default=0, help=&quot;min conf value to filter weak text detection&quot;)
          # sets a min conf to filter weak detections
  args = vars(ap.parse_args())
  
  
  #Load input image, convert from BGR to RGB ch ordering, and
  # use Tesseract to localize each area of text in the input image
  image = cv2.imread(args[&quot;image&quot;] )
  rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  results = pytesseract.image_to_data(rgb, output_type=Output.DICT)
      # 'image_to_data' detects and localizes text 
  
  
  #Loop over each indiv text localizations
  for i in range(0,  len(results[&quot;text&quot;] )  ):
      #extract bounding box coordinates of the text region from the current result
      x = results[&quot;left&quot;][i]
      y = results[&quot;top&quot;][i]
      w = results[&quot;width&quot;][i]
      h = results[&quot;height&quot;][i]
  
      #extract OCR itself along with conf of text localztn
      text = results[&quot;text&quot;][i]
      print(results[&quot;conf&quot;][i])
      conf = int( results[&quot;conf&quot;][i] )
  
  
  #Filter out weak conf text localztns
      if conf &gt; args[&quot;min_conf&quot;]:
  
          #display conf and text to terminal
          print(&quot;Confidence: {}&quot;.format(conf) )
          print(&quot;Text: {}&quot;.format(text) )
          print(&quot;&quot;)
  
          #remove non-ASCII text so we can draw text on image using OpenCV, then draw bounding box around text with text itself
          text = &quot;&quot;.join( [c if ord(c) &lt; 128 else &quot;&quot; for c in text] ).strip()
          cv2.rectangle(image,  (x,y),  (x+w, y+h),  (0, 255, 0), 2 )
          cv2.putText(image, text, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 255), 3)
  
      #Show output image
      cv2.imshow(&quot;Image&quot;, image)
      cv2.waitKey(0)      # makes it so that it'll wait for you to hit a key before it continues
  </code></pre>
  <p>but it doesn't work when I try to implement it into another project. Here's <em>my</em> code:</p>
  <pre><code>screenshotOfDesktop = pyautogui.screenshot('screenshotOfDesktop.png')
  
  #have Tesseract read it
  readDesktop_SAP = cv2.imread('screenshotOfDesktop.png')
  
  #convert data to string
  rgb = cv2.cvtColor(readDesktop_SAP, cv2.COLOR_BGR2RGB)
  
  results = pytesseract.image_to_data(rgb, config='--psm 7', output_type=Output.DICT)
      # &quot;config= '--psm 7' &quot; makes it so that PyTesseract reads everything as a single line of text
  print(results)
  
  # Iterating through the list of results
  for i in range(0,  len(results[&quot;text&quot;] )  ):
      if &quot;Description&quot; not in results[&quot;text&quot;]:
  
          print(&quot;Didn't find description on screen. Please check that the SAP 'find document' page is open on the screen. &quot;)
          input('Press ENTER to exit now. ')
          exit()
      
      if &quot;Description&quot; in results[&quot;text&quot;]:
          print(&quot;Found 'Description' on screen! &quot;)
  
          # Gating by confidence
          conf = int(results[&quot;conf&quot;][i])
          if conf &lt; 0.2:
              print(&quot;Confidence is less than 0.7. Moving on. &quot;)
              continue
  
          elif conf &gt;= 0.2:
              # Getting the coordinates of the result
              Desc_x = results[&quot;left&quot;][i]
              Desc_y = results[&quot;top&quot;][i]
              Desc_w = results[&quot;width&quot;][i]
              Desc_h = results[&quot;height&quot;][i]
              # Printing everything
              print(&quot;The coordinates are: &quot;)
              print(x, y, width, height)
              print(f&quot;Confidence = {conf}&quot;) 
  #  
  </code></pre>
  <p>Instead, my code only spits out this for the &quot;results&quot; list:</p>
  <pre><code>{'level': [1, 2, 3, 4, 5, 5], 'page_num': [1, 1, 1, 1, 1, 1], 'block_num': [0, 1, 1, 1, 1, 1], 'par_num': [0, 0, 1, 1, 1, 1], 'line_num': [0, 0, 0, 1, 1, 1], 'word_num': [0, 0, 0, 0, 1, 2], 'left': [0, 0, 0, 0, 0, 1451], 'top': [0, 4, 4, 4, 4, 145], 'width': [1920, 1727, 1912, 1727, 891, 276], 'height': [1080, 1061, 1070, 1061, 1061, 8], 'conf': ['-1', '-1', '-1', '-1', 11, 0], 'text': ['', '', '', '', 'fe', '~']}
  </code></pre>
  <p>Does anyone have any clue on why that might be? I understand I'm not using argparser like the writer is, but it should be the same result, no? I checked to make sure that it was looking at the right screenshot as well.</p>
  <p>Relevant information:</p>
  <ol>
  <li>Tesseract v4.1.0.20190314</li>
  <li>Python 3.9.2</li>
  </ol>