title: cv2.waitKey(25) & 0xFF == ord('q'): and cv2.imwrite() not working
body: <p>I am following <a href="https://github.com/jg-fisher/dinoAI" rel="nofollow noreferrer">this</a> project to make a AI that plays Google Chrome Dino game. I am stuck at a point while capturing screen feed to generate training data. I am new to CV</p>
  
  <p>The project is supposed to supposed to break the video feed and save the CSV file in cv2.waitKey(25) &amp; 0xFF == ord('q'): condition. Which I believe is when key "q" is pressed. But nothing happens when I press 'q'. The print statement in this if condition doesn't print when I press q.</p>
  
  <p>Also although the console prints the print statement in 'up' ,'down' or 't' key pressed condition but the </p>
  
  <pre><code>cv2.imwrite('./images/frame_(0).jpg'.format(x), img) 
  </code></pre>
  
  <p>Doesn't seem to be working as no images in the images folder are saved. </p>
  
  <p>Here is the code</p>
  
  <pre><code>import cv2 
  from mss import mss 
  import numpy as np 
  import keyboard
  
  #Captures dinasour run for given coordinates
  
  def start():
      """
      Capture video feed frame by frame, crops out coods and the dino then process
      """
  
      sct = mss()
  
      coordinates = {
          'top': 168,
          'left': 230,
          'width': 624,
          'height': 141
      }
  
      with open('actions.csv','w') as csv:
          x = 0
          while True:
              img = np.array(sct.grab(coordinates))
  
              #crop out the dino from the image array
              img = img[::,75:624]
  
              #edge detection to reduce ammount of image processing work
              img = cv2.Canny(img, threshold1=100, threshold2=200)
  
              if keyboard.is_pressed('up arrow'):
                  cv2.imwrite('./images/frame_(0).jpg'.format(x), img)
                  csv.write('1\n')
                  print('jump write')
                  x += 1
  
              if keyboard.is_pressed('down arrow'):
                  cv2.imwrite('./images/frame_(0).jpg'.format(x), img)
                  csv.write('2\n')
                  print('duck')
                  x += 1
  
  
              if keyboard.is_pressed('t'):
                  cv2.imwrite('./images/frame_(0).jpg'.format(x), img)
                  csv.write('0\n')
                  print('nothing')
                  x += 1
  
              # break the video feed
              if cv2.waitKey(25) &amp; 0xFF == ord('q'):
                  csv.close()
                  cv2.destroyAllWindows()
                  print('Exited')
                  break
  
  def play():
      sct = mss()
  
      coordinates = {
          'top': 168,
          'left': 230,
          'width': 624,
          'height': 141
      }
  
      img = np.array(sct.grab(coordinates))
  
      # crop out the dinosaur from the image array
      img = img[::,75:615]
  
      # edge detection to reduce amount of image processing work
      img = cv2.Canny(img, threshold1=100, threshold2=200)
  </code></pre>