Code Monkey home page Code Monkey logo

edge--linking-hough-transform's Introduction

Edge-Linking-using-Hough-Transform

Aim:

To write a Python program to detect the lines using Hough Transform.

Software Required:

Anaconda - Python 3.7 .

Algorithm:

Step 1:

Import all the necessary packages required for the program.

Step 2:

Load a image using imread() from cv2 module.

Step 3:

Convert the image to grayscale image.

Step 4:

Using Canny edge operator from cv2, detect the edges of the image.

Step 5:

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.

Step 6:

Display the image found by the HoughLinesP() and end the program.

Program:

Developed By : Pooja A
Register no:212222240072

Read image and convert it to grayscale image:

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

Find the edges in the image using canny detector and display:

edge = cv2.Canny(img,50,100)
plt.imshow(edge,cmap='gray')
plt.title('Canny Edge Detector')
plt.xticks([])
plt.yticks([])
plt.show()

Detect points that form a line using HoughLinesP:

lines=cv2.HoughLinesP(edge,1,np.pi/180, threshold=80, minLineLength=50,maxLineGap=250)

Draw lines on the image:

for line in lines:
    x1,y1,x2,y2 = line[0]
    cv2.line(edge,(x1,y1),(x2,y2),(250,0,0),3)

Display the result:

plt.imshow(edge)
plt.axis('off')
plt.show()

Output:

Input image:

WhatsApp Image 2023-11-14 at 01 26 49_0cd65e7e

Grayscale image:

WhatsApp Image 2023-11-14 at 01 28 57_5454e417

Canny Edge detector output:

WhatsApp Image 2023-11-14 at 01 29 36_87074133

Display the result of Hough transform:

WhatsApp Image 2023-11-14 at 01 30 11_d048d011

Result:

Thus the program is written with python and OpenCV to detect lines using Hough transform.

edge--linking-hough-transform's People

Contributors

poojaanbu0 avatar swedha333 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.