def gridsize(original, segdst=SEGMENT_DISTANCE):
global im
# read the image from disk
im = original.copy()
add_image('Original')
# edge detection
im = sobel(im)
# blurring
im = filters.gaussian(im, sigma=5)
# thresholding: convert to binary rage
loc = threshold_local(im, 31)
im = im > loc
if (DEBUG): add_image('Threshold')
# detect straight lines longer than 150px
segs = probabilistic_hough_line(
im,
threshold=30,
line_length=250,
line_gap=7)
#segs = [seg for seg in segs if vertical(seg)]
# draw the segments
im[:] = 0 # set image to black
for seg in segs:
((x1, y1), (x2, y2)) = seg
rr,cc = draw.line(y1,x1,y2,x2)
im[rr, cc] = 1
if (DEBUG): add_image('Hough Lines')
hh, vv = process_segments(segs)
# draw the segments
im[:] = 0 # set image to black
num = 0
for yy in hh:
for yyy in yy:
(_,y),_ = yyy
rr,cc = draw.line(y,0,y,999)
im[rr, cc] = 1
num += 1
for xx in vv:
for xxx in xx:
(x,_),_ = xxx
rr,cc = draw.line(0,x,999,x)
im[rr, cc] = 1
num += 1
if (DEBUG):
add_image('Filtered Segs')
# finally save the result
displ()
return len(vv)-1, len(hh)-1
评论列表
文章目录