Pigs counting when crossing a line using OpenCV

hysteresis.

give your boundary some width. inside that boundary, no subject changes its state. the state changes if the subject leaves the boundary one way or another.

that requires that you track your subjects, give them (temporary) identity, so you can associate information from the past with a detection in the current frame.

“nearest neighbor” assignment is a good start. requires some thresholds so you know when to create and destroy identities/tracks.

  • when a detection is truly new, you detect that because no known objects are near it.
  • when a known object disappears, no detection as been associated to it for several frames.

detections are noisy. blobs can split and merge.

1 Like