sld_simple

This commit is contained in:
Siwat Sirichai 2022-11-15 17:49:40 +07:00
parent e7db5e4dfb
commit e61e0b36dd
2 changed files with 62 additions and 1 deletions

View File

@ -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)

60
siwatld_simply.py Normal file
View File

@ -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)<threshold):
print("Go straight")
theta=0
cv2.imshow("Gray Image",gray)
cv2.imshow("blurred",blurred)
cv2.imshow("Edged",edged)
cv2.imshow("Line Detection",image)
cv2.waitKey(0)
cv2.destroyAllWindows()