Search code examples
pythonopencvimage-processingtrackingdlib

Find entry exit on intersect


Im using the following code to find entry and exit count of the people.

 # check to see if the object has been counted or not
            if not to.counted:
                # if the direction is negative (indicating the object
                # is moving up) AND the centroid is above the center
                # line, count the object
                if direction < 0 and centroid[1] < H // 2:
                    totalUp += 1
                    to.counted = True

                # if the direction is positive (indicating the object
                # is moving down) AND the centroid is below the
                # center line, count the object
                elif direction > 0 and centroid[1] > H // 2:
                    totalDown += 1
                    to.counted = True

As per this code if the same person comes back and enters again, the entry count is still the same as the person has been counted already. I want to find the entry and exit count everytime when the person intersects the line. How do I sort it out?


Solution

  • A quick way to do that would be to ignore the counted attribute entirely:

    # if the direction is negative (indicating the object
    # is moving up) AND the centroid is above the center
    # line, count the object
    if direction < 0 and centroid[1] < H // 2:
          totalUp += 1
    
    # if the direction is positive (indicating the object
    # is moving down) AND the centroid is below the
    # center line, count the object
    elif direction > 0 and centroid[1] > H // 2:
        totalDown += 1
    

    This is assuming that your total counts are not per person but a grand total of occurrences. If that's the case, ignore the if to.counted because you don't care if they've been counted already, you just care if the conditions you've set have been satisfied