From ac2395e79ce0bbbf023cc8407689f16044c04ea4 Mon Sep 17 00:00:00 2001 From: vinuki Date: Tue, 29 Oct 2024 13:33:55 +0530 Subject: [PATCH] added choc chips to conveyor_module --- cloud_modules.py | 4 ++-- conveyor_module.py | 28 +++++++++++++++++++++++----- edge_modules.py | 4 ++-- main.py | 4 ++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/cloud_modules.py b/cloud_modules.py index 4587521..e827e89 100644 --- a/cloud_modules.py +++ b/cloud_modules.py @@ -18,8 +18,8 @@ class CloudAnalyzer: def __init__(self): - self.endPoint = '[CLOUD URL]' - self.apiKey = '[API KEY]' + self.endPoint = 'https://2021csc051-prediction.cognitiveservices.azure.com/customvision/v3.0/Prediction/3afd0fce-ce6c-48dd-b92e-195e9fffc0ef/detect/iterations/Iteration2/image' + self.apiKey = '74a793fe0ad046779ed5d02a3b56def3' def analyzeImage(self, filePath) -> int: start_time = time.time() diff --git a/conveyor_module.py b/conveyor_module.py index 5ae794c..de40e5e 100644 --- a/conveyor_module.py +++ b/conveyor_module.py @@ -18,8 +18,8 @@ pygame.init() # Screen dimensions -SCREEN_WIDTH = 1200 -SCREEN_HEIGHT = 1000 +SCREEN_WIDTH = 900 +SCREEN_HEIGHT = 700 # Port Listening CONVEYOR_PORT = 12121 @@ -42,7 +42,7 @@ ARM_WIDTH = 150 BELT_WIDTH = 600 COOKIE_WIDTH = 100 -COOKIE_QUALITY = 100 #between 10 and 100 +COOKIE_QUALITY = 50 #between 10 and 100 ARM_POSITION = (SCREEN_WIDTH // 2) - ARM_WIDTH // 2 DEV_OFF_Y = SCREEN_HEIGHT // 2 - BELT_WIDTH // 2 - 10 CAM_MARGIN = COOKIE_WIDTH // 4 @@ -105,7 +105,15 @@ def __init__(self, x, y): self.shape_arc = BAD_SHAPES[random.randint(1,3)] else: self.shape_arc = BAD_SHAPES[0] - + +# ----------------------------------------------------- + self.has_chips = True + self.chip_color = (50, 25, 0) # Dark brown for chocolate chips + self.num_chips = random.randint(3, 7) + self.chip_positions = [(random.randint(10, COOKIE_WIDTH - 10), random.randint(10, COOKIE_WIDTH - 10)) for _ in range(self.num_chips)] +# (added for the choc chips) +# ------------------------------------------------------- + def draw(self, screen): # Draw the full cookie pygame.draw.ellipse(screen, @@ -118,6 +126,15 @@ def draw(self, screen): [self.x, self.y, COOKIE_WIDTH, COOKIE_WIDTH], self.shape_arc[0], self.shape_arc[1], self.shape_arc[2]) +# --------------------------------------------------------- + if self.has_chips: + for pos in self.chip_positions: + chip_x = self.x + pos[0] + chip_y = self.y + pos[1] + pygame.draw.circle(screen, self.chip_color, (chip_x, chip_y), 7) # radius of the chocolate chip is 7 +# (draw choc chips) +# ------------------------------------------------------------ + def move(self, speed): if(self.dead == False) : self.x += speed @@ -217,7 +234,8 @@ def capture(self, screen, capture_area, analyze): #pygame.transform.smoothscale(capture_image,) # Save the captured image - imgFile = f"captures/image{self.imgCounter:02}.png" + # imgFile = f"captures/image{self.imgCounter:02}.png" + imgFile = "e:/CSC/cookies/PySimulator/captures/image{:02}.png".format(self.imgCounter) pygame.image.save(capture_image, imgFile) #only send image for analysis if opted diff --git a/edge_modules.py b/edge_modules.py index f179448..7e81358 100644 --- a/edge_modules.py +++ b/edge_modules.py @@ -18,8 +18,8 @@ class EdgeAnalyzer: def __init__(self): - self.endPoint = '[CLOUD URL]' - self.apiKey = '[API KEY]' + self.endPoint = 'http://172.19.100.178:80/image' + self.apiKey = '74a793fe0ad046779ed5d02a3b56def3' def analyzeImage(self, filePath) -> int: start_time = time.time() diff --git a/main.py b/main.py index a488352..8276465 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ def main(): # 1. isCloud # =True : Uses cloud module # =False: Uses edge module - analytic = analytic_module.Listener(isCloud=True) + analytic = analytic_module.Listener(isCloud=False) # Parameters: # 1. shouldAnalyzeImg @@ -27,7 +27,7 @@ def main(): # =False: To get images for training # 2. imgLimit # =Number: Number of images/rows to be stored (use 50 to get images for training) - conveyor = conveyor_module.Simulation(shouldAnalyzeImg=False, imgLimit=50) + conveyor = conveyor_module.Simulation(shouldAnalyzeImg=True, imgLimit=50) analytic.start() conveyor.start()