Camera Blocking detection

Detect if the webcam is blocked/obstructed using simple image processing techniques.

Ashwin A Raikar

--

Introduction

Applications like user detection, child safety, security monitoring demand uninterrupted uniform access to camera frames. If someone or some object blocks the camera view it has to be automatically identified without human intervention.

An ML Engineer often needs to make a decision on the type of algorithm to be used to solve a given problem. Using CNN’s have their own set of limitations like it requires access to reasonable training data, annotation of data, GPU resources to train, and proper hardware to run which eventually turns out to be both expensive and time-consuming. That might be a possible way but not an optimal one to handle this situation.

Using simple image processing techniques the above problem can be solved without the use of GPUs and faster running times on CPUs.

The Idea

The idea is pretty simple - if a frame is blocked the number of similar pixel counts will be more than dissimilar pixels.

Dissimilar pixels
Similar Pixels

But we have a small problem with color pixels, as they differ from each other even by a slight gradient effect which we can see in Fig. 3, So we first convert the images to grayscale to reduce pixel variations or statistically what we call Standard deviation of the pixels in the image.

Histogram plots of Color vs Grayscale image

As we can see the pixel value distribution for RGB images is more as compared with the corresponding grayscale converted image. Then we specify a specific threshold for the standard deviation values, let's say the Threshold value is 10 which we will use to determine if a camera is blocked or not.

The pixel value distribution for RGB images is more as compared with the corresponding grayscale converted image.

Normal webcam Images

Fig. 1 Original Image
Fig. 2 Histogram of a greyscale image

The Standard deviation value is 63.74 which is greater than our threshold value of 10, thus implying the camera is not blocked.

Blocked webcam image

Fig.3 Webcam blocked by finger
Fig.4 Grey Scale converted image

As we can see from the Histogram plot the Standard Deviation value for the Greyscale image is less than 10, thus implying that the frame is blocked.

Conclusion

Avoid using AI/ML to solve simple tasks if possible. Image Processing with the right experimentation tools can prove to be very powerful which can be cost-effective and save a lot of developer resources.

--

--

Ashwin A Raikar

Artificial Intelligence, Computer Vision, Researcher & Developer