Assignment 5: Hough transform Line and Circle

Image Link: https://drive.google.com/drive/folders/1USa7N0JCIeGGhZhkKP18-QuziOzh8riX?usp=share_link

Code Line: 

import cv2

import numpy as np


img = cv2.imread('sudoku.png')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

edges = cv2.Canny(gray, 50, 150, apertureSize=3)

lines = cv2.HoughLines(edges, 1, np.pi / 180, 200)


for line in lines:

    rho,theta = line[0]

    a = np.cos(theta)

    b = np.sin(theta)

    x0 = a * rho

    y0 = b * rho

    # x1 stores the rounded off value of (r * cos(theta) - 1000 * sin(theta))

    x1 = int(x0 + 1000 * (-b))

    # y1 stores the rounded off value of (r * sin(theta)+ 1000 * cos(theta))

    y1 = int(y0 + 1000 * (a))

    # x2 stores the rounded off value of (r * cos(theta)+ 1000 * sin(theta))

    x2 = int(x0 - 1000 * (-b))

    # y2 stores the rounded off value of (r * sin(theta)- 1000 * cos(theta))

    y2 = int(y0 - 1000 * (a))

    cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2)


cv2.imshow('image', img)

k = cv2.waitKey(0)

cv2.destroyAllWindows()

img = cv2.imread('road.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)

lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10)
for line in lines:
     x1,y1,x2,y2 = line[0]
    cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imshow('image', img)
k = cv2.waitKey(0)
cv2.destroyAllWindows()


img = cv.imread('shape.png')
output = img.copy()
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.medianBlur(gray, 5)
circles = cv.HoughCircles(gray, cv.HOUGH_GRADIENT, 1, 20,
param1=50, param2=30, minRadius=0, maxRadius=0)
detected_circles = np.uint16(np.around(circles))
for (x, y ,r) in detected_circles[0, :]:
    cv.circle(output, (x, y), r, (0, 0, 0), 3)
    cv.circle(output, (x, y), 2, (0, 255, 255), 3)
cv.imshow('output',output)
cv.waitKey(0)
cv.destroyAllWindows()

Comments

  1. Online teaching and learning have transformed how students engage with educational content. Having access to an academic writing consultant at the center of this process can significantly improve students’ understanding and performance. Such experts guide learners in structuring assignments, enhancing clarity, and adhering to academic standards. Their support ensures that even in a virtual environment, students receive the personalized guidance needed to succeed, making online education more effective and enriching.

    ReplyDelete

Post a Comment

Popular posts from this blog

Assignment 5 (Sutherland polygon clipping)

Assignments No. 2

Object Tracking In Motion