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

added name and fav animal #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added SoccerAnalysis/basicSoccerNet/shortTestVid.mov
Binary file not shown.
Binary file not shown.
28 changes: 17 additions & 11 deletions SoccerAnalysis/basicSoccerNet/soccerNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,32 @@

# Paths to files
PICKLE_FILE_PATH = "video_detections.pkl" # Path to the saved detections
SOURCE_VIDEO_PATH = "source_video.mov" # Path to the source video file
TARGET_VIDEO_PATH = "video_out.mov" # Path to the output video file
SOURCE_VIDEO_PATH = "short_soccer_vid.mp4" # Path to the source video file
TARGET_VIDEO_PATH = "video_out.mp4" # Path to the output video file

# Initialize Roboflow and model
rf = Roboflow(api_key="")
rf = Roboflow(api_key="sQSgPz1GyivBdnnWUKtR")
project = rf.workspace().project("football-players-detection-3zvbc")
model = project.version(9).model

# Create BYTETracker instance
byte_tracker = sv.ByteTrack(track_thresh=0.25, track_buffer=30, match_thresh=0.8, frame_rate=30)
#byte_tracker = sv.ByteTrack(track_thresh=0.25, track_buffer=30, match_thresh=0.8, frame_rate=30)
#byte_tracker = sv.ByteTrack(track_buffer=30, match_thresh=0.8, frame_rate=30)

# Create instance of BoxAnnotator and TraceAnnotator
box_annotator = sv.BoxAnnotator(thickness=4, text_thickness=4, text_scale=2)
box_annotator = sv.BoxAnnotator(thickness=4)

trace_annotator = sv.TraceAnnotator(thickness=4, trace_length=50)

# Function to load detections from a pickle file
def load_detections_from_pickle(pickle_file_path):
with open(pickle_file_path, 'rb') as f:
detections = pickle.load(f)
print(f"Loaded detections from {pickle_file_path}")
return detections
# def load_detections_from_pickle(pickle_file_path):
# with open(pickle_file_path, 'rb') as f:
# detections = pickle.load(f)
# print(f"Loaded detections from {pickle_file_path}")
# return detections

# Load detections from pickle file
all_detections = load_detections_from_pickle(PICKLE_FILE_PATH)
# all_detections = load_detections_from_pickle(PICKLE_FILE_PATH)

# Open the source video
cap = cv2.VideoCapture(SOURCE_VIDEO_PATH)
Expand Down Expand Up @@ -72,3 +74,7 @@ def load_detections_from_pickle(pickle_file_path):
cap.release()
out.release()
print(f"Processed video saved to {TARGET_VIDEO_PATH}")

"""
Aarnav, and my favorite animal are dogs
"""
71 changes: 71 additions & 0 deletions SoccerAnalysis/basicSoccerNet/updatedSoccerNet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import numpy as np
import supervision as sv
from roboflow import Roboflow
from inference import get_model


SOURCE_VIDEO_PATH = "shortTestVid.mov"
TARGET_VIDEO_PATH = "video_out.mp4"

rf = Roboflow(api_key="")
#project = rf.workspace().project("football-players-detection-3zvbc")
model = get_model(model_id="football-players-detection-3zvbc/9")
#model = project.version(9).model
#print("model is 1111", model)

# Create BYTETracker instance
byte_tracker = sv.ByteTrack(track_activation_threshold=0.25, lost_track_buffer=30, minimum_matching_threshold=0.8, frame_rate=1)

# Create VideoInfo instance
video_info = sv.VideoInfo.from_video_path(SOURCE_VIDEO_PATH)

# Create frame generator
generator = sv.get_video_frames_generator(SOURCE_VIDEO_PATH)

# Create instance of BoxAnnotator
box_annotator = sv.BoxAnnotator(thickness=4)

# Create instance of TraceAnnotator
trace_annotator = sv.TraceAnnotator(thickness=4, trace_length=50)

# Define callback function to be used in video processing
def callback(frame: np.ndarray, index: int) -> np.ndarray:
# Model prediction on single frame and conversion to supervision Detections
print('callback')
print("frame is ", frame)
print("model is ", model)
results = model.infer(frame)
detections = sv.Detections.from_inference(results[0].dict(by_alias=True, exclude_none=True))

# Show detections in real time
print(detections)

# Tracking detections
detections = byte_tracker.update_with_detections(detections)
print("Updated Detections:", detections)

# Prepare labels for box annotations
labels = [
f"{detections.data['class_name'][i]} {detections.confidence[i]:0.2f}"
for i in range(len(detections.confidence))
]

# Annotate frame with traces and boxes
annotated_frame = trace_annotator.annotate(
scene=frame.copy(),
detections=detections
)
annotated_frame = box_annotator.annotate(
scene=annotated_frame,
detections=detections,
)

# Return annotated frame
return annotated_frame

# Process the whole video
sv.process_video(
source_path=SOURCE_VIDEO_PATH,
target_path=TARGET_VIDEO_PATH,
callback=callback
)
Binary file added SoccerAnalysis/basicSoccerNet/video_out.mp4
Binary file not shown.