Пример #1
0
# use hough transform to detect straight lines
from src.hough import hough_vertical_mask
fn = result_dir + 'hough_line'
ptsv, linesv = hough_vertical_mask(high_pass, fn, save=False)

# get lined image
from src.util import add_wide_lines
canvas = Image.fromarray(np.zeros((height, width), dtype=np.uint8))
lined = add_wide_lines(linesv, canvas, height, width)

#========================= test_6 ===================================
#find connected components and label them
from scipy import ndimage
labeled, num_obj = ndimage.label(lined == True)

#set the highest and lowest point of each component as candidate points
pts = []
from src.util import savedots
for i in range(1, num_obj):
    tmp = np.where(labeled == i)
    sy, sx = tmp[0][0], tmp[1][0]
    ey, ex = tmp[0][-1], tmp[1][-1]
    pts.append((sx, sy))
    pts.append((ex, ey))
    fn = result_dir + str(i)
    savedots(pts, gray, fn, str(i), is_gray=True, show=False)
    pts = []
    

Пример #2
0
#from src.util import saveline
#for i in range(1, num_obj):
#    if i in good_pts:
#        tmp = np.where(labeled == i)
#        sy, sx = tmp[0][0], tmp[1][0]
#        ey, ex = tmp[0][-1], tmp[1][-1]
#        pts.append((sx, sy))
#        pts.append((ex, ey))
    
    #tmp = np.where(labeled == i)
    #sy, sx = tmp[0][0], tmp[1][0]
    #ey, ex = tmp[0][-1], tmp[1][-1]
    #line = (sx, sy, ex, ey)
    #fn = result_dir + str(i)
    #saveline(line, img, fn, str(i), show=False)
    
from src.util import savedots
from PIL import Image
fn = result_dir + 'end_points'
savedots(pts, img, fn, 'end points')


#========================= test_8 ===================================
# both points in correct location



# at least one point is in correct location
#true_pts = np.array([7, 8, 12, 19, 24, 28, 30, 34, 38, 44, 50, 51, 54, 58])

Пример #3
0
lined = add_wide_lines(linesv, canvas, height, width)
fn = result_dir + "added_wide_lines"
from src.util import saveimage_binary

saveimage_binary(lined, fn, "added wide lines")

# ========================= test_6 ===================================
# find connected components and label them
from scipy import ndimage

labeled, num_obj = ndimage.label(lined == True)
import matplotlib.pyplot as plt

fn = result_dir + "connected_components_wide"
plt.imsave(fn, labeled)
plt.imshow(labeled)
plt.show()

# set the highest and lowest point of each component as candidate points
pts = []
for i in range(1, num_obj):
    tmp = np.where(labeled == i)
    sy, sx = tmp[0][0], tmp[1][0]
    ey, ex = tmp[0][-1], tmp[1][-1]
    pts.append((sx, sy))
    pts.append((ex, ey))
from src.util import savedots

fn = result_dir + "end_points"
savedots(pts, gray, fn, "end points", is_gray=True)