-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhough_lines_acc.py
More file actions
52 lines (39 loc) · 1.41 KB
/
hough_lines_acc.py
File metadata and controls
52 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from scipy.spatial.distance import cdist
import numpy as np
import time
import matplotlib.pyplot as plt
import winsound
from PIL import Image, ImageFilter
def hough_lines_acc(img):
st = time.time()
h,w = img.shape
D = int(np.ceil(np.sqrt(w * w + h * h)))
# generate theta [-90:90]
# THETA IN 180 DEG RANGE
theta_arr = np.deg2rad(np.arange(-90.0, 90.0))
rho_arr = np.linspace(-D, D, D * 2)
numThetas = len(theta_arr)
# MAKE ARRAYS OF SIN AND COS INDEXES
thetaCos = np.cos(theta_arr)
thetaSin =np.sin(theta_arr)
# acc array of doubles (H) has:
# X axis - theta [-90:90]
# Y axis - rho (dist from origin)
H = np.zeros((2*D, numThetas ), np.uint64)
r, c = np.nonzero(img) # (row, col) indexes of edges, but flipped
# for traveling down each y value
# grab index of each nonzero value (of each edge)
for i in range(len(c)):
x = c[i]
y = r[i]
# go through each theta
# calculate the distance from that point to origin
# inc the accumulator arr
print(i, "\n")
for j in range(numThetas):
rho = round(x*thetaCos[j] + y*thetaSin[j]) + D
H[rho, j] += 1
print("!!! FINALLY DONE !!!")
winsound.Beep(800, 2000) # so i can go do other things
return [H, theta_arr, rho_arr]
#read in BW