From e61e0b36dd4794341a43bac6d31ec983d0316811 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 15 Nov 2022 17:49:40 +0700 Subject: [PATCH] sld_simple --- siwatlanedetect.py | 3 ++- siwatld_simply.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 siwatld_simply.py diff --git a/siwatlanedetect.py b/siwatlanedetect.py index ef71748..a755e80 100644 --- a/siwatlanedetect.py +++ b/siwatlanedetect.py @@ -94,13 +94,14 @@ while True: '''##### DETECTING lane lines in image ######''' rv, image1 = camera.read() + image1 = cv2.resize(image1,[1280,720]) plt.imshow(image1) plt.show() copy = np.copy(image1) edges = cv2.Canny(copy,50,150) - isolated = region(edges) + isolated = edges #region(edges) print(edges) plt.imshow(edges) plt.imshow(isolated) diff --git a/siwatld_simply.py b/siwatld_simply.py new file mode 100644 index 0000000..490d60a --- /dev/null +++ b/siwatld_simply.py @@ -0,0 +1,60 @@ +import cv2 +import numpy as np +import math +import serial +# import picamera +# import picamera.array + +threshold1 = 85 +threshold2 = 85 +theta=0 +r_width = 500 +r_height = 300 +minLineLength = 5 +maxLineGap = 10 +k_width = 5 +k_height = 5 +max_slider = 10 + +# Linux System Serial Port +# ser = serial.Serial("/dev/ttyACM0", 115200, timeout=1) # linux + +# Read Image +camera = cv2.VideoCapture(1) +# image = cv2.imread(r'C:\Users\aasai\Desktop\new1.jpeg') + +ff, image = camera.read() + +# Resize width=500 height=300 incase of inputting raspi captured image +image = cv2.resize(image,(r_width,r_height)) +# Convert the image to gray-scale +gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) +# given input image, kernel width =5 height = 5, Gaussian kernel standard deviation +blurred = cv2.GaussianBlur(gray, (k_width, k_height), 0) +# Find the edges in the image using canny detector +edged = cv2.Canny(blurred, threshold1, threshold2) +# Detect points that form a line +lines = cv2.HoughLinesP(edged,1,np.pi/180,max_slider,minLineLength,maxLineGap) +print(lines[0]) +for x in range(0, len(lines)): + for x1,y1,x2,y2 in lines[x]: + cv2.line(image,(x1,y1),(x2,y2),(255,0,0),3) + theta=theta+math.atan2((y2-y1),(x2-x1)) + print(theta) +threshold=5 +if(theta>threshold): + + print("Go left") +if(theta<-threshold): + + print("Go right") +if(abs(theta)