Created
April 16, 2020 10:39
-
-
Save tomaszkacmajor/52619c76a1606d5e9f01a8d3f9f4955f to your computer and use it in GitHub Desktop.
HoughLines in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import matplotlib.image as mpimg | |
import numpy as np | |
import cv2 | |
image = mpimg.imread("test_images/ppnt.jpg") | |
gray_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) | |
blurred_image = cv2.GaussianBlur(gray_image, (9, 9), 0) | |
edges_image = cv2.Canny(blurred_image, 50, 120) | |
rho_resolution = 1 | |
theta_resolution = np.pi/180 | |
threshold = 155 | |
hough_lines = cv2.HoughLines(edges_image, rho_resolution , theta_resolution , threshold) | |
hough_lines_image = np.zeros_like(image) | |
draw_lines(hough_lines_image, hough_lines) | |
original_image_with_hough_lines = weighted_img(hough_lines_image,image) | |
plt.figure(figsize = (30,20)) | |
plt.subplot(131) | |
plt.imshow(image) | |
plt.subplot(132) | |
plt.imshow(edges_image, cmap='gray') | |
plt.subplot(133) | |
plt.imshow(original_image_with_hough_lines, cmap='gray') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment