OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I am making a football analysis tracking machine learning project i am getting import error of speed and distance estimator

  • Thread starter Thread starter Awez Sheikh
  • Start date Start date
A

Awez Sheikh

Guest
Code:
ImportError: cannot import name 'Speed_and_Distance_Estimator' from 
'speed_and_distance_estimator.speed_and_distance_estimator' 
(c:\Users...\Football analysis\speed_and_distance_estimator\speed_and_distance_estimator.py)

In my file speed_and_distance_estimator.py

Code:
sys.path.append('../')
from utils import measure_distance, get_foot_position

class Speed_and_Distance_Estimator:
    pass

And in my init.py

Code:
from .speed_and_distance_estimator import Speed_and_Distance_Estimator

I am expecting no error in my main.py

Code:
from utils import read_video, save_video
from trackers import Tracker
import cv2
import numpy as np
from team_assigner import TeamAssigner
from player_ball_assigner import PlayerBallAssigner
from camera_movement_estimator import CameraMovementEstimator
from view_transformer import ViewTransformer
from speed_and_distance_estimator import Speed_and_Distance_Estimator


def main():
    # Read Video
    video_frames = read_video('input_videos/08fd33_4.mp4')

    # Initialize Tracker
    tracker = Tracker('models/best.pt')

    tracks = tracker.get_object_tracks(video_frames,
                                       read_from_stub=True,
                                       stub_path='stubs/track_stubs.pkl')
    # Get object positions 
    tracker.add_position_to_tracks(tracks)

    # camera movement estimator
    camera_movement_estimator = CameraMovementEstimator(video_frames[0])
    camera_movement_per_frame = camera_movement_estimator.get_camera_movement(video_frames,
                                                                                read_from_stub=True,
                                                                                stub_path='stubs/camera_movement_stub.pkl')
    camera_movement_estimator.add_adjust_positions_to_tracks(tracks,camera_movement_per_frame)


    # View Trasnformer
    view_transformer = ViewTransformer()
    view_transformer.add_transformed_position_to_tracks(tracks)

    # Interpolate Ball Positions
    tracks["ball"] = tracker.interpolate_ball_positions(tracks["ball"])

    # Speed and distance estimator
    speed_and_distance_estimator = Speed_and_Distance_Estimator()
    speed_and_distance_estimator.add_speed_and_distance_to_tracks(tracks)

    # Assign Player Teams
    team_assigner = TeamAssigner()
    team_assigner.assign_team_color(video_frames[0], 
                                    tracks['players'][0])
    
    for frame_num, player_track in enumerate(tracks['players']):
        for player_id, track in player_track.items():
            team = team_assigner.get_player_team(video_frames[frame_num],   
                                                 track['bbox'],
                                                 player_id)
            tracks['players'][frame_num][player_id]['team'] = team 
            tracks['players'][frame_num][player_id]['team_color'] = team_assigner.team_colors[team]

    
    # Assign Ball Aquisition
    player_assigner =PlayerBallAssigner()
    team_ball_control= []
    for frame_num, player_track in enumerate(tracks['players']):
        ball_bbox = tracks['ball'][frame_num][1]['bbox']
        assigned_player = player_assigner.assign_ball_to_player(player_track, ball_bbox)

        if assigned_player != -1:
            tracks['players'][frame_num][assigned_player]['has_ball'] = True
            team_ball_control.append(tracks['players'][frame_num][assigned_player]['team'])
        else:
            team_ball_control.append(team_ball_control[-1])
    team_ball_control= np.array(team_ball_control)


    # Draw output 
    ## Draw object Tracks
    output_video_frames = tracker.draw_annotations(video_frames, tracks,team_ball_control)

    ## Draw Camera movement
    output_video_frames = camera_movement_estimator.draw_camera_movement(output_video_frames,camera_movement_per_frame)

    ## Draw Speed and Distance
    speed_and_distance_estimator.draw_speed_and_distance(output_video_frames,tracks)

    # Save video
    save_video(output_video_frames, 'output_videos/output_video.avi')

if __name__ == '__main__':
    main()
<pre><code>ImportError: cannot import name 'Speed_and_Distance_Estimator' from
'speed_and_distance_estimator.speed_and_distance_estimator'
(c:\Users...\Football analysis\speed_and_distance_estimator\speed_and_distance_estimator.py)
</code></pre>
<p>In my file speed_and_distance_estimator.py</p>
<pre><code>sys.path.append('../')
from utils import measure_distance, get_foot_position

class Speed_and_Distance_Estimator:
pass
</code></pre>
<p>And in my <strong>init</strong>.py</p>
<pre><code>from .speed_and_distance_estimator import Speed_and_Distance_Estimator
</code></pre>
<p>I am expecting no error in my main.py</p>
<pre><code>from utils import read_video, save_video
from trackers import Tracker
import cv2
import numpy as np
from team_assigner import TeamAssigner
from player_ball_assigner import PlayerBallAssigner
from camera_movement_estimator import CameraMovementEstimator
from view_transformer import ViewTransformer
from speed_and_distance_estimator import Speed_and_Distance_Estimator


def main():
# Read Video
video_frames = read_video('input_videos/08fd33_4.mp4')

# Initialize Tracker
tracker = Tracker('models/best.pt')

tracks = tracker.get_object_tracks(video_frames,
read_from_stub=True,
stub_path='stubs/track_stubs.pkl')
# Get object positions
tracker.add_position_to_tracks(tracks)

# camera movement estimator
camera_movement_estimator = CameraMovementEstimator(video_frames[0])
camera_movement_per_frame = camera_movement_estimator.get_camera_movement(video_frames,
read_from_stub=True,
stub_path='stubs/camera_movement_stub.pkl')
camera_movement_estimator.add_adjust_positions_to_tracks(tracks,camera_movement_per_frame)


# View Trasnformer
view_transformer = ViewTransformer()
view_transformer.add_transformed_position_to_tracks(tracks)

# Interpolate Ball Positions
tracks["ball"] = tracker.interpolate_ball_positions(tracks["ball"])

# Speed and distance estimator
speed_and_distance_estimator = Speed_and_Distance_Estimator()
speed_and_distance_estimator.add_speed_and_distance_to_tracks(tracks)

# Assign Player Teams
team_assigner = TeamAssigner()
team_assigner.assign_team_color(video_frames[0],
tracks['players'][0])

for frame_num, player_track in enumerate(tracks['players']):
for player_id, track in player_track.items():
team = team_assigner.get_player_team(video_frames[frame_num],
track['bbox'],
player_id)
tracks['players'][frame_num][player_id]['team'] = team
tracks['players'][frame_num][player_id]['team_color'] = team_assigner.team_colors[team]


# Assign Ball Aquisition
player_assigner =PlayerBallAssigner()
team_ball_control= []
for frame_num, player_track in enumerate(tracks['players']):
ball_bbox = tracks['ball'][frame_num][1]['bbox']
assigned_player = player_assigner.assign_ball_to_player(player_track, ball_bbox)

if assigned_player != -1:
tracks['players'][frame_num][assigned_player]['has_ball'] = True
team_ball_control.append(tracks['players'][frame_num][assigned_player]['team'])
else:
team_ball_control.append(team_ball_control[-1])
team_ball_control= np.array(team_ball_control)


# Draw output
## Draw object Tracks
output_video_frames = tracker.draw_annotations(video_frames, tracks,team_ball_control)

## Draw Camera movement
output_video_frames = camera_movement_estimator.draw_camera_movement(output_video_frames,camera_movement_per_frame)

## Draw Speed and Distance
speed_and_distance_estimator.draw_speed_and_distance(output_video_frames,tracks)

# Save video
save_video(output_video_frames, 'output_videos/output_video.avi')

if __name__ == '__main__':
main()
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top