diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..830c765
Binary files /dev/null and b/.DS_Store differ
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index dfe0770..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1,2 +0,0 @@
-# Auto detect text files and perform LF normalization
-* text=auto
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 26d3352..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
diff --git a/.idea/Project.iml b/.idea/Project.iml
deleted file mode 100644
index 2c80e12..0000000
--- a/.idea/Project.iml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
deleted file mode 100644
index 105ce2d..0000000
--- a/.idea/inspectionProfiles/profiles_settings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index e4e0c8b..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 74f1bcb..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Assets/Images/Bots.png b/Assets/Images/Bots.png
new file mode 100644
index 0000000..e68ed83
Binary files /dev/null and b/Assets/Images/Bots.png differ
diff --git a/Assets/Images/BotsAndBall.png b/Assets/Images/BotsAndBall.png
new file mode 100644
index 0000000..ebc40dd
Binary files /dev/null and b/Assets/Images/BotsAndBall.png differ
diff --git a/Assets/Template.svg b/Assets/Template.svg
new file mode 100644
index 0000000..b6d7322
--- /dev/null
+++ b/Assets/Template.svg
@@ -0,0 +1,1192 @@
+
+
+
+
diff --git a/Computer Vision/Test1.mp4 b/Assets/Video/Test1.mp4
similarity index 100%
rename from Computer Vision/Test1.mp4
rename to Assets/Video/Test1.mp4
diff --git a/Computer Vision/Test2.mp4 b/Assets/Video/Test2.mp4
similarity index 100%
rename from Computer Vision/Test2.mp4
rename to Assets/Video/Test2.mp4
diff --git a/Computer Vision/.DS_Store b/Computer Vision/.DS_Store
new file mode 100644
index 0000000..11140de
Binary files /dev/null and b/Computer Vision/.DS_Store differ
diff --git a/Computer Vision/1.py b/Computer Vision/1.py
new file mode 100644
index 0000000..348acf3
--- /dev/null
+++ b/Computer Vision/1.py
@@ -0,0 +1,160 @@
+import cv2
+import numpy as np
+from scipy.spatial import distance as dist, distance
+import main1
+
+
+
+class Robot:
+ def __init__(self, pos=None, team='-no team!-', ID='-no ID!-'):
+ self.pos = pos if pos is not None else []
+ self.team = team
+ self.ID = ID
+ self.circles = []
+
+ def add_marking(self, circle=None):
+ if circle is None:
+ circle = [0, 0, [0, 0, 0]]
+ self.circles.append(circle)
+
+
+class Ball:
+ def __init__(self, pos=None):
+ self.pos = pos if pos is not None else []
+
+
+# Initialize the ball with default position
+ball = Ball()
+# Initialize empty lists for robots and ID markings
+robotList = []
+robotMarks = []
+
+def Color_Detection(blue, green, red):
+ if blue > 220 and green < 50 and red < 50:
+ return 'Blue'
+ if blue < 50 and green > 200 and red > 200:
+ return 'Yellow'
+ if blue > 200 and green < 50 and red > 200:
+ return 'Purple'
+ if blue < 50 and green > 220 and red < 50:
+ return 'Green'
+ if blue < 50 and green < 200 and red > 180:
+ return 'Orange'
+ return 'Unidentified'
+
+
+def IdentifyCircles(img, circle):
+ global ball
+
+ x, y = int(circle[0]), int(circle[1])
+ blue, green, red = img[y, x, 0], img[y, x, 1], img[y, x, 2]
+ color = Color_Detection(blue, green, red)
+
+ # Debugging statements
+ print(f"Circle at ({x}, {y}) with BGR ({blue}, {green}, {red}) detected as {color}")
+
+ if color == 'Blue' or color == 'Yellow':
+ robotList.append(Robot([x, y], color))
+ elif color == 'Green' or color == 'Purple':
+ robotMarks.append([x, y, color])
+ print('ROBOT FOUND')
+ elif color == 'Orange':
+ ball.pos = [x, y]
+ print(f"Ball found at ({x}, {y})")
+
+
+def assignIDmarks():
+ if robotList is not None:
+ for idx, robot in enumerate(robotList):
+ distances = []
+
+ for i, mark in enumerate(robotMarks):
+ mark_dist = distance.euclidean(mark[:2], robot.pos)
+ distances.append((i, mark_dist))
+ distances.sort(key=lambda x: x[1])
+ closest_marks_indices = [i for i, _ in distances[:4]]
+ robot.circles = [robotMarks[i] for i in closest_marks_indices]
+ robot.ID = idx + 1
+
+
+def detect_circles(image):
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+ blurred = cv2.GaussianBlur(gray, (9, 9), 0)
+ circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, minDist=20, param1=50, param2=14, minRadius=15,
+ maxRadius=50)
+ return [circles]
+
+
+def annotate_image(img):
+ for robot in robotList:
+ team_color = "B" if robot.team == 'Blue' else "Y"
+ cv2.putText(img, f'{team_color}', (robot.pos[0] + 20, robot.pos[1] - 40), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'ID{robot.ID}', (robot.pos[0] + 20, robot.pos[1] - 20), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'{robot.pos}', (robot.pos[0] + 20, robot.pos[1]), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+
+ if ball.pos:
+ cv2.putText(img, f'Ball {ball.pos}', (ball.pos[0] + 20, ball.pos[1] + 20), cv2.FONT_HERSHEY_SIMPLEX, 1,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.circle(img, (ball.pos[0], ball.pos[1]), 10, (0, 165, 255), -1) # Orange color for the ball
+
+
+# Main function
+def main():
+ global robotList, robotMarks
+ global ball
+
+ while True:
+ # Initialize globals
+ robotList = []
+ robotMarks = []
+ ball = Ball() # Ensure ball is always an instance of Ball
+
+ # Load and process the image
+ imgpath = "Assets/Images/BotsAndBall.png"
+ img = cv2.imread(imgpath)
+ if img is None:
+ print(f"Failed to load image at path: {imgpath}")
+ return
+
+ cv2.imshow("Original Image", img)
+
+ # Detect circles in the image
+ circles = detect_circles(img)
+
+ if circles is not None:
+ circles = np.uint8(np.around(circles))
+ for circle in circles[0, :]:
+ IdentifyCircles(img, circle)
+ cv2.circle(img, (circle[0], circle[1]), circle[2], (0, 255, 0), 2)
+ cv2.circle(img, (circle[0], circle[1]), 2, (0, 0, 255), 3)
+
+ assignIDmarks()
+
+ for robot in robotList:
+ print(f'There is a {robot.team} robot with these ID circles:')
+ for mark in robot.circles:
+ print(mark)
+
+ if ball.pos:
+ print(f'Ball found at {ball.pos}')
+
+ for robot in robotList:
+ if robot.pos:
+ cv2.circle(img, (robot.pos[0], robot.pos[1]), 10, (0, 0, 0), 5)
+ for mark in robot.circles:
+ cv2.circle(img, (mark[0], mark[1]), 10, (0, 0, 0), 5)
+
+ else:
+ print("No circles detected")
+
+ annotate_image(img)
+ cv2.imshow("Annotated Image", img)
+ cv2.waitKey(0)
+ cv2.destroyAllWindows()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/Computer Vision/2.py b/Computer Vision/2.py
new file mode 100644
index 0000000..2307b9b
--- /dev/null
+++ b/Computer Vision/2.py
@@ -0,0 +1,163 @@
+import cv2
+import numpy as np
+from scipy.spatial import distance as dist, distance
+
+
+class Robot:
+ def __init__(self, pos=None, team='-no team!-', ID='-no ID!-'):
+ self.pos = pos if pos is not None else []
+ self.team = team
+ self.ID = ID
+ self.circles = []
+
+ def add_marking(self, circle=None):
+ if circle is None:
+ circle = [0, 0, [0, 0, 0]]
+ self.circles.append(circle)
+
+
+class Ball:
+ def __init__(self, pos=None):
+ self.pos = pos if pos is not None else []
+
+
+# Initialize the ball with default position
+ball = Ball()
+# Initialize empty lists for robots and ID markings
+robotList = []
+robotMarks = []
+
+def Color_Detection(blue, green, red):
+ if blue > 220 and green < 50 and red < 50:
+ return 'Blue'
+ if blue < 50 and green > 200 and red > 200:
+ return 'Yellow'
+ if blue > 200 and green < 50 and red > 200:
+ return 'Purple'
+ if blue < 50 and green > 220 and red < 50:
+ return 'Green'
+ if blue <= 50 and green <= 200 and red >= 180:
+ return 'Orange'
+ return 'Unidentified'
+
+
+def IdentifyCircles(img, circle):
+ global ball
+
+ x, y = int(circle[0]), int(circle[1])
+ blue, green, red = img[y, x, 0], img[y, x, 1], img[y, x, 2]
+ color = Color_Detection(blue, green, red)
+
+ # Debugging statements
+ print(f"Circle at ({x}, {y}) with BGR ({blue}, {green}, {red}) detected as {color}")
+
+ if color == 'Blue' or color == 'Yellow':
+ robotList.append(Robot([x, y], color))
+ elif color == 'Green' or color == 'Purple':
+ robotMarks.append([x, y, color])
+ print('ROBOT FOUND')
+ elif color == 'Orange':
+ ball.pos = [x, y]
+ print(f"Ball found at ({x}, {y})")
+
+
+def assignIDmarks():
+ if robotList is not None:
+ for idx, robot in enumerate(robotList):
+ distances = []
+
+ for i, mark in enumerate(robotMarks):
+ mark_dist = distance.euclidean(mark[:2], robot.pos)
+ distances.append((i, mark_dist))
+ distances.sort(key=lambda x: x[1])
+ closest_marks_indices = [i for i, _ in distances[:4]]
+ robot.circles = [robotMarks[i] for i in closest_marks_indices]
+ robot.ID = idx + 1
+
+
+def detect_circles(image):
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+ blurred = cv2.GaussianBlur(gray, (9, 9), 0)
+ circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, minDist=20, param1=50, param2=14, minRadius=15,
+ maxRadius=50)
+ return circles
+
+
+def annotate_image(img):
+ for robot in robotList:
+ team_color = "B" if robot.team == 'Blue' else "Y"
+ cv2.putText(img, f'{team_color}', (robot.pos[0] + 20, robot.pos[1] - 40), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'ID{robot.ID}', (robot.pos[0] + 20, robot.pos[1] - 20), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'{robot.pos}', (robot.pos[0] + 20, robot.pos[1]), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+
+ if ball.pos:
+ cv2.putText(img, f'Ball {ball.pos}', (ball.pos[0] + 20, ball.pos[1] + 20), cv2.FONT_HERSHEY_SIMPLEX, 1,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.circle(img, (ball.pos[0], ball.pos[1]), 10, (0, 165, 255), -1) # Orange color for the ball
+
+
+# Main function
+def main():
+ global robotList, robotMarks
+ global ball
+
+ # Initialize globals
+ robotList = []
+ robotMarks = []
+ ball = Ball() # Ensure ball is always an instance of Ball
+
+ # Load and process the image
+ imgpath = "Assets/Images/BotsAndBall.png"
+ img = cv2.imread(imgpath)
+ if img is None:
+ print(f"Failed to load image at path: {imgpath}")
+ return
+
+ cv2.imshow("Original Image", img)
+
+ # Detect circles in the image
+ circles = detect_circles(img)
+
+ if circles is not None:
+ circles = np.uint16(np.around(circles))
+ for circle in circles[0, :]:
+ IdentifyCircles(img, circle)
+ cv2.circle(img, (circle[0], circle[1]), circle[2], (0, 255, 0), 2)
+ cv2.circle(img, (circle[0], circle[1]), 2, (0, 0, 255), 3)
+
+ assignIDmarks()
+
+ for robot in robotList:
+ print(f'There is a {robot.team} robot with these ID circles:')
+ for mark in robot.circles:
+ print(mark)
+
+ if ball.pos:
+ print(f'Ball found at {ball.pos}')
+
+ for robot in robotList:
+ if robot.pos:
+ cv2.circle(img, (robot.pos[0], robot.pos[1]), 10, (0, 0, 0), 5)
+ for mark in robot.circles:
+ cv2.circle(img, (mark[0], mark[1]), 10, (0, 0, 0), 5)
+
+ else:
+ print("No circles detected")
+
+ annotate_image(img)
+ cv2.imshow("Annotated Image", img)
+
+ # Use cv2.waitKey() to display the window until a key is pressed
+ while True:
+ key = cv2.waitKey(1) & 0xFF
+ if key == ord('q'):
+ break
+
+ cv2.destroyAllWindows()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/Computer Vision/3.py b/Computer Vision/3.py
new file mode 100644
index 0000000..b8a9c16
--- /dev/null
+++ b/Computer Vision/3.py
@@ -0,0 +1,160 @@
+import cv2
+import numpy as np
+from scipy.spatial import distance as dist, distance
+
+
+class Robot:
+ def __init__(self, pos=None, team='-no team!-', ID='-no ID!-'):
+ self.pos = pos if pos is not None else []
+ self.team = team
+ self.ID = ID
+ self.circles = []
+
+ def add_marking(self, circle=None):
+ if circle is None:
+ circle = [0, 0, [0, 0, 0]]
+ self.circles.append(circle)
+
+
+class Ball:
+ def __init__(self, pos=None):
+ self.pos = pos if pos is not None else []
+
+
+ball = Ball()
+robotList = []
+robotMarks = []
+
+def Color_Detection(blue, green, red):
+ if blue > 220 and green < 50 and red < 50:
+ return 'Blue'
+ if blue < 50 and green > 200 and red > 200:
+ return 'Yellow'
+ if blue > 200 and green < 50 and red > 200:
+ return 'Purple'
+ if blue < 50 and green > 220 and red < 50:
+ return 'Green'
+ if blue < 50 and green < 200 and red > 180:
+ return 'Orange'
+ return 'Unidentified'
+
+
+def IdentifyCircles(img, circle):
+ global ball
+
+ x, y = int(circle[0]), int(circle[1])
+ blue, green, red = img[y, x, 0], img[y, x, 0], img[y, x, 0]
+ color = Color_Detection(blue, green, red)
+
+ if color == 'Blue' or color == 'Yellow':
+ robotList.append(Robot([x, y], color))
+ elif color == 'Green' or color == 'Purple':
+ robotMarks.append([x, y, color])
+ print('ROBOT FOUND')
+ elif color == 'Orange':
+ ball.pos = [x, y]
+ print(f"Ball found at ({x}, {y})")
+
+
+def assignIDmarks():
+ if robotList is not None:
+ for idx, robot in enumerate(robotList):
+ distances = []
+
+ for i, mark in enumerate(robotMarks):
+ mark_dist = distance.euclidean(mark[:2], robot.pos)
+ distances.append((i, mark_dist))
+ distances.sort(key=lambda x: x[1])
+ closest_marks_indices = [i for i, _ in distances[:4]]
+ robot.circles = [robotMarks[i] for i in closest_marks_indices]
+ robot.ID = idx + 1
+
+
+def detect_circles(image):
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+ blurred = cv2.GaussianBlur(gray, (9, 9), 0)
+ circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, minDist=20, param1=50, param2=14, minRadius=1,
+ maxRadius=99)
+ return circles
+
+
+def annotate_image(img):
+ for robot in robotList:
+ team_color = "B" if robot.team == 'Blue' else "Y"
+ cv2.putText(img, f'{team_color}', (robot.pos[0] + 20, robot.pos[1] - 40), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'ID{robot.ID}', (robot.pos[0] + 20, robot.pos[1] - 20), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'{robot.pos}', (robot.pos[0] + 20, robot.pos[1]), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+
+ if ball.pos:
+ cv2.putText(img, f'Ball {ball.pos}', (ball.pos[0] + 20, ball.pos[1] + 20), cv2.FONT_HERSHEY_SIMPLEX, 1,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.circle(img, (ball.pos[0], ball.pos[1]), 10, (0, 165, 255), -1) # Orange color for the ball
+
+
+# Main function
+def main():
+ global robotList, robotMarks
+ global ball
+
+ # Open the video file
+ video_path = "Assets/Images/BotsAndBall.png"
+ cap = cv2.VideoCapture(1)
+
+ if not cap.isOpened():
+ print(f"Failed to open video file: {video_path}")
+ return
+
+ while cap.isOpened():
+ ret, frame = cap.read()
+ if not ret:
+ break
+
+ # Initialize globals for each frame
+ robotList = []
+ robotMarks = []
+ ball = Ball() # Ensure ball is always an instance of Ball
+
+ # Detect circles in the frame
+ circles = detect_circles(frame)
+
+ if circles is not None:
+ circles = np.uint16(np.around(circles))
+ for circle in circles[0, :]:
+ IdentifyCircles(frame, circle)
+ cv2.circle(frame, (circle[0], circle[1]), circle[2], (0, 255, 0), 2)
+ cv2.circle(frame, (circle[0], circle[1]), 2, (0, 0, 255), 3)
+
+ assignIDmarks()
+
+ for robot in robotList:
+ print(f'There is a {robot.team} robot with these ID circles:')
+ for mark in robot.circles:
+ print(mark)
+
+ if ball.pos:
+ print(f'Ball found at {ball.pos}')
+
+ for robot in robotList:
+ if robot.pos:
+ cv2.circle(frame, (robot.pos[0], robot.pos[1]), 10, (0, 0, 0), 5)
+ for mark in robot.circles:
+ cv2.circle(frame, (mark[0], mark[1]), 10, (0, 0, 0), 5)
+
+ else:
+ print("No circles detected")
+
+ annotate_image(frame)
+ cv2.imshow("Annotated Frame", frame)
+
+ if cv2.waitKey(1) & 0xFF == ord('q'):
+ break
+
+ cap.release()
+ cv2.destroyAllWindows()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/Computer Vision/Template.jpg b/Computer Vision/Template.jpg
deleted file mode 100644
index a8fd926..0000000
Binary files a/Computer Vision/Template.jpg and /dev/null differ
diff --git a/Computer Vision/__pycache__/main1.cpython-311.pyc b/Computer Vision/__pycache__/main1.cpython-311.pyc
new file mode 100644
index 0000000..645d9c0
Binary files /dev/null and b/Computer Vision/__pycache__/main1.cpython-311.pyc differ
diff --git a/Computer Vision/main1.py b/Computer Vision/main1.py
index b4897d7..bc70e8c 100644
--- a/Computer Vision/main1.py
+++ b/Computer Vision/main1.py
@@ -28,15 +28,15 @@ ball = Ball()
def Color_Detection(blue, green, red):
if blue > 220 and green < 50 and red < 50:
return 'Blue'
- if blue < 50 and green > 200 and red > 200:
+ elif blue < 50 and green > 200 and red > 200:
return 'Yellow'
- if blue > 200 and green < 50 and red > 200:
+ elif blue > 200 and green < 50 and red > 200:
return 'Purple'
- if blue < 50 and green > 220 and red < 50:
+ elif blue < 50 and green > 220 and red < 50:
return 'Green'
- if blue < 50 and green < 200 and red > 220:
+ elif blue < 50 and green < 200 and red > 220:
return 'Orange'
- return 'Unidentified'
+ return f'Unidentified Color R:{red}, G:{green}, B:{blue}'
def IdentifyCircles(img, circle):
global ball
@@ -49,7 +49,6 @@ def IdentifyCircles(img, circle):
robotList.append(Robot([x, y], color))
elif color == 'Green' or color == 'Purple':
robotMarks.append([x, y, color])
- print('ROBOT FOUND')
elif color == 'Orange':
ball = Ball([x, y])
@@ -76,8 +75,8 @@ def annotate_image(img):
for robot in robotList:
team_color = "B" if robot.team == 'Blue' else "Y"
cv2.putText(img, f'{team_color}', (robot.pos[0] + 20, robot.pos[1] - 40), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
- cv2.putText(img, f'ID{robot.ID}', (robot.pos[0] + 20, robot.pos[1] - 20), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
- cv2.putText(img, f'{robot.pos}', (robot.pos[0] + 20, robot.pos[1]), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'\nID{robot.ID}', (robot.pos[0] + 20, robot.pos[1] - 20), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'{robot.pos }', (robot.pos[0] + 20, robot.pos[1]), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
if ball:
cv2.putText(img, f'Ball {ball.pos}', (ball.pos[0] + 20, ball.pos[1] + 20), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
@@ -92,7 +91,7 @@ def main():
ball = None
# Load and process the video
- video_path = "/Users/mannpatel/Desktop/Project/Computer Vision/Test2.mp4"
+ video_path = "/Users/mannpatel/Desktop/Robocup/Assets/Video/Test2.mp4"
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
@@ -116,10 +115,10 @@ def main():
assignIDmarks()
- for robot in robotList:
- print(f'There is a {robot.team} robot with these ID circles:')
- for mark in robot.circles:
- print(mark)
+ # for robot in robotList:
+ # print(f'There is a {robot.team} robot with these ID circles:')
+ # for mark in robot.circles:
+ # print(mark)
if ball:
print(f'Ball found at {ball.pos}')
diff --git a/Computer Vision/main2.py b/Computer Vision/main2.py
index ffd9b1e..bd3ffdc 100644
--- a/Computer Vision/main2.py
+++ b/Computer Vision/main2.py
@@ -1,50 +1,202 @@
+# import cv2
+# import numpy as np
+# from scipy.spatial import distance as dist, distance
+#
+# class Robot:
+# def __init__(self, pos=None, team='-no team!-', ID='-no ID!-'):
+# self.pos = pos if pos is not None else []
+# self.team = team
+# self.ID = ID
+# self.circles = []
+#
+# def add_marking(self, circle=None):
+# if circle is None:
+# circle = [0, 0, [0, 0, 0]]
+# self.circles.append(circle)
+#
+# class Ball:
+# def __init__(self, pos=None):
+# self.pos = pos if pos is not None else []
+#
+# ball = Ball()
+# robotList = []
+# robotMarks = []
+#
+# def Color_Detection(blue, green, red):
+# if blue >= 220 and green <= 50 and red <= 50:
+# return 'Blue'
+# if blue <= 50 and green >= 200 and red >= 200:
+# return 'Yellow'
+# if blue >= 200 and green <= 50 and red >= 200:
+# return 'Purple'
+# if blue <= 50 and green >= 220 and red <= 50:
+# return 'Green'
+# if blue <= 50 and green <= 200 and red >= 180:
+# return 'Orange'
+# return 'Unidentified'
+#
+#
+# def IdentifyCircles(img, circle):
+# global ball
+#
+# x, y = int(circle[0]), int(circle[1])
+# blue, green, red = img[y, x, 0], img[y, x, 1], img[y, x, 2]
+# color = Color_Detection(blue, green, red)
+#
+# if color == 'Blue' or color == 'Yellow':
+# robotList.append(Robot([x, y], color))
+# elif color == 'Green' or color == 'Purple':
+# robotMarks.append([x, y, color])
+# print('ROBOT FOUND')
+# elif color == 'Orange':
+# ball.pos = [x, y]
+# print(f"Ball found at ({x}, {y})")
+#
+#
+# def assignIDmarks():
+# if robotList is not None:
+# for idx, robot in enumerate(robotList):
+# distances = []
+#
+# for i, mark in enumerate(robotMarks):
+# mark_dist = distance.euclidean(mark[:2], robot.pos)
+# distances.append((i, mark_dist))
+# distances.sort(key=lambda x: x[1])
+# closest_marks_indices = [i for i, _ in distances[:4]]
+# robot.circles = [robotMarks[i] for i in closest_marks_indices]
+# robot.ID = idx + 1
+#
+#
+# def detect_circles(image):
+# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+# blurred = cv2.GaussianBlur(gray, (9, 9), 0)
+# circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, minDist=20, param1=50, param2=14, minRadius=15,
+# maxRadius=50)
+# return circles
+#
+#
+# def annotate_image(img):
+# for robot in robotList:
+# team_color = "B" if robot.team == 'Blue' else "Y"
+# sting = f'Team: {team_color} | ID: {robot.ID} | POS: {robot.pos}'
+# cv2.putText(img, sting, (robot.pos[0] + 20, robot.pos[1] - 40), cv2.FONT_HERSHEY_SIMPLEX, .75,
+# (255, 255, 255), 2, cv2.LINE_AA)
+#
+# if ball.pos:
+# cv2.putText(img, f'Ball {ball.pos}', (ball.pos[0] + 20, ball.pos[1] + 20), cv2.FONT_HERSHEY_SIMPLEX, 1,
+# (255, 255, 255), 2, cv2.LINE_AA)
+#
+# # Main function
+# def main():
+# global robotList, robotMarks
+# global ball
+#
+# while True:
+# # Initialize globals
+# robotList = []
+# robotMarks = []
+# ball = Ball() # Ensure ball is always an instance of Ball
+#
+# # Load and process the image
+# imgpath = "/Users/mannpatel/Desktop/Project/Computer Vision/Test2.jpeg"
+# img = cv2.imread(imgpath)
+# if img is None:
+# print(f"Failed to load image at path: {imgpath}")
+# return
+#
+# cv2.imshow("Original Image", img)
+#
+# # Detect circles in the image
+# circles = detect_circles(img)
+#
+# if circles is not None:
+# circles = np.uint16(np.around(circles))
+# for circle in circles[0, :]:
+# IdentifyCircles(img, circle)
+# cv2.circle(img, (circle[0], circle[1]), circle[2], (0, 255, 0), 2)
+# cv2.circle(img, (circle[0], circle[1]), 2, (0, 0, 255), 3)
+# assignIDmarks()
+#
+# for robot in robotList:
+# print(f'There is a {robot.team} robot with these ID circles:')
+# for mark in robot.circles:
+# print(mark)
+#
+# if ball.pos:
+# print(f'Ball found at {ball.pos}')
+#
+# for robot in robotList:
+# if robot.pos:
+# cv2.circle(img, (robot.pos[0], robot.pos[1]), 10, (0, 0, 0), 5)
+# for mark in robot.circles:
+# cv2.circle(img, (mark[0], mark[1]), 10, (0, 0, 0), 5)
+#
+# else:
+# print("No circles detected")
+#
+# annotate_image(img)
+# cv2.imshow("Annotated Image", img)
+# cv2.waitKey(0)
+# cv2.destroyAllWindows()
+#
+#
+# if __name__ == "__main__":
+# main()
import cv2
import numpy as np
from scipy.spatial import distance as dist, distance
-import copy
-
-
-# Initialize empty lists for robots and ID markings
-robotList = []
-robotMarks = []
-
class Robot:
def __init__(self, pos=None, team='-no team!-', ID='-no ID!-'):
- # Initialize with default empty list if pos is not provided
self.pos = pos if pos is not None else []
self.team = team
self.ID = ID
- self.circles = [] # ID markings [x, y, color]
+ self.circles = []
def add_marking(self, circle=None):
- # Initialize with default circle if none is provided
if circle is None:
circle = [0, 0, [0, 0, 0]]
self.circles.append(circle)
+
class Ball:
def __init__(self, pos=None):
- # Initialize with default empty list if pos is not provided
self.pos = pos if pos is not None else []
+
# Initialize the ball with default position
ball = Ball()
+# Initialize empty lists for robots and ID markings
+robotList = []
+robotMarks = []
def Color_Detection(blue, green, red):
- if blue > 220 and green < 50 and red < 50:
+ if blue >= 220 and green <= 50 and red <= 50:
return 'Blue'
- if blue < 50 and green > 200 and red > 200:
+ if blue <= 50 and green >= 200 and red >= 200:
return 'Yellow'
- if blue > 200 and green < 50 and red > 200:
+ if blue >= 200 and green <= 50 and red >= 200:
return 'Purple'
- if blue < 50 and green > 220 and red < 50:
+ if blue <= 50 and green >= 220 and red <= 50:
return 'Green'
- if blue < 50 and green < 200 and red > 220:
+ if blue <= 50 and green <= 200 and red >= 220:
return 'Orange'
return 'Unidentified'
+# def Color_Detection(blue, green, red):
+# if blue == 246 and green == 0 and red == 0:
+# return 'Blue'
+# if blue <= 0 and green >= 250 and red > 350:
+# return 'Yellow'
+# if blue == 247 and green == 51 and red == 235:
+# return 'Purple'
+# if blue == 77 and green == 252 and red == 118:
+# return 'Green'
+# if blue == 50 and green == 113 and red == 228:
+# return 'Orange'
+# return 'Unidentified'
+
def IdentifyCircles(img, circle):
global ball
@@ -53,13 +205,17 @@ def IdentifyCircles(img, circle):
blue, green, red = img[y, x, 0], img[y, x, 1], img[y, x, 2]
color = Color_Detection(blue, green, red)
+ # Debugging statements
+ print(f"Circle at ({x}, {y}) with BGR ({blue}, {green}, {red}) detected as {color}")
+
if color == 'Blue' or color == 'Yellow':
robotList.append(Robot([x, y], color))
elif color == 'Green' or color == 'Purple':
robotMarks.append([x, y, color])
print('ROBOT FOUND')
elif color == 'Orange':
- ball = Ball([x, y])
+ ball.pos = [x, y]
+ print(f"Ball found at ({x}, {y})")
def assignIDmarks():
@@ -79,32 +235,44 @@ def assignIDmarks():
def detect_circles(image):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (9, 9), 0)
- circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, minDist=20, param1=50, param2=14, minRadius=15, maxRadius=25)
+ circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, 1, minDist=20, param1=50, param2=14, minRadius=15,
+ maxRadius=50)
return circles
+
def annotate_image(img):
for robot in robotList:
team_color = "B" if robot.team == 'Blue' else "Y"
- cv2.putText(img, f'{team_color}', (robot.pos[0] + 20, robot.pos[1] - 40), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
- cv2.putText(img, f'ID{robot.ID}', (robot.pos[0] + 20, robot.pos[1] - 20), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
- cv2.putText(img, f'{robot.pos}', (robot.pos[0] + 20, robot.pos[1]), cv2.FONT_HERSHEY_SIMPLEX, .75, (255, 255, 255), 2, cv2.LINE_AA)
- # Assuming orientation and other details are part of robot attributes
+ cv2.putText(img, f'{team_color}', (robot.pos[0] + 20, robot.pos[1] - 40), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'ID{robot.ID}', (robot.pos[0] + 20, robot.pos[1] - 20), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.putText(img, f'{robot.pos}', (robot.pos[0] + 20, robot.pos[1]), cv2.FONT_HERSHEY_SIMPLEX, .75,
+ (255, 255, 255), 2, cv2.LINE_AA)
+
+ if ball.pos:
+ cv2.putText(img, f'Ball {ball.pos}', (ball.pos[0] + 20, ball.pos[1] + 20), cv2.FONT_HERSHEY_SIMPLEX, 1,
+ (255, 255, 255), 2, cv2.LINE_AA)
+ cv2.circle(img, (ball.pos[0], ball.pos[1]), 10, (0, 165, 255), -1) # Orange color for the ball
- if ball:
- cv2.putText(img, f'Ball {ball.pos}', (ball.pos[0] + 20, ball.pos[1] + 20), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
# Main function
def main():
- global robotList, robotMarks, ball
+ global robotList, robotMarks
+ global ball
# Initialize globals
robotList = []
robotMarks = []
- ball = None
+ ball = Ball() # Ensure ball is always an instance of Ball
# Load and process the image
- imgpath = "/Users/mannpatel/Desktop/Project/Template.jpg"
+ imgpath = "/Users/mannpatel/Desktop/Robocup/Computer Vision/Template1.png"
img = cv2.imread(imgpath)
+ if img is None:
+ print(f"Failed to load image at path: {imgpath}")
+ return
+
cv2.imshow("Original Image", img)
# Detect circles in the image
@@ -120,26 +288,33 @@ def main():
assignIDmarks()
for robot in robotList:
- print(f'There is a {robot.team} robot with these ID circles:')
+ print(f'There is a {robot.team} robot with these ID {robot.ID}')
for mark in robot.circles:
print(mark)
- if ball:
+ if ball.pos:
print(f'Ball found at {ball.pos}')
for robot in robotList:
- cv2.circle(img, (robot.pos[0], robot.pos[1]), 10, (0, 0, 0), 5)
- for mark in robot.circles:
- cv2.circle(img, (mark[0], mark[1]), 10, (0, 0, 0), 5)
+ if robot.pos:
+ cv2.circle(img, (robot.pos[0], robot.pos[1]), 10, (0, 0, 0), 5)
+ for mark in robot.circles:
+ cv2.circle(img, (mark[0], mark[1]), 10, (0, 0, 0), 5)
else:
print("No circles detected")
annotate_image(img)
cv2.imshow("Annotated Image", img)
- cv2.waitKey(0)
+
+ # Use cv2.waitKey() to display the window until a key is pressed
+ while True:
+ key = cv2.waitKey(1) & 0xFF
+ if key == ord('q'):
+ break
+
cv2.destroyAllWindows()
if __name__ == "__main__":
- main()
\ No newline at end of file
+ main()
diff --git a/GUI/GUI.py b/GUI/GUI.py
deleted file mode 100644
index 242d4b0..0000000
--- a/GUI/GUI.py
+++ /dev/null
@@ -1,22 +0,0 @@
-import dearpygui.dearpygui as dpg
-
-dpg.create_context()
-
-with dpg.window(label="Example Window"):
- dpg.add_text("Hello, world")
- dpg.add_button(label="Save")
- dpg.add_input_text(label="string", default_value="Quick brown fox")
- dpg.add_slider_float(label="float", default_value=0.273, max_value=1)
-
-dpg.create_viewport(title='Custom Title', width=600, height=200)
-dpg.setup_dearpygui()
-dpg.show_viewport()
-
-# below replaces, start_dearpygui()
-while dpg.is_dearpygui_running():
- # insert here any code you would like to run in the render loop
- # you can manually stop by using stop_dearpygui()
- print("this will run every frame")
- dpg.render_dearpygui_frame()
-
-dpg.destroy_context()
\ No newline at end of file