OpenCV GUI CanvasCV has line crossing detection

OpenCV takes you a long way, but you have some distance to go by yourself to complete your projects. You can handle the GUI task by using a full blown GUI toolkit, but still there are some specific solutions that you would need from a GUI toolkit for CV. CanvasCV wants to make it easier for you with the LineCrossing shape.

Why the OpenCV GUI CanvasCV needs LineCrossing?

It’s a common task in CV to want to know if something you track crossed a line, and sometimes you even want to know the direction.

canvascv::LineCrossing is a GUI shape component in CanvasCV which can:

Be drawn on the screen with the mouse.

Has an attached label for naming.

Has a visual crossing direction attached to it.

You can persist it to a file.

Here is a screenshot from the CanvasCV project.

So how would you use it?

In this example you want to count people coming in and out in a footage from a over head camera pointing down. We’ll assume you have a Tracker, which on some events asks a CountingManager to evaluate which lines are crossed and handle counters.

Let’s say you want the user to draw LineCrossing objects on the screen, and handle the counting in the code. We’ll add our own primitive CountingManager that does that.

First you need to know when the user created and deleted the lines

The CTOR will register callbacks for create and delete notifications.

We’ll maintain a list of LineCrossing objects and an integer count paired to that line.

Using a std::pair for this is primitive, but sufficient here.

When the Tracker (not show here) needs to know if the line segment was crossed it invokes our evaluatePerson() method and pass it the movement vector of the person.

That vector could start where the Person was first detected, or from the last couple of detections – you decide.