title: OpenCV clear screen
body: <h1>Problem</h1>
  
  <p>I'm using <code>OpenCV</code> in <code>Python</code> make a program to crop images into squares.</p>
  
  <p>It draws a square to show the selected area so I have to clear the screen with the image before drawing a new square, but <strong>unless I read the image again the code doesn't clear the screen</strong>.</p>
  
  <h3>This code doesn't work:</h3>
  
  <pre><code># Get Image
  img = cv2.imread(path,-1)
  DEFAULT = cv2.imread(path,-1)
  
  # Draw Function
  def draw(event,x,y,flags,param):
      if event == cv2.EVENT_LBUTTONDOWN:
          drawing = True
          # Set initial points
          ix,iy = x,y
  
      elif event == cv2.EVENT_MOUSEMOVE:
          if drawing == True:
              # Clear Screen
              img = DEFAULT
  
              # Draw Square
              if (abs(ix - x) &lt; abs(iy -y)):
                  cv2.rectangle(img,(ix,iy),(y,y),(0,255,0),1)
              else:
                  cv2.rectangle(img,(ix,iy),(x,x),(0,255,0),1)
  
      elif event == cv2.EVENT_LBUTTONUP:
          drawing = False
          crop(x,y)
  </code></pre>
  
  <h3>This one does work:</h3>
  
  <pre><code># Get Image
  img = cv2.imread(path,-1)
  
  # Draw Function
  def draw(event,x,y,flags,param):
      if event == cv2.EVENT_LBUTTONDOWN:
          drawing = True
          # Set initial points
          ix,iy = x,y
  
      elif event == cv2.EVENT_MOUSEMOVE:
          if drawing == True:
              # Clear Screen
              img = cv2.imread(path,-1)
  
              # Draw Square
              if (abs(ix - x) &lt; abs(iy -y)):
                  cv2.rectangle(img,(ix,iy),(y,y),(0,255,0),1)
              else:
                  cv2.rectangle(img,(ix,iy),(x,x),(0,255,0),1)
  
      elif event == cv2.EVENT_LBUTTONUP:
          drawing = False
          crop(x,y)
  </code></pre>
  
  <h1>Question</h1>
  
  <p>How do I make it so I don't have to read the image each time I want to clear the screen?</p>