Пример #1
0
    def detect_lines(self):
        print "Detecting lines..."
        self.lines = []
        i = 0
        j = 0
        pixels_original = list(self.pixels)
        while (len(self.pixels) > 0):

            line = []
            angles = []
            pixel = self.pixels[i]

            while (pixel is not None):
                line.append(pixel)
                #img[pixel.y,pixel.x] = [pixel.r,pixel.g,pixel.b]
                pixel_old = pixel
                pixel = neighbour(pixel, self.pixels, angles)
                #pixel = neighbour(pixel,pixels_original,angles)

                #calculate angle between pixels
                if pixel is not None:
                    ang = angle(pixel_old, pixel)

                    angles.append(ang)
                    if len(angles) > angles_thr:
                        angles.remove(angles[0])

                    #removing pixel between old and new pixel
                    x_borders = [pixel_old.x, pixel.x]
                    y_borders = [
                        min([pixel_old.y, pixel.y]),
                        max([pixel_old.y, pixel.y])
                    ]

                    pixels_inside = [
                        item for item in self.pixels
                        if x_borders[0] <= item.x <= x_borders[1]
                        and y_borders[0] <= item.y <= y_borders[1]
                    ]

                    for item in pixels_inside:
                        #print str(item)
                        self.pixels.remove(item)

                if pixel_old in self.pixels:
                    self.pixels.remove(pixel_old)

            j += 1
            if len(line) > line_thr:
                self.lines.append(line)
Пример #2
0
    def detect_lines(self):
        print "Detecting lines..."
        self.lines = []
        i = 0
        j = 0
        #pixels_original = list(self.pixels) #debug only
        while (len(self.pixels) > 0):

            line = []
            angles = []
            pixel = self.pixels[i]

            while (pixel is not None):  #while neighbour found
                line.append(pixel)
                pixel_old = pixel
                pixel = neighbour(pixel, self.pixels, angles, self.neighbours,
                                  self.max_dist)

                #calculate angle between pixels
                if pixel is not None:
                    ang = angle(pixel_old, pixel)

                    angles.append(ang)
                    if len(angles) > self.angles_thr:
                        angles.remove(angles[0])

                    #removing pixel between old and new pixel
                    x_borders = [pixel_old.x, pixel.x]
                    y_borders = [
                        min([pixel_old.y, pixel.y]),
                        max([pixel_old.y, pixel.y])
                    ]

                    pixels_inside = [
                        item for item in self.pixels
                        if x_borders[0] <= item.x <= x_borders[1]
                        and y_borders[0] <= item.y <= y_borders[1]
                    ]

                    for item in pixels_inside:
                        self.pixels.remove(item)

                if pixel_old in self.pixels:
                    self.pixels.remove(pixel_old)

            j += 1

            if len(line) > int(self.line_thr):  #if line longer than threshold
                self.lines.append(line)
Пример #3
0
    line = []
    angles = []

    pixel = pixels_copy[i]
    #print pixel

    while (pixel is not None):
        line.append(pixel)
        #img[pixel.y,pixel.x] = [pixel.r,pixel.g,pixel.b]
        tmp[pixel.y, pixel.x] = [0, 0, 0]
        pixel_old = pixel
        pixel = neighbour(pixel, pixels, angles)

        #calculate angle between pixels
        if pixel is not None:
            ang = angle(pixel_old, pixel)

            angles.append(ang)
            if len(angles) > angles_thr:
                angles.remove(angles[0])

            #removing pixel between old and new pixel
            x_borders = [pixel_old.x, pixel.x]
            y_borders = [
                min([pixel_old.y, pixel.y]),
                max([pixel_old.y, pixel.y])
            ]

            #print "borders"
            #print x_borders, y_borders
            pixels_inside = [