def skeletonizationCffi(self, ogm, origin, resolution, ogml):
        # width = ogm.shape[0]
        # height = ogm.shape[1]

        local = numpy.zeros(ogm.shape)
        local[ogm < 49] = 1
        # for i in range(0, width):
        #   for j in range(0, height):
        #     if ogm[i][j] < 49:
        #       local[i][j] = 1

        skeleton = Cffi.thinning(local, ogml)
        skeleton = Cffi.prune(skeleton, ogml, 10)

        # viz = []
        # for i in range(0, width):
        #   for j in range(0, height):
        #     if skeleton[i][j] == 1:
        #       viz.append([i * resolution + origin['x'],j * resolution + origin['y']])
        viz = (numpy.array(numpy.where(skeleton == 1)).T * resolution +
               [origin['x'], origin['y']]).tolist()

        RvizHandler.printMarker(\
                viz,\
                1, # Type: Arrow
                0, # Action: Add
                "map", # Frame
                "art_skeletonization_cffi", # Namespace
                [0.5, 0, 0, 0.5], # Color RGBA
                0.05 # Scale
            )

        return skeleton
예제 #2
0
    def skeletonizationCffi(self, ogm, origin, resolution, ogml):
        width = ogm.shape[0]
        height = ogm.shape[1]

        local = numpy.zeros(ogm.shape)

        for i in range(0, width):
            for j in range(0, height):
                if ogm[i][j] < 49:
                    local[i][j] = 1

        skeleton = Cffi.thinning(local, ogml)
        skeleton = Cffi.prune(skeleton, ogml, 10)

        viz = []
        for i in range(0, width):
            for j in range(0, height):
                if skeleton[i][j] == 1:
                    viz.append([
                        i * resolution + origin['x'],
                        j * resolution + origin['y']
                    ])

        RvizHandler.printMarker(\
                viz,\
                1, # Type: Arrow
                0, # Action: Add
                "map", # Frame
                "art_skeletonization_cffi", # Namespace
                [0.5, 0, 0, 0.5], # Color RGBA
                0.05 # Scale
            )

        return skeleton
    def skeletonizationCffi(ogm, origin, resolution, ogml):

        local = numpy.zeros(ogm.shape)
        local = set_ogm(ogm, local, ogm.shape[0], ogm.shape[1])

        #start = time()
        skeleton = Cffi.thinning(local, ogml)
        #print str('SkeletonizationCffi: Thinning in ') + str(time() - start) + str(' seconds.')

        #start = time()
        skeleton = Cffi.prune(skeleton, ogml, 10)
        #print str('SkeletonizationCffi: Prunning in ') + str(time() - start) + str(' seconds.')

        #start = time()
        '''
        viz = set_skeleton_viz(skeleton, numpy.zeros((set_skeleton_viz_number(skeleton, ogm.shape[0], ogm.shape[1]), 2), dtype=numpy.float64),
                               ogm.shape[0], ogm.shape[1], resolution, origin['x'], origin['y'])
        RvizHandler.printMarker(viz, 1, 0, "map", "art_skeletonization_cffi", [0.5, 0, 0, 0.5], 0.05)
        '''
        '''
        viz = []
        for i in range(0, ogm.shape[0]):
            for j in range(0, ogm.shape[1]):
                if skeleton[i][j] == 1:
                    viz.append([i * resolution + origin['x'],j * resolution + origin['y']])

        print str('SkeletonizationCffi: Visualization in ') + str(time() - start) + str(' seconds.')
        RvizHandler.printMarker(viz, 1, 0, "map", "art_skeletonization_cffi", [0.5, 0, 0, 0.5], 0.05)
        '''
        return skeleton
예제 #4
0
def skeletonizationCffi(ogm, origin, resolution, ogml):
    skeleton = (ogm < 49).astype("int32")
    skeleton = Cffi.thinning(skeleton, ogml)
    skeleton = Cffi.prune(skeleton, ogml, 10)

    print_viz(skeleton, resolution, origin['x'], origin['y'])
    return skeleton
예제 #5
0
    def skeletonizationCffi(self, ogm, origin, resolution, ogml):
        width = ogm.shape[0]
        height = ogm.shape[1]
        # import time
        local = numpy.zeros(ogm.shape)

        # 10x faster
        local[numpy.where(ogm < 49)] = 1

        # local2 = numpy.zeros(ogm.shape)
        # start = time.time()
        # for i in range(0, width):
        #   for j in range(0, height):
        #     if ogm[i][j] < 49:
        #       local[i][j] = 1
        # end = time.time()
        # print ("loop took:", end-start)
        # start = time.time()
        # local[numpy.where(ogm<49)] = 1
        # end = time.time()
        # print ("numpy took:", end-start)

        skeleton = Cffi.thinning(local, ogml)
        skeleton = Cffi.prune(skeleton, ogml, 10)

        viz = []
        for i in range(0, width):
            for j in range(0, height):
                if skeleton[i][j] == 1:
                    viz.append([
                        i * resolution + origin['x'],
                        j * resolution + origin['y']
                    ])



        RvizHandler.printMarker(\
                viz,\
                1, # Type: Arrow
                0, # Action: Add
                "map", # Frame
                "art_skeletonization_cffi", # Namespace
                [0.5, 0, 0, 0.5], # Color RGBA
                0.05 # Scale
            )

        return skeleton
    def skeletonizationCffi(self, ogm, origin, resolution, ogml):
        width = ogm.shape[0]
        height = ogm.shape[1]

        local = numpy.zeros(ogm.shape)

        start = time.time()

        ########################################################################
        ####################### Original Code ##################################

        # for i in range(0, width):
        #   for j in range(0, height):
        #     if ogm[i][j] < 49:
        #       local[i][j] = 1

        ############################ Added code #################################
        step = 50
        first = [0, 0]
        last = [0, 0]
        # Find the area in which there is propability of coverage
        for i in range(0, width, step):
            for j in range(0, height, step):
                if ogm[i][j] < 49:
                    if first == [0, 0]:
                        first = [i, j]
                    last = [i, j]

        # Search only in the area found
        for i in range(first[0] - step, last[0] + step):
            for j in range(first[1] - step, last[1] + step):
                if ogm[i][j] < 49:
                    local[i][j] = 1

    #########################################################################

        end = time.time()

        print end - start

        skeleton = Cffi.thinning(local, ogml)
        skeleton = Cffi.prune(skeleton, ogml, 10)

        viz = []
        for i in range(0, width):
            for j in range(0, height):
                if skeleton[i][j] == 1:
                    viz.append([
                        i * resolution + origin['x'],
                        j * resolution + origin['y']
                    ])


        RvizHandler.printMarker(\
                viz,\
                1, # Type: Arrow
                0, # Action: Add
                "map", # Frame
                "art_skeletonization_cffi", # Namespace
                [0.5, 0, 0, 0.5], # Color RGBA
                0.05 # Scale
            )

        return skeleton