From dd9dd78c1e3773e49d5d12e99538df2ea45c1d93 Mon Sep 17 00:00:00 2001 From: ROHAN PANDEY <95585299+rohan-pandeyy@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:19:30 +0530 Subject: [PATCH] LD.py code for Presentation with Raspberry. you need to connect gpio 18 with a motor driver and give external source voltage to motors. --- LD.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/LD.py b/LD.py index 4f827db..0e59059 100644 --- a/LD.py +++ b/LD.py @@ -7,7 +7,7 @@ import paho.mqtt.client as mqtt # Set up the MQTT client -broker_address = "192.168.29.216" # Replace with your broker address +broker_address = "10.12.104.29" # Replace with your broker address mqtt_client = mqtt.Client(client_id="Publisher") mqtt_client.connect(broker_address, 1883, 60) @@ -174,7 +174,7 @@ def process_image(image): lane_mask = cv2.cvtColor(lane_image_unwarped, cv2.COLOR_BGR2GRAY) _, lane_mask = cv2.threshold(lane_mask, 1, 255, cv2.THRESH_BINARY) - brake_signal = 1 # Initialize as move (1 = no brake, car moves) + brake_signal = 1 # Initialize as not braking (0) # Draw detections on the image for _, detection in detections.iterrows(): @@ -191,7 +191,7 @@ def process_image(image): if distance_ratio > 0.8: box_color = (0, 0, 255) # Red - brake_signal = 0 # Brake signal = 1 (car brakes) + brake_signal = 0 # Brake (1) elif distance_ratio > 0.5: box_color = (0, 255, 255) # Yellow @@ -209,9 +209,6 @@ def process_video_realtime(input_video_path): while True: ret, frame = cap.read() if not ret: - # When the video ends, send a brake signal (cut off power) - mqtt_client.publish("test", "1") # Brake signal - print("Video ended, applying brakes.") break # First apply YOLO detections on the frame @@ -227,7 +224,4 @@ def process_video_realtime(input_video_path): break cap.release() - cv2.destroyAllWindows() - # Ensure brakes are applied when video capture is released - mqtt_client.publish("test", "0") - print("Capture released, brakes applied.") \ No newline at end of file + cv2.destroyAllWindows() \ No newline at end of file