Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to print the all the pedestrian trajectories within a period of time #12818

Open
1 task done
ArielZhanghj opened this issue May 19, 2024 · 1 comment
Open
1 task done
Labels
question Further information is requested

Comments

@ArielZhanghj
Copy link

Search before asking

Question

Thank you for your time in advance. There are two questions in print save trajectory and tracking details.
Firstly, I found add the ‘save_txt’ to ‘results = model track( )’ can put the text as s shown in the figure below. The last column shows all the pedestrian IDs recognized for each frame, but I'd like to also be able to derive what frame the recognition resulted in. I should know the time factor later. Is there anything that can be done?
Secondly, in order to get the trajectory and show all the pedestrian trajectories which are recognized within a period of time in the picture, How should it be done? Is there a better way than the previous one (my plan was to get the coordinate information of all pedestrians in each frame and concatenate the coordinates of pedestrians with the same id, but in reality, when the video is outputted, the trajectory is actually outputted)
微信图片_20240518160311

Additional

No response

@ArielZhanghj ArielZhanghj added the question Further information is requested label May 19, 2024
@glenn-jocher
Copy link
Member

Hello! Thanks for reaching out with your questions. Let's tackle them one by one:

  1. Frame Information in Tracking Output: To include frame information in your tracking output, you can modify the output format in your tracking script. For each detection, append the frame number to the saved text file. Here's a quick example of how you might adjust your tracking loop:

    for frame_idx, frame in enumerate(video_frames):
        results = model.track(frame)
        for result in results:
            with open('output.txt', 'a') as f:
                f.write(f'{frame_idx} {result}\n')

    This will prepend the frame index to each line of the output file, allowing you to track when each detection occurs.

  2. Visualizing Pedestrian Trajectories: To visualize trajectories over a period, you can accumulate the coordinates for each pedestrian ID over frames and then plot them. Here’s a simplified approach:

    import matplotlib.pyplot as plt
    
    trajectories = {}
    for frame_idx, frame in enumerate(video_frames):
        results = model.track(frame)
        for result in results:
            id = result.id
            if id not in trajectories:
                trajectories[id] = []
            trajectories[id].append((frame_idx, result.xyxy[0], result.xyxy[1]))  # Assuming xyxy format
    
    # Plotting
    for id, trajectory in trajectories.items():
        x = [coord[1] for coord in trajectory]
        y = [coord[2] for coord in trajectory]
        plt.plot(x, y, label=f'ID {id}')
    
    plt.legend()
    plt.show()

This script collects coordinates for each ID and plots them. Adjust the coordinate extraction based on your specific bbox format (xyxy, xywh, etc.).

I hope this helps! Let me know if you have any more questions. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants