Example #1
0
    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
Example #2
0
    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
Example #3
0
 def aspect_ratio(component):
     copy = image.copy()
     points_in_region = MSER.extremal_region(component_to_points, component)
     num_rows, num_cols = np.shape(copy)
     min_row = num_rows
     max_row = 0
     min_col = num_cols
     max_col = 0
     for point in points_in_region:
         if point.row < min_row:
             min_row = point.row
         elif point.row > max_row:
             max_row = point.row
         if point.col < min_col:
             min_col = point.col
         elif point.col > max_col:
             max_col = point.col
     width, height = (max_row-min_row) , (max_col-min_col)
     if width > 0 and height>0:
         return float(width)/height
     return None
Example #4
0
 def aspect_ratio(component):
     copy = image.copy()
     points_in_region = MSER.extremal_region(component_to_points,
                                             component)
     num_rows, num_cols = np.shape(copy)
     min_row = num_rows
     max_row = 0
     min_col = num_cols
     max_col = 0
     for point in points_in_region:
         if point.row < min_row:
             min_row = point.row
         elif point.row > max_row:
             max_row = point.row
         if point.col < min_col:
             min_col = point.col
         elif point.col > max_col:
             max_col = point.col
     width, height = (max_row - min_row), (max_col - min_col)
     if width > 0 and height > 0:
         return float(width) / height
     return None
Example #5
0
 def size(component):
     return len(MSER.extremal_region(component_to_points, component))
Example #6
0
 def difference(component1, component2):
     return MSER.extremal_region(
         component_to_points, component1).difference(
             MSER.extremal_region(component_to_points, component2))
Example #7
0
    lambda neighbour: neighbour.intensity >= universe[0].intensity, universe)


def already_processed_neighbours(point, higher_intensity):
    if point.intensity < higher_intensity[-1].intensity:
        higher_intensity = filter(
            lambda neighbour: neighbour.intensity >= point.intensity, universe)
    return point.neighbours(higher_intensity)


logging.info("Preprocessing step")
num_points = len(universe)
i = 0
for point in universe:
    i += 1
    set1[point] = MSER.DisjointSet(point)
    set2[point] = MSER.DisjointSet(point)
    nodes[point] = MSER.ComponentTree(point.intensity)
    subtreeRoot[point] = point
i = 0
print "Universe bomb"
for point in universe:
    i += 1
    current_canonical = set1[point].find()
    current_node = set2[subtreeRoot[current_canonical.data]].find()
    #    print "Looking at ", nodes[current_node.data]
    #    if point.row == 22 and point.col == 19:
    #                    print "Looking at special point"
    for neighbour in already_processed_neighbours(point, higher_intensity):
        #        if point.row == 22 and point.col == 19:
        #            print "Neighbour of special pt ", neighbour, " ", neighbour.intensity
Example #8
0
 def size(component):
     return len(MSER.extremal_region(component_to_points, component))
Example #9
0
 def difference(component1, component2):
     return MSER.extremal_region(component_to_points, component1).difference(MSER.extremal_region(component_to_points, component2))