To write a Python program to detect the lines using Hough Transform.
Anaconda - Python 3.7 .
Import all the necessary packages required for the program.
Load a image using imread() from cv2 module.
Convert the image to grayscale image.
Using Canny edge operator from cv2, detect the edges of the image.
Using the HoughLinesP(), detect the line co-ordinates for every points in the images. Using For loop, draw the lines on the found co-ordinates.
Display the image found by the HoughLinesP() and end the program.
Developed By : Pooja A
Register no:212222240072
import numpy as np
import matplotlib.pyplot as plt
import cv2
image = cv2.imread("road.jpg",0)
img = cv2.GaussianBlur(image,(3,3),0)
plt.axis('off')
plt.imshow(img)
plt.show()
edge = cv2.Canny(img,50,100)
plt.imshow(edge,cmap='gray')
plt.title('Canny Edge Detector')
plt.xticks([])
plt.yticks([])
plt.show()
lines=cv2.HoughLinesP(edge,1,np.pi/180, threshold=80, minLineLength=50,maxLineGap=250)
for line in lines:
x1,y1,x2,y2 = line[0]
cv2.line(edge,(x1,y1),(x2,y2),(250,0,0),3)
plt.imshow(edge)
plt.axis('off')
plt.show()
Thus the program is written with python and OpenCV to detect lines using Hough transform.