Untitled
unknown
python
4 years ago
2.6 kB
6
Indexable
import numpy as np from matplotlib import pyplot as plt import cv2 import math from PIL import Image import Methods2 as m2 import Methods3 as m3 import a3_utils as a3 pierIm = np.asarray(Image.open("pier.jpg")) pierIm_copy = np.copy(pierIm) pierIm = m3.to_grayscale(pierIm) bricksIm = np.asarray(Image.open("bricks.jpg")) bricksIm_copy = np.copy(bricksIm) bricksIm = m3.to_grayscale(bricksIm) pierIm_edges = m3.findedges(pierIm, 1, 7) bricksIm_edges = m3.findedges(bricksIm, 2, 10) pierIm_supressed = m3.nonmaxima_supression_box(pierIm_edges) bricksIm_supressed = m3.nonmaxima_supression_box(bricksIm_edges) r1 = 150; t1 = 155 r2 = 100; t2 = 100 #if r1 >> t1, we get all of the lines on the walking surface #if r1 << t1, we get all of the lines on the walking surface pierIm_accumulator = m3.hough_find_lines(pierIm_supressed, r1, t1) bricksIm_accumulator = m3.hough_find_lines(bricksIm_supressed, r2, t2) #get the indices of the n=10 biggest elements in the accum. matrices pier_indices = [] bricks_indices = [] for i in range(0, len(pierIm_accumulator)): for j in range(0, len(pierIm_accumulator[0])): pier_indices.append((pierIm_accumulator[i][j], i, j)) pier_indices = sorted(pier_indices, key=lambda sub: (sub[0]), reverse=True) res_theta = t1 res_rho = r1 pier_diag = math.sqrt(len(pierIm)**2 + len(pierIm[0])**2) theta_values = np.linspace(-90, 90, res_theta) theta_values = np.deg2rad(theta_values) # I am forced to work with radians rho_values = np.linspace(-pier_diag, pier_diag, res_rho) plt.subplot(1,2,1) plt.title("r = " + str(r1) + ", t = " + str(t1)) for k in range(0, 11): (votes, y, x) = pier_indices[k] i = rho_values[y] j = theta_values[x] a3.draw_line(i, j, pier_diag) plt.imshow(pierIm_copy) #############BRICKS###########3 for i in range(0, len(bricksIm_accumulator)): for j in range(0, len(bricksIm_accumulator[0])): bricks_indices.append((bricksIm_accumulator[i][j], i, j)) bricks_indices = sorted(bricks_indices, key=lambda sub: (sub[0]), reverse=True) res_theta = t2 res_rho = r2 bricks_diag = math.sqrt(len(bricksIm)**2 + len(bricksIm[0])**2) theta_values = np.linspace(-90, 90, res_theta) theta_values = np.deg2rad(theta_values) # I am forced to work with radians rho_values = np.linspace(-bricks_diag, bricks_diag, res_rho) plt.subplot(1,2,2) plt.title("r = " + str(r2) + ", t = " + str(t2)) for k in range(0, 14): (votes, y, x) = bricks_indices[k] i = rho_values[y] j = theta_values[x] a3.draw_line(i, j, bricks_diag) plt.imshow(bricksIm_copy) plt.show()
Editor is loading...