Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to detect moving object in varying light(illumination) conditions due to clouds - openCV

I have been trying to detect moving vehicles. But due to varying light conditions because of clouds, (not shadows of clouds, just illuminations) the background subtraction fails.

I have uploaded my input video here --> Youtube (30secs)

Here is what I got using various available background subtraction methods available in opencv

import numpy as np
import cv2

cap = cv2.VideoCapture('traffic_finalns.mp4')
#fgbgKNN = cv2.createBackgroundSubtractorKNN()
fgbgMOG = cv2.bgsegm.createBackgroundSubtractorMOG(100,5,0.7,0)
#fgbgGMG = cv2.bgsegm.createBackgroundSubtractorGMG()
#fgbgMOG2 = cv2.createBackgroundSubtractorMOG2()
#fgbgCNT = cv2.bgsegm.createBackgroundSubtractorCNT(15,True,15*60,True)

#while(1):
#   ret, frame = cap.read()
#   fgmaskKNN = fgbgKNN.apply(frame)
    fgmaskMOG = fgbgMOG.apply(frame)
#   fgmaskGMG = fgbgGMG.apply(frame)
#   fgmaskMOG2 = fgbgMOG2.apply(frame)
#   fgmaskCNT = fgbgCNT.apply(frame)
#   
#   cv2.imshow('frame',frame)
#   cv2.imshow('fgmaskKNN',fgmaskKNN)
    cv2.imshow('fgmaskMOG',fgmaskMOG)
#   cv2.imshow('fgmaskGMG',fgmaskGMG)
#   cv2.imshow('fgmaskMOG2',fgmaskMOG2)
#   cv2.imshow('fgmaskCNT',fgmaskCNT)

    k = cv2.waitKey(20) & 0xff
    if k == 27:
        break


cap.release()
cv2.destroyAllWindows()

(Below images -> Frame number - 977)

  • BackgroundSubtractorMOG : By varying the input parameter history some illumination could be reduced, but not all, as the duration of illumination is variable enter image description here

  • BackgroundSubtractorMOG2 : enter image description here

  • BackgroundSubtractorGMG : enter image description here

  • *BackgroundSubtractorKNN : * enter image description here

  • BackgroundSubtractorCNT enter image description here