- Getting started
- C# nuget package
- C# git repository
- IP video camera viewer
- PTZ IP camera motion control
- Onvif network video recorder
- SMS notifications
- Motion detection and alarms
- IP camera to SIP video call
- Configure Onvif IP cam remotely
- Onvif IP camera video server
- Video stream on website
- Onvif Network Video Analytics
- Events based on changes
- Implement object tracking
- Implement tripwire
- Implement loitering
- Implement take away events
- Leave-behind events
- Number plate recognition
- Object classification
- Onvif IP Camera Manager
- Computer Vision Technology
- Motion recognition
- Object detection
- Object categorization
- Image Manipulation
- Ozeki SDK for Linux
- Supported cameras
How to implement loitering in C#
This article shows you how to detect when an object enters a specified region of interest (ROI) for a specified period of time within camera's view. With creating a ROI on an Onvif IP Camera video stream you will able to monitor the incoming objects and measure the time how long these objects spend in this area.
What does loitering means?
Loitering is the act of remaining in a particular public place for a protracted time without an apparent purpose. Under certain circumstances, it is illegal in various jurisdictions. For example you can distinguish parking vehicles from the ones who just stopped in an area where parking is forbidden. Before you read how to detect loitering, you have to be able implementing ROI, blob detection and handle enter and exit events so be sure to check our previous tutorials if you are not familiar with any of these. You can learn more about these topics in the How to implement object tracking page.
You need to find all of the foreground objects and recognize them as individual objects. A blob has a position, width and height. Your application should put the blobs into a list as they appear. After an object enters in the ROI, they get a unique identifier one by one, which remains the same while they stay in the intrested region. You should also start the identifiers own private timer. This way you can measure how long it stays in the ROI (Figure 1). When an object's minimum loiter timer elapsed you will be able to react in many different ways (alarm call, take snapshot, capture video).
Set loitering parameters
Each facility and industry may have a different definition of what entails "loitering," as such loitering algorithms typically provide a set of parameters that can be adjusted based on the scene or the specific needs of a particular customer. These parameters include items such as:
For many situations a single or two loitering persons can be ignored. However, in some cases, such as in banks, loitering becomes more of an interest when it exceeds a defined number of people in a specific region.
Minimum loiter time:
For many cases (e.g. in parking lots) there is a time limit until there is no reaction needed (e.g. 30 minutes of free parking is given to every visitors in a hospital). With this parameter you can control the trigger of the alarm and set up a time limit after it alerts or reacts.
Region of interest:
Loitering algorithms typically have the ability to be applied to the entire scene, or just to a portion of the scene. Different regions of interest may also have different loitering parameters thereby distinguishing more or less important areas.
Real speed / Resting times:
When applying loitering to a large scene with many targets, the act of loitering may better manifest itself as those objects that are, in general, moving at a slower speed, or coming to rest at a greater frequency for example someone taking just a few steps before a shop window then staring for minutes before taking some steps again.
Below you can find the answers for the most frequently asked questions related to this topic:
How can I get the URL of the camera?
You can get the URL from the producer of the camera. (In the 10th tutorial you can find information on how to create an own IP camera discoverer program.)
- Motion detection example source code in c#
- How to implement Blob (binary large object) tracking
- How to implement tripwire in C#
- How to implement take away events in C#
- How to implement leave-behind events in C#
- How to implement number plate recognition in C#
- How to implement object classification (Differentiates between a person, vehicle, or other objects) in C#