How to implement Tripwire in C#

On this page you will find detailed information on how to implement tripwire 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.

detected by the tripwire
Figure 1 - Change detected by the Tripwire

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: https://www.camera-sdk.com/https://ozeki-sms-gateway.com/p_595-how-to-configure-the-firewall-for-smpp.html
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\examples.zip\Examples\Other\Tripwire\

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

Corporate use of tripwire

Tripwire is a mean of detecting intruders. This useful function can be implemented with your C# camera application by using the Ozeki Camera SDK.

The tripwire function can be an effective help if you wish obtain the security of your own business or even home. If you develop a tripwire application in C# with the Ozeki Camera SDK the event will trigger in the case of any changes detected by the tripwire application. For example, if you use belts in your business you can detect the changes in connection with the items placed on the belts. In this way this function becomes an effective solution for counting or locating. To continue with this field, the tripwire application can be an effective help in counting people. Nowadays, there are several restrictions about the capacity of public buildings. With the help of the tripwire function you can supervise whether the building is below the required level of occupancy.

Implement tripwire in C#

namespace: Ozeki.Media

Property

  • IsRunning: it gives back in a boolean whether the tripwire function is running at that time or not
  • LineColor: we can determine the color of the line with the help of a Color object
  • Line: provides the position and the width of the line
  • DetectionFps: we can provide the frames to detect in one second
  • PixelIntensitySensitivity and PixelAmountSensitivity: by modifying these values we can determine the sensitivity of the motion sensor
  • HighlightMotion: it is an enum value. By modifying this value we can apply different effects on the motion
  • MotionColor: we can provide a Color object in order to indicate the motion on the video image. In this way the motion will appear with the determined color.

Events

  • TripwireMotionDetected: this event occurs when the tripwire function detects motion
  • TripwireMotionEnteredToLine: this event occurs when the motion enters to the line (crosses the line)
  • TripwireMotionLeaveFromLine: this event occurs when the motion leaves the line
  • LinePositionChanged: this event occurs when we modify the position of the line

Methods

  • Start: to start the tripwire function
  • Stop: to stop the tripwire function. After this the video image will be forwarded in the same form
  • SetPoints: we can determine the position of the line. The method can be called by two different parameter lists:

  • TripwireLinePosition line: in this case we can set the line by providing an enum value. The position of the line can be the following: center horizontal, centered vertically, main diagonal and ext diagonal

  • Point p1, Point p2: we can determine 2 points so by creating a straight line between the 2 points we can examine whether the motion crosses the line or not

C# code example for tripwire

MainForm.cs

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

namespace Tripwire_WF
{
    public partial class MainForm : Form
    {
        private WebCamera _camera;
        private DrawingImageProvider _provider;
        private MediaConnector _connector;

        private Tripwire tripwire;

        private Point _p1, _p2;

        public MainForm()
        {
            InitializeComponent();

            tripwire = new Tripwire();

            _provider = new DrawingImageProvider();
            _connector = new MediaConnector();
        }

        private void connectBt_Click(object sender, EventArgs e)
        {
            _camera = WebCamera.GetDefaultDevice();
            if (_camera == null) return;

            videoViewerWF1.SetImageProvider(_provider);

            _connector.Connect(_camera, tripwire);
            _connector.Connect(tripwire, _provider);

            _camera.Start();

            videoViewerWF1.Start();
        }

        private void startBt_Click(object sender, EventArgs e)
        {
            tripwire.Line.LineWidth = 3;
            tripwire.LineColor = Color.Red;

            tripwire.SetPoints(new Point(300, 100), new Point(150, 300));
            tripwire.HighlightMotion = HighlightMotion.Highlight;

            tripwire.MotionColor = Color.Blue;
            tripwire.TripwireMotionEnteredToLine += TripwireTripwireMotionEnteredToLine;
            tripwire.TripwireMotionLeaveFromLine += TripwireTripwireMotionLeaveFromLine;

            tripwire.Start();
        }

        private void stopBt_Click(object sender, EventArgs e)
        {
            tripwire.Stop();
        }

        void InvokeThread(Action action)
        {
            Invoke(action);
        }

        void TripwireTripwireMotionLeaveFromLine(object sender, TripwireMotionCrossedArgs e)
        {
            InvokeThread(() => { crossedText.Text = @"EXIT!!!"; });
        }

        void TripwireTripwireMotionEnteredToLine(object sender, TripwireMotionCrossedArgs e)
        {
            InvokeThread(() => { crossedText.Text = @"ENTER!!!"; });
        }

        private void videoViewerWF1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;
            _p1 = e.Location;
            videoViewerWF1.MouseMove += videoViewerWF1_MouseMove;
        }

        private void videoViewerWF1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;
            _p2 = e.Location;
            tripwire.SetPoints(_p1, _p2);
            videoViewerWF1.MouseMove -= videoViewerWF1_MouseMove;
        }

        private void videoViewerWF1_MouseMove(object sender, MouseEventArgs e)
        {
            _p2 = e.Location;
            tripwire.SetPoints(_p1, _p2);
        }
    }
}
	

Code 1 - Tripwire example code in C#

Conclusion

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

Related pages

FAQ

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