title: Detect if light is on or not based on color detection on poor lightning conditions
body: <p>I want to detect if traffic light is on based on color detection. The problem is that, because of how sun light impacts on it, appears to be on when it's off. Currently i'm applying standard color detection using opencv in python with hsv color model. Here's a <strong>fragment</strong> of the code</p>
  <pre><code>hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)    
  mask = cv2.inRange(hsv, lower_1, upper_1)
  contours, hierarchy = cv2.findContours(mask, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
  
  for cnt in contours:
     cnt_area = cv2.contourArea(cnt)
     cnt_area = (cnt_area / (frame_width * frame_height)) * 100
     if cnt_area &gt;= min_contour_area:
       color_detected = True
  
  return color_detected
  </code></pre>
  <p>For example:</p>
  <p>Light off <a href="https://i.stack.imgur.com/Mw5GN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mw5GN.png" alt="" /></a></p>
  <p>Light on <a href="https://i.stack.imgur.com/zO4r0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zO4r0.png" alt="" /></a></p>
  <p>The code is working properly on ideal light conditions. Light in first image should look black, and second image should look yellow. My idea is to apply the same detection algorithm to traffic lights in a variety of light conditions. <em><strong>¿Is there a way in which i can correct lightness or add some image processing step to achieve this?</strong></em></p>