title: Python OpenCV Color Tracking
body: <p>Below is my python code for tracking white color objects. It works - but only for a few seconds and then the whole screen turns black and in some times it not work. I experimented with blue color and it works - but white and green are giving me problems:</p>
  <pre><code>import cv2
  import numpy as np
  
  cap = cv2.VideoCapture(0)
  
  while(1):
  
  _, frame = cap.read()
  hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
  
  # define range of white color in HSV
  # change it according to your need !
  sensitivity = 15
  lower_white = np.array([0,0,255-sensitivity])
  upper_white = np.array([255,sensitivity,255])
  
  # Threshold the HSV image to get only white colors
  mask = cv2.inRange(hsv, lower_white, upper_white)
  # Bitwise-AND mask and original image
  res = cv2.bitwise_and(frame,frame, mask= mask)
  
  cv2.imshow('frame',frame)
  cv2.imshow('mask',mask)
  cv2.imshow('res',res)
  
  k = cv2.waitKey(5) &amp; 0xFF
  if k == 27:
  break
  
  cv2.destroyAllWindows()
  </code></pre>