def plot_results(results): global final_points if not len(results): return logProbs = array([x[1] for x in results]) bestind = logProbs.argmax() L = results[bestind][0] pl.clf() plot_points(final_points) plotter.plot_walls(L) pl.legend(['points', 'best walls (%d)' % len(results)], 'best') pl.draw()
def detect_room(points, do_preprocessing=False, numwalls=None, numcalculations=4, fancy_output=False): """ detects room structures from walls """ ## parse params global final_points, FANCY_OUTPUT FANCY_OUTPUT = fancy_output if numwalls == None: numwalls = range(4, 20, 2) ## start plotting if FANCY_OUTPUT: pl.ion() #fig = pl.figure() ## do preprocessing if do_preprocessing: points = preprocess_points(points) if points == None: return [] final_points = points ## get ideal K and consequently ideal lines bestL = None bestLogProb = float('-inf') for K in numwalls: executor = DuplicatedParallelExecution() ncalc = numcalculations if K < 8 else numcalculations * 5 L, logProb = executor.execute(detect_room_one_iteration, [points, K], M=ncalc) print " [K={0}] best: logProb={1}".format(K, logProb) if logProb > bestLogProb: bestLogProb = logProb bestL = L elif K > 7: # stop on decreasing prob break ## plot walls if FANCY_OUTPUT: pl.clf() plot_points(final_points) plotter.plot_walls(L) pl.legend(['points', 'final walls'], 'best') pl.draw() time.sleep(2) pl.close() return bestL
def detect_room(points, do_preprocessing=False, numwalls=None, numcalculations=4, fancy_output=False): """ detects room structures from walls """ ## parse params global final_points, FANCY_OUTPUT; FANCY_OUTPUT = fancy_output if numwalls == None: numwalls = range(4, 20, 2) ## start plotting if FANCY_OUTPUT: pl.ion() #fig = pl.figure() ## do preprocessing if do_preprocessing: points = preprocess_points(points) if points == None: return [] final_points = points ## get ideal K and consequently ideal lines bestL = None bestLogProb = float('-inf') for K in numwalls: executor = DuplicatedParallelExecution() ncalc = numcalculations if K < 8 else numcalculations*5 L, logProb = executor.execute(detect_room_one_iteration, [points, K], M=ncalc) print " [K={0}] best: logProb={1}".format(K, logProb) if logProb > bestLogProb: bestLogProb = logProb bestL = L elif K > 7: # stop on decreasing prob break ## plot walls if FANCY_OUTPUT: pl.clf() plot_points(final_points) plotter.plot_walls(L) pl.legend(['points', 'final walls'], 'best') pl.draw() time.sleep(2) pl.close() return bestL