Skip to content
Snippets Groups Projects
Commit b66a75ff authored by LexvanGastel's avatar LexvanGastel
Browse files

vraag 27

parent 8601e82a
Branches main
No related tags found
No related merge requests found
...@@ -55,7 +55,20 @@ def detect_blobs(mask, min_sigma=25, max_sigma=50, num_sigma = 10, threshold=0.2 ...@@ -55,7 +55,20 @@ def detect_blobs(mask, min_sigma=25, max_sigma=50, num_sigma = 10, threshold=0.2
#print('blobs detected') #print('blobs detected')
if len(blobs) > 0: if len(blobs) > 0:
blobs[:,2] = blobs[:, 2]*np.sqrt(2) blobs[:,2] = blobs[:, 2]*np.sqrt(2)
return blobs return blobs
def detect_traffic_light(red_blobs, yellow_blobs, green_blobs):
blobs_couts ={
"Red": len(red_blobs),
"Yellow": len(yellow_blobs),
"Green": len(green_blobs)
}
max_colour = max(blobs_couts, key=blobs_couts.get)
if blobs_couts[max_colour] > 0:
return f"Traffic light is {max_colour}"
def plot_detected_blobs(mask, blobs, title): def plot_detected_blobs(mask, blobs, title):
fig, ax = plt.subplots(figsize=(6,6)) fig, ax = plt.subplots(figsize=(6,6))
...@@ -175,16 +188,22 @@ class Plotter: ...@@ -175,16 +188,22 @@ class Plotter:
plt.show() plt.show()
image_path = "traffic_light_image_1.png" image_path = "traffic_light_image_1.png"
processor = ImageProcessor(image_path) processor = ImageProcessor(image_path)
red, green, blue = processor.get_color_channels() red, green, blue = processor.get_color_channels()
red_mask, yellow_mask, green_mask = processor.get_color_masks() red_mask, yellow_mask, green_mask = processor.get_color_masks()
red_blobs = detect_blobs(red_mask) red_blobs = detect_blobs(red_mask)
yellow_blobs = detect_blobs(yellow_mask) yellow_blobs = detect_blobs(yellow_mask)
green_blobs = detect_blobs(green_mask) green_blobs = detect_blobs(green_mask)
traffic_light_status = detect_traffic_light(red_blobs, yellow_blobs, green_blobs)
print(traffic_light_status)
print(f"Red Blobs: {len(red_blobs)}") print(f"Red Blobs: {len(red_blobs)}")
print(f"Yellow Blobs: {len(yellow_blobs)}") print(f"Yellow Blobs: {len(yellow_blobs)}")
print(f"Green Blobs: {len(green_blobs)}") print(f"Green Blobs: {len(green_blobs)}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment