title: Controlling Contrast and Brightness of Video Stream in OpenCV and Python
body: <p>I’m using OpenCV3 and Python 3.7 to capture a live video stream from my webcam and I want to control the brightness and contrast.  I cannot control the camera settings using OpenCV's <code>cap.set(cv2.CAP_PROP_BRIGHTNESS, float)</code> and <code>cap.set(cv2.CAP_PROP_BRIGHTNESS, int)</code> commands so I want to apply the contrast and brightness after each frame is read.   The Numpy array of each captured image is (480, 640, 3).  The following code properly displays the video stream without any attempt to change the brightness or contrast.</p>
  
  <pre><code>import numpy as np
  import cv2
  
  cap = cv2.VideoCapture(0)    
  while(True):
      # Capture frame-by-frame
      ret, frame = cap.read()
      cv2.imshow('frame',frame)
      if cv2.waitKey(1) &amp; 0xFF == ord('q'):
          break
  # When everything done, release the capture
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>I get a washed-out video stream when I use Numpy’s <code>clip()</code> method to control the contrast and brightness, even when I set <code>contrast = 1.0</code> (no change to contrast) and <code>brightness = 0</code> (no change to brightness).  Here is my attempt to control contrast and brightness.</p>
  
  <pre><code>import numpy as np
  import cv2
  
  cap = cv2.VideoCapture(0)
  while(True):
      # Capture frame-by-frame
      ret, frame = cap.read()
      contrast = 1.0
      brightness = 0
      frame = np.clip(contrast * frame + brightness, 0, 255)
      cv2.imshow('frame',frame)
      if cv2.waitKey(1) &amp; 0xFF == ord('q'):
          break
  # When everything done, release the capture
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>How can I control the contrast and brightness of a video stream using OpenCV?</p>