2

I am using open CV 3.4. I am getting feed from an RTSP input camera. I want to add a condition in my code such that if camera is covered using any thing Alert should go to user. Checking blackness of the frame doesn't do any justice because when covered with white color cloth, the frame will be white. Can anyone suggest some logic for this? How can we accomplish this using openCV?

Iwo Kucharski
  • 3,735
  • 3
  • 50
  • 66
  • Check if the range in color/intensity surpasses some threshold? – Quang Hoang Apr 26 '19 at 04:02
  • How can it be done by just checking color inensity , blocking with different color objects results in different result / threshold right? Can you please send code to do so in open CV?? –  Apr 26 '19 at 04:49
  • I don't know a direct solution for openCV but that kind of thing can be done with simple image processing techniques. You can look at the overall "range" of different pixel values (hue, saturation, lightness) and if that range is below a certain threshold the camera is covered by a lens cover, cloth(or is only capturing a pictures of a monotone colored image->wall, sky, etc.) – GittingGud Apr 26 '19 at 07:14
  • What is that threshold that you have to set ? camera light intensity varies accordingly at day and night ,so HSV values changes accordingly –  Apr 26 '19 at 07:41
  • Think of 3-4 of the most likely things a silly user might cover your camera with and record each of them into separate images or videos then analyse them to determine their characteristics. I guess the videos will be very static/unchanging if a cloth is covering the lens, also unsharp as it will be too close to focus and also have little variance if the cloth is plain. – Mark Setchell Apr 26 '19 at 08:23
  • Calculate distance between camera and object probably will work. https://stackoverflow.com/questions/14038002/opencv-how-to-calculate-distance-between-camera-and-object-using-image and https://www.pyimagesearch.com/2015/01/19/find-distance-camera-objectmarker-using-python-opencv/ – gameon67 Apr 26 '19 at 08:55
  • @NithinPradeep The overall change of the HSV values over a day don't matter you only need to look at range of hsv values in one picture (in certain intervals) to determine if the camera is covered. I would use all three values of HSV for "redundancy". – GittingGud Apr 26 '19 at 08:58
  • @gameon67 that doesn't work if for example your lens cap is on the camera. – GittingGud Apr 26 '19 at 08:59
  • @GittingGud does OP's camera have lens cap on? If yes, well......... use Deep Learning lol – gameon67 Apr 26 '19 at 09:03

1 Answers1

4

You can check whether the camera is in focus or not. For example, here's a blurry photo of my palm and of my window:

enter image description here

Here's the function that calculates a sharpness "score" of each image:

def sharpness(img):
    img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    lap = cv.Laplacian(img, cv.CV_16S)
    mean, stddev = cv.meanStdDev(lap)
    return stddev[0,0]

Testing:

enter image description here

The blurry picture has a much lower score. You can set the threshold to e.g. 20 and anything below that is considered blurry and therefore the camera is covered or something else is wrong with it.

Stefan Dragnev
  • 14,143
  • 6
  • 48
  • 52
  • This value varies for cameras that is kept in different locations,ie for multiple cameras . so threshold varies for each.can we generalize this?? –  Apr 29 '19 at 07:36
  • Place a Jackson Pollock painting in front of every camera. This should allow you to use the same threshold for every camera. – Stefan Dragnev May 10 '19 at 09:07