(self, image=None, start=90, end = 0, step=-1,
                                       recursion=0)
return x_y, angle
updates angle of image, and centre using PIL.
        NOTE: this assumes the floorplan is rectangular! if you live in a
        lighthouse, the angle will not be valid!
        input is PIL image
updates angle of image, and centre using PIL.
        NOTE: this assumes the floorplan is rectangular! if you live in a
        lighthouse, the angle will not be valid!
        input is PIL image
updates angle of image and centre using PIL . NOTE : this assumes the floorplan is rectangular! if you live in a lighthouse the angle will not be valid! input is PIL image
def PIL_get_image_parameters(self, image=None, start=90, end = 0, step=-1,
                                       recursion=0):
        '''
        updates angle of image, and centre using PIL.
        NOTE: this assumes the floorplan is rectangular! if you live in a
        lighthouse, the angle will not be valid!
        input is PIL image
        '''
        if image is not None and HAVE_PIL:
            imbw = image.convert('L')
            max_area = self.base.size[0] * self.base.size[1]
            x_y = (self.base.size[0] // 2, self.base.size[1] // 2)
            angle = self.angle
            div_by_10 = False
            if step >=10 or step <=-10:
                step /= 10
                div_by_10 = True
            for try_angle in range(start, end, step):
                if div_by_10:
                    try_angle /= 10.0
                #rotate image and resize to fit
                im = imbw.rotate(try_angle, expand=True)
                box = im.getbbox()
                if box is not None:
                    area = (box[2]-box[0]) * (box[3]-box[1])
                    if area < max_area:
                        angle = try_angle
                        x_y = ((box[2] - box[0]) // 2 + box[0],
                               (box[3] - box[1]) // 2 + box[1])
                        max_area = area

        if recursion >= 1:
            return x_y, angle

        x_y, angle = self.PIL_get_image_parameters(
            image,
            (angle + 1) * 10,
            (angle - 1) * 10, -10,
            recursion + 1)

        # self.log.info("MAP: PIL: image center: "
        #               "x:%d, y:%d, angle %.2f" % (x_y[0], x_y[1], angle))
        return x_y, angle
def PIL_get_image_parameters ( self , image = None , start = 90 , end = 0 , step = - 1 , recursion = 0 ) : if image is not None and HAVE_PIL : imbw = image . convert ( 'L' ) max_area = self . base . size [ 0 ] * self . base . size [ 1 ] x_y = ( self . base . size [ 0 ] // 2 , self . base . size [ 1 ] // 2 ) angle = self . angle div_by_10 = False if step >= 10 or step <= - 10 : step /= 10 div_by_10 = True for try_angle in range ( start , end , step ) : if div_by_10 : try_angle /= 10.0 #rotate image and resize to fit im = imbw . rotate ( try_angle , expand = True ) box = im . getbbox ( ) if box is not None : area = ( box [ 2 ] - box [ 0 ] ) * ( box [ 3 ] - box [ 1 ] ) if area < max_area : angle = try_angle x_y = ( ( box [ 2 ] - box [ 0 ] ) // 2 + box [ 0 ] , ( box [ 3 ] - box [ 1 ] ) // 2 + box [ 1 ] ) max_area = area if recursion >= 1 : return x_y , angle x_y , angle = self . PIL_get_image_parameters ( image , ( angle + 1 ) * 10 , ( angle - 1 ) * 10 , - 10 , recursion + 1 ) # self.log.info("MAP: PIL: image center: " #               "x:%d, y:%d, angle %.2f" % (x_y[0], x_y[1], angle)) return x_y , angle