How to implement Tampering detection in C#

On the following page you will find more information on how to implement tampering detection in C# using the Ozeki Camera SDK. In order to make this example work, Ozeki Camera SDK has to be installed and a reference to OzekiSDK.dll has to be added to your Visual Studio project.

change detected by the tampering detection
Figure 1 - Change detected by the Tampering detection

an implementation of the tampering function
Figure 2 - An implementation of the tampering function

Important: you should study this article in order to find out how to setup your Windows Forms Application correctly.

Getting started

To get started it is recomended to Download and Install the latest version of Ozeki Camera SDK. After installation you can find the example code discussed in this page with full source code in the following location on your harddisk:

Download Ozeki Camera SDK:
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\\Examples\Other\Tripwire\

To compile this example you will need Microsoft Visual Studio installed on your computer.

Benefits of using Tampering detection

With tampering detection, the camera is capable of detecting incidents such as redirection, blocking or defocusing, or even spray paint.

Camera tampering detection is a new intelligent function, that can be an effective help if you wish obtain the security of your own business or even home. If you implement this application in C# with the Ozeki Camera SDK the event will trigger in the case of any changes detected by the tampering detection application. If you have a camera on the outside wall of your business place, you can detect the changes easily. For example if the camera was sprayed or blocked, this appliction would detect immediately and warns you. Therefore the tampering detection application can be an effective help in defending your property. This function can easily detect if somebody redirect the camera or defocus it.

Implement tampering detection in C#

namespace: Ozeki.Media


  • IsRunning: it gives back in a boolean whether the tripwire function is running at that time or not
  • Percent: it provides the proportion of the changing based on the reference image


  • ReferenceImageTaken: this event occurs when a reference image is taken
  • Detected: this event occurs when the tampering function detects large enough change
  • CurrenttamperValue: this event occurs with every frame and indicates the percentage of the changes between the referenced image and the current image


  • Start: to start the tampering detection function
  • Stop: to stop the tampering detection function
  • Clear: to delete the referenced image

  • MakeReferencedImage: with this method we can set the referenced image

C# code example for tampering


using System;
using System.Globalization;
using System.Windows.Forms;
using Ozeki.Camera;
using Ozeki.Media;

namespace Tampering_WF
    public partial class MainForm : Form
        private DrawingImageProvider provider;
        private MediaConnector connector;
        private IWebCamera camera;
        private Tampering tamper;

        public MainForm()

            connector = new MediaConnector();
            provider = new DrawingImageProvider();
            tamper = new Tampering();
            tamper.Detected += Tamper_Detected;
            tamper.ReferenceImageTaken += Tamper_ReferenceImageTaken;
            tamper.CurrentTamperValue += Tamper_CurrentTamperValue;

            numericUpDown.Value = decimal.Parse(tamper.Percent.ToString(CultureInfo.InvariantCulture));


            camera = new WebCamera();

            connector.Connect(camera.VideoChannel, tamper);
            connector.Connect(tamper, provider);


        private void Tamper_CurrentTamperValue(object sender, TamperValueArgs e)
            GuiThread(() =>
                if (e.Value < tamper.Percent)
                    detectLb.Text = string.Empty;

                valueLb.Text =  @"Value: " + Math.Round(e.Value, 2) + "%";

        private void Tamper_ReferenceImageTaken(object sender, ReferenceArgs e)
            GuiThread(() =>
                pictureBox1.Image = e.ReferenceImage;

        private void Tamper_Detected(object sender, DetectedArgs e)
            GuiThread(() =>
                detectLb.Text = @"Detected";

                pictureBox1.Image = e.ReferenceImage;

                pictureBox2.Image = e.CoveredImage;

        private void referenceBt_Click(object sender, EventArgs e)
            detectLb.Text = string.Empty;

        void GuiThread(Action action)

        private void numericUpDown_ValueChanged(object sender, EventArgs e)
            var numeric = sender as NumericUpDown;
            if (numeric != null)
                tamper.Percent = (double)numeric.Value;


Code 1 - Tripwire example code in C#


After reading through this webpage you can find all the information about how to accomplish tampering detection successfully in C# using the Ozeki Camera SDK. You will find examples and implementation for tampering in the case of any changes detected by the tampering detection application.

Related pages


Below you can find the answers for the most frequently asked questions related to this topic:

  1. I have not managed to build the solution. How to solve it?

    • Please set the Target framework property of the project to .NET 4.0.
    • You should add the OzekiSDK.dll to the references of the solution.
    • Please import the missing classes.
  2. What are the hardware requirements?

    • 1 GHz or faster processor
    • 1GB RAM (32-bit) || 2GB RAM (64-bit)
  3. Which OS are supported? Does it work with Windows 10?

    Yes,the SDK works with Windows 10. The following Operating Systems are supported:.

    • Microsoft Windows XP
    • Microsoft Windows Vista
    • Microsoft Windows 7
    • Microsoft Windows 8
    • Microsoft Windows 10
    • Microsoft Windows Server 2003
    • Microsoft Windows Server 2008

More information