HI TolqinjonRahimov ,
To modify the code to count people walking up and down instead of left and right, you need to make changes to the PeopleCounter class and the tracklet_removed method. Here's what you can modify:
In the PeopleCounter class, initialize the people_counter list as [0, 0, 0, 0] to [0, 0, 0, 0], where the indices represent the following directions: [Up, Down, Left, Right]. The updated initialization should be as follows:
self.people_counter = [0, 0, 0, 0] # Up, Down, Left, Right
In the tracklet_removed method, update the logic for counting the direction. Instead of incrementing the self.people_counter[2] for left and self.people_counter[3] for right, you should increment self.people_counter[0] for up and self.people_counter[1] for down. Modify the method as follows:
def tracklet_removed(self, coords1, coords2):
deltaY = coords2[1] - coords1[1] # Calculate the change in Y coordinate
if THRESH_DIST_DELTA < abs(deltaY):
self.people_counter[0 if 0 > deltaY else 1] += 1
direction = "up" if 0 > deltaY else "down"
print(f"Person moved {direction}")
With these changes, the code will count people walking up and down instead of left and right. Remember to update the corresponding text output if needed.
Courtesy of ChatGPT.
Hope this helps,
Jaka