Detecting multiple laser pointer positions at fading out moment

There are many workarounds to detect laser pointer with OpenCV. But I have an opposite task. I need to detect the position of multiple laser pointers at the moment when one or more pointers disappears inside given four points contour area.

  • The contour area is static and not changing between frames
  • The pointer fade out time is 50, 100, 150 ms (configurable)
  • All this should work in realtime using 60fps webcam video stream without heavy computations

Preparation steps:

  1. Apply thresholding filter
  2. Obtain laser pointer positions from Blob Detector

Here is an example of resulting frame after preparation steps:
sr1

Possible per-frame pointer conditions:

  • Pointer 1 is inside contour area, Pointer 2 is outside contour area
  • Blob Detector has failed to detect one or more pointers at given frame (but most of the time it does)
  • Pointer 1 has been switched off by user and disappears for given amount of time (50ms), but Pointer 2 is inside contour area
  • Pointer 1 has been switched off by user, but Pointer 2 is outside contour area
  • One or more pointers has been switched off by user inside contour area and appears outsude
  • One or more pointers has been switched off by user inside contour area and does not appears again anywhere on the frame
  • Pointer 1 has been switched off by user within a small distance to Pointer 2
  • etc. etc.

One of the possible solutions:
Assign fixed-size radius (say 10% of the image size) and timestamp for each newly detected pointer. In the next frames, if one of the pointers has not beed detected inside previously defined circe area and elapsed time is more that 50ms, decide it as a pointer hit.

I have tried this and many other approaches, but all of them gives poor results based on the variety of described pointer conditions.

how about this:

  • keep a set of pointers
    – a pointer has a position and a last_matched timestamp (time can be a simple incrementing counter)

  • for every frame:
    – find the dots
    – for each dot:
    — find nearest pointer
    — if that’s close enough and hasn’t been matched in this round, update its position and timestamp
    — otherwise create new pointer from dot and timestamp
    – for each pointer:
    — if its timestamp is too old, it must have vanished → remove it, do something