(self, overwrite=False)
draw map with outlines at end of mission. Called when mission has
        finished and Roomba has docked
draw map with outlines at end of mission. Called when mission has
        finished and Roomba has docked
draw map with outlines at end of mission . Called when mission has finished and Roomba has docked
def draw_final_map(self, overwrite=False):
        '''
        draw map with outlines at end of mission. Called when mission has
        finished and Roomba has docked
        '''
        merge = self.make_blank_image()
        if HAVE_CV2:
            # NOTE: this is CPU intensive!
            edgedata = np.array(self.base.convert('L'), dtype=np.uint8)
            # find all contours
            _, contours, _ = self.findContours(
                edgedata,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
            # zero edge data for later use
            edgedata.fill(0)
            max_perimeter = 0
            max_contour = None
            for cnt in contours:
                perimeter = cv2.arcLength(cnt,True)
                if perimeter >= max_perimeter:
                    max_contour = cnt   # get the contour with maximum length
                    max_perimeter = perimeter
            if max_contour is None: return
            if len(max_contour) < 5: return
            try:
                contours.remove(max_contour)    # remove max contour from list
            except ValueError:
                self.log.warning("MAP: unable to remove contour")
                pass

            mask = np.full(edgedata.shape, 255, dtype=np.uint8) # white
            # create mask (of other contours) in black
            cv2.drawContours(mask,contours, -1, 0, -1)

            # self.draw_edges is the max deviation from a line
            # you can fiddle with this in enable_map
            approx = cv2.approxPolyDP(max_contour,
                self.draw_edges * max_perimeter,True)

            bgimage = np.array(merge)   # make blank RGBA image array
            # draw contour and fill with "lawngreen" (default)
            cv2.drawContours(bgimage,[approx] , -1, self.fillColor, -1)
            # mask image with internal contours
            bgimage = cv2.bitwise_and(bgimage,bgimage,mask = mask)
            # not dure if you really need this - uncomment if you want the
            # area outlined.
            # draw longest contour aproximated to lines (in black), width 1
            cv2.drawContours(edgedata,[approx] , -1, (255), 1)

            outline = Image.fromarray(edgedata) # outline
            base = Image.fromarray(bgimage)   # filled background image
        else:   #PIL
            base = self.base.filter(ImageFilter.SMOOTH_MORE)
            # draw edges at end of mission
            outline = base.convert('L').filter(ImageFilter.FIND_EDGES)
            # outline = ImageChops.subtract(
            #     base.convert('L').filter(ImageFilter.EDGE_ENHANCE),
            #     base.convert('L'))

        edges = ImageOps.invert(outline)
        edges = make_transparent(edges, (0, 0, 0, 255))
        if self.debug:
            self.save_image(edges, 'edges.png')
        merge = Image.alpha_composite(merge,base)
        if self.floorplan is None:
            merge = Image.alpha_composite(merge,edges)
        if overwrite:
            self.log.info("MAP: Drawing final map")
            self.timer('update_after_completed', True, 3600)
            self.base=merge

        if self.debug:
            merge_rotated = merge.rotate(180+self.angle, expand=True)
            self.save_image(merge_rotated, 'final_map.png')
def draw_final_map ( self , overwrite = False ) : merge = self . make_blank_image ( ) if HAVE_CV2 : # NOTE: this is CPU intensive! edgedata = np . array ( self . base . convert ( 'L' ) , dtype = np . uint8 ) # find all contours _ , contours , _ = self . findContours ( edgedata , cv2 . RETR_TREE , cv2 . CHAIN_APPROX_SIMPLE ) # zero edge data for later use edgedata . fill ( 0 ) max_perimeter = 0 max_contour = None for cnt in contours : perimeter = cv2 . arcLength ( cnt , True ) if perimeter >= max_perimeter : max_contour = cnt # get the contour with maximum length max_perimeter = perimeter if max_contour is None : return if len ( max_contour ) < 5 : return try : contours . remove ( max_contour ) # remove max contour from list except ValueError : self . log . warning ( "MAP: unable to remove contour" ) pass mask = np . full ( edgedata . shape , 255 , dtype = np . uint8 ) # white # create mask (of other contours) in black cv2 . drawContours ( mask , contours , - 1 , 0 , - 1 ) # self.draw_edges is the max deviation from a line # you can fiddle with this in enable_map approx = cv2 . approxPolyDP ( max_contour , self . draw_edges * max_perimeter , True ) bgimage = np . array ( merge ) # make blank RGBA image array # draw contour and fill with "lawngreen" (default) cv2 . drawContours ( bgimage , [ approx ] , - 1 , self . fillColor , - 1 ) # mask image with internal contours bgimage = cv2 . bitwise_and ( bgimage , bgimage , mask = mask ) # not dure if you really need this - uncomment if you want the # area outlined. # draw longest contour aproximated to lines (in black), width 1 cv2 . drawContours ( edgedata , [ approx ] , - 1 , ( 255 ) , 1 ) outline = Image . fromarray ( edgedata ) # outline base = Image . fromarray ( bgimage ) # filled background image else : #PIL base = self . base . filter ( ImageFilter . SMOOTH_MORE ) # draw edges at end of mission outline = base . convert ( 'L' ) . filter ( ImageFilter . FIND_EDGES ) # outline = ImageChops.subtract( #     base.convert('L').filter(ImageFilter.EDGE_ENHANCE), #     base.convert('L')) edges = ImageOps . invert ( outline ) edges = make_transparent ( edges , ( 0 , 0 , 0 , 255 ) ) if self . debug : self . save_image ( edges , 'edges.png' ) merge = Image . alpha_composite ( merge , base ) if self . floorplan is None : merge = Image . alpha_composite ( merge , edges ) if overwrite : self . log . info ( "MAP: Drawing final map" ) self . timer ( 'update_after_completed' , True , 3600 ) self . base = merge if self . debug : merge_rotated = merge . rotate ( 180 + self . angle , expand = True ) self . save_image ( merge_rotated , 'final_map.png' )