1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
import numpy as np
from skimage import io,color,exposure,transform,draw
from matplotlib import pyplot as plt
img_contours = io.imread("D:/Contours_IMG_2410.jpg")
mur_gauche,mur_droite = img_contours.copy(),img_contours.copy()
mur_gauche[:,2500:] = 1
h_g ,Theta_g, d_g = transform.hough_line(mur_gauche,theta = np.arange(-pi/2,pi/2,((0.5*np.pi)/180))) #Pas de 0.5 degré
f,ax = plt.subplots(1,1)
ax.imshow(mur_gauche, cmap=plt.cm.gray)
H,angle,dist = transform.hough_line_peaks(h_g ,Theta_g, d_g,num_peaks=8)
rows,colomns = img_contours.shape
X = np.arange(0,colomns,1)
for i in range(len(angle)):
Y = (dist[i]-np.cos(angle[i])*X)/(np.sin(angle[i])) #Droite d'équation Y = ( Rho - cos(theta) * X ) / sin(theta) dans le repère image
ax.plot(X,Y,'-r')
ax.set_xlim((0, colomns))
ax.set_ylim((rows,0))
ax.set_title('Detected lines')
plt.show() |
Partager