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

Task 4 done. #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 20 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ def calculate_homography(image_points, field_points, field_length, field_width):
prev_PrightB_image = (0,0)
threshold_moving = 20
############## Task 3 ###################
############## Task 4 ###################
# Initialization of the lists that will collect the time sequence of the step points: i.e., the positions H^-1P of the feet in the instances when they were static.
PleftA_image_static_list = []
PrightA_image_static_list =[]
PleftB_image_static_list = []
PrightB_image_static_list =[]
############## Task 4 ###################

##
# PROCESSING LOOP
Expand Down Expand Up @@ -229,7 +236,7 @@ def calculate_homography(image_points, field_points, field_length, field_width):
######################################################################################################


############## Task 2 + Task 3 ###################
############## Task 2 + Task 3 + Task 4 ###################
#Initialization of the left and right ankles coordinates of the player in region A

PleftA = None
Expand All @@ -247,7 +254,7 @@ def calculate_homography(image_points, field_points, field_length, field_width):
#print("Original point (PleftA):", PleftA)
#print("Transformed point (PleftA_image):", PleftA_image)

if PleftA is None: # Avoid the "TypeError: 'NoneType' object is not subscriptable" => successful
if PleftA is None: # Avoid the "TypeError: 'NoneType' object is not subscriptable" => successful
PleftA = (0,0)

# Right ankle coordinates display in region A
Expand Down Expand Up @@ -275,14 +282,14 @@ def calculate_homography(image_points, field_points, field_length, field_width):

else:
cv2.putText(cropped_frame_A, f"(LFoot) Static", (PleftA[0]-60, PleftA[1]+70), font, font_scale, color, thickness, cv2.LINE_AA) # Display "(LFoot) Static" under the player's left foot using the image coordinates of the left foot with an offset

PleftA_image_static_list.append(PleftA_image) # Add the image coordinates of the left foot to the list if it is static (Task4)
if PrightA!=(0,0): # Check if the right ankle's point has been detected
if right_foot_moved_A: # Check if the right foot has moved
cv2.putText(cropped_frame_A, f"(RFoot) Moving", (PrightA[0]+60, PrightA[1]+40), font, font_scale, color, thickness, cv2.LINE_AA) # Display "(RFoot) Moving" under the player's right foot using the image coordinates of the left foot with an offset

else:
cv2.putText(cropped_frame_A, f"(RFoot) Static", (PrightA[0]+60, PrightA[1]+40), font, font_scale, color, thickness, cv2.LINE_AA) # Display "(RFoot) Static" under the player's right foot using the image coordinates of the right foot with an offset

PrightA_image_static_list.append(PrightA_image) # Add the image coordinates of the right foot to the list if it is static (Task4)
prev_PleftA_image = PleftA_image # Update the values of the field coordinates of the feet from the previous frame with the current ones
prev_PrightA_image = PrightA_image

Expand All @@ -293,7 +300,7 @@ def calculate_homography(image_points, field_points, field_length, field_width):



############## Task 2 + Task 3 ###################
############## Task 2 + Task 3 + Task 4 ###################

####################################################################################################
################################### TOP DETECTION ##################################################
Expand Down Expand Up @@ -348,7 +355,7 @@ def calculate_homography(image_points, field_points, field_length, field_width):
######################################################################################################


############## Task 2 + Task 3 ###################
############## Task 2 + Task 3 + Task 4 ###################
#Initialization of the left and right ankles coordinates of the player in region B

PleftB = None
Expand Down Expand Up @@ -392,14 +399,15 @@ def calculate_homography(image_points, field_points, field_length, field_width):

else:
cv2.putText(cropped_frame_B, f"(Lfoot) Static", (PleftB[0]-60, PleftB[1]+70), font, font_scale, color, thickness, cv2.LINE_AA) # Display "(LFoot) Static" under the player's left foot using the image coordinates of the left foot with an offset

PleftB_image_static_list.append(PleftB_image) # Add the image coordinates of the left foot to the list if it is static (Task4)
if PrightB !=(0,0): # Check if the right ankle's point has been detected
if right_foot_moved_B: # Check if the right foot has moved
cv2.putText(cropped_frame_B, f"(Rfoot) Moving", (PrightB[0]-60, PrightB[1]+40), font, font_scale, color, thickness, cv2.LINE_AA) # Display "(RFoot) Moving" under the player's right foot using the image coordinates of the left foot with an offset

else:
cv2.putText(cropped_frame_B, f"(Rfoot) Static", (PrightB[0]-60, PrightB[1]+40), font, font_scale, color, thickness, cv2.LINE_AA) # Display "(RFoot) Static" under the player's right foot using the image coordinates of the right foot with an offset

PrightB_image_static_list.append(PrightB_image) # Add the image coordinates of the right foot to the list if it is static (Task4)

prev_PleftB_image = PleftB_image # Update the values of the field coordinates of the feet from the previous frame with the current ones
prev_PrightB_image = PrightB_image

Expand All @@ -408,9 +416,9 @@ def calculate_homography(image_points, field_points, field_length, field_width):
prev_PleftB_image = prev_PleftB_image # Keep the values of the field coordinates of the feet from the previous frame constant in case they weren't detected
prev_PrightB_image = prev_PrightB_image

############## Task 2 + Task 3 ###################
############## Task 2 + Task 3 + Task 4 ###################


t, _ = net.getPerfProfile()
freq = cv2.getTickFrequency() / 1000

Expand Down