-class V(object):
- def __init__(self, x, y):
- self.x = x
- self.y = y
-
- def __add__(self, other):
- return V(self.x + other.x, self.y + other.y)
-
- def __sub__(self, other):
- return V(self.x - other.x, self.y - other.y)
-
- def __rmul__(self, other):
- return V(other * self.x, other * self.y)
-
- def __len__(self):
- return 2;
-
- def __getitem__(self, key):
- if key == 0:
- return self.x
- elif key == 1:
- return self.y
- elif type(key) != int:
- raise TypeError("V indices must be integers")
- else:
- raise KeyError("V index ({}) out of range".format(key))
-
- def __iter__(self):
- yield self.x
- yield self.y
-
- @property
- def normal(self):
- return V(-self.y, self.x)
-
-def projection(point, line, vector):
- return V(*intersection(g_line(point, point + vector.normal), g_line(*line)))
-
-def job(args):
- X, Y, im_l, a, b, c, d, s, v1, k, hough, size = args
- return [distance(im_l,
- get_grid(a + X[y] * s * v1,
- b + Y[y] * s * v1,
- c, d, hough, size),
- size) for y in range(0,2 * k)]
-
-def error_surface(im_l, a, b, c, d, hough, size, v1):
- import matplotlib.pyplot as plt
- from matplotlib import cm
- import multiprocessing
- import time
- import sys
- import pickle
-
- X = []
- Y = []
- Z = []
- s = 0.001
- k = 250
- for i in range(-k, k):
- X.append(range(-k, k))
- Y.append(2*k*[i])
-
- tasks = [(X[x], Y[x], im_l, a, b, c, d, s, v1, k, hough, size) for x in xrange(0, 2 * k)]
- #everything is passed by value here; can it somehow be passed by reference?
-
- pool = multiprocessing.Pool(None)
-
- start = time.time()
- Z = pool.map(job, tasks, 1)
- print time.time() - start
-
- s_file = open('surface' + str(k), 'w')
- pickle.dump((X, Y, Z), s_file)
- s_file.close()
- plt.imshow(Z, cmap=cm.jet, interpolation='bicubic',
- origin='upper', extent=(-k, k, -k, k), aspect='equal')
- plt.colorbar()
-
- plt.show()
-
- sys.exit()
-
-def find(lines, size, l1, l2, bounds, hough, do_something):
+def job_br1(args):
+ X, Y, im_l, a, b, c, d, s, v1, v2, k, hough, size = args
+ return [(distance(im_l,
+ get_grid(a + X[y] * s * v1,
+ b + Y[y] * s * v1,
+ c, d, hough, size),
+ size), a + X[y] * s * v1, b + Y[y] * s * v1) for y in range(2 *k)]
+
+def job_br2(args):
+ X, Y, im_l, a, b, c, d, s, v1, v2, k, hough, size = args
+ return [(distance(im_l,
+ get_grid(a, b, c + X[y] * s * v2,
+ d + Y[y] * s * v2,
+ hough, size),
+ size), c + X[y] * s * v2, d + Y[y] * s * v2) for y in range(2 *k)]
+
+def find(lines, size, l1, l2, bounds, hough, do_something, im_h):