def run_MSER(image, show=False): mser = MSER(image, 64) data = mser.build_component_tree() universe = data["points"] root_node = data["root"] nodes= data["nodes"] component_to_points = data["component to points"] # prune the excess regions mser_regions = TextDetector.prune_MSERs(mser.grey_scale, universe, root_node, nodes, component_to_points) # def walk (tree, f): # print "walked to ", tree # f(image, component_to_points, tree) # for c in tree.children: # walk(c, f) # walk(root_node, TextDetector.draw_component) # convert to opencv contours # contours = map( lambda c: component_to_points[c.component],mser_regions) # def convertPoint(point): # lst = [point.row,point.col] # lst = np.array([lst],dtype= int32) # return [lst] #points = map(lambda i: map(lambda c : convertPoint(c),i),contours) #print list(itertools.chain(*points)) #test = np.array(reduce(lambda x, y: x+y, points),dtype= int32) # our_contours = map(lambda c: np.array(reduce(lambda x, y: x+y, map(lambda p: convertPoint(p), c)),dtype= int32),contours) if show: for region in mser_regions: TextDetector.draw_colour_component(image, component_to_points, region.component) return mser_regions
def run_MSER(image, show=False): mser = MSER(image, 64) data = mser.build_component_tree() universe = data["points"] root_node = data["root"] nodes = data["nodes"] component_to_points = data["component to points"] # prune the excess regions mser_regions = TextDetector.prune_MSERs(mser.grey_scale, universe, root_node, nodes, component_to_points) # def walk (tree, f): # print "walked to ", tree # f(image, component_to_points, tree) # for c in tree.children: # walk(c, f) # walk(root_node, TextDetector.draw_component) # convert to opencv contours # contours = map( lambda c: component_to_points[c.component],mser_regions) # def convertPoint(point): # lst = [point.row,point.col] # lst = np.array([lst],dtype= int32) # return [lst] #points = map(lambda i: map(lambda c : convertPoint(c),i),contours) #print list(itertools.chain(*points)) #test = np.array(reduce(lambda x, y: x+y, points),dtype= int32) # our_contours = map(lambda c: np.array(reduce(lambda x, y: x+y, map(lambda p: convertPoint(p), c)),dtype= int32),contours) if show: for region in mser_regions: TextDetector.draw_colour_component(image, component_to_points, region.component) return mser_regions