Detecting Camera Tampering using OpenCV and Python

In this article we will discuss how to provide security to a camera.Before diving deeper into the implementation let us first understand what is Tampering of Camera,possible scenarios and how can we prevent tampering.
                               

Let’s begin
What is Camera Tampering?
Camera Tampering means any external interference with the camera, causing damage to it or making unauthorized alterations. It may indicate that criminal activity is occurring or is about to occur.
Some examples of camera tampering are:
  1. Turning camera to point in a different direction so that the activities cannot be recorded.
  2. Covering the lens of the camera by opaque objects(Also known as Camera Occlusion).
  3. Screen shaking, fogging, screen flickering, defocus, etc.
All such activities can degrade the performance of the Smart Surveillance system. This article focuses strongly on automating the process of detecting camera tampering in a video surveillance system.

  
Diving Deeper into the problem

How Tamper Detection works?

Tamper detection allows your camera to alert you when its ability to record has been impacted. Especially helpful for locations where the camera may be physically attacked or blocked.
Tamper detection can also be set to send alerts based on the duration of the disruption, so a stray leaf caught on the camera for a few seconds won’t trigger anything but spray painting the camera will trigger an alert.
We will be using Computer Vision to solve our problem. Differences between the older frames and recent frames will be monitored and based on it, the decision of tampering or not will be taken.
Implementation in python
#Video capturing starts
cap = cv2.VideoCapture(0)
fgbg = cv2.createBackgroundSubtractorMOG2()
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
kernel = np.ones((5,5), np.uint8)
Step 1: Importing necessary libraries(NumPy and OpenCV).
Step 2: Camera is opened and video capturing starts. Here 0 specifies the use of the built-in webcam while 1 specifies the use of an external webcam. One by one the frames of the camera are read.
Background Subtraction is a technique used for generating a 
foreground mask. It is a two-step process: Background Initialisation and Updation
1.Background Initialisation: In the Background Initialisation process, an initial model is computed.
2.Background Updation: In Background Updation, the model is updated to keep new changes in the frame.
               
Step 3: We are now ready to loop over frames and begin the detection process.

Erosion and Dilation: Erosion is a process of eroding the boundaries of the foreground object. As the kernel slides over the image, depending on the values of pixels (0 or 1), the value is eroded while Dilation is a process of increasing the size of the foreground image thus increasing the white region.
                                 
                             Process of Erosion makes object in white smaller
                                 
                             Process of Dilation makes object in white bigger
When a hand or any object is brought nearer to the camera, the distance decreases and after a particular set threshold value, a message is displayed “TAMPERING DETECTED”.
Applications in Real Life
Camera Tampering can be used in surveillance and security field( Inside ATM chambers, old aged homes, banks, etc.)
            

Comments

  1. Some one is erasing my recorded footage on my dvr. Nobody has my password....they also look like someone has thrown a bucket of paint on them but then it goes away after a bit. How do I totaly protect my cameras from being tampered with it hacked into...?? Please help. My email is thejokersdeck101@gmail.com

    ReplyDelete

Post a Comment