Esempio n. 1
0
    def generate_regions(self):
        if len(self.initial_lines) == 0:
            return
        
        #print("KKKKKKKKKKKKKKK ::::")
        #print(np.shape(self.initial_lines))

        # Sort lines by row position
        self.initial_lines.sort(key=Line().get_min_row_position)
        #reset line regions
        self.lines_region = []
        # Add first region
        r = Region(top=Line(), bottom=self.initial_lines[0])

        # r.update_region(self.thresh, 0)
        r.update_region(self.gray_img, 0)
        self.initial_lines[0].above = r
        self.lines_region.append(r)

        if r.height < self.predicted_line_height * 2.5:
            self.avg_line_height += r.height

        # Add rest of regions.
        for i in range(len(self.initial_lines)):
            #print(i)
            top_line = self.initial_lines[i]
            if i + 1 < len(self.initial_lines):
                bottom_line = self.initial_lines[i + 1]
            else:
                bottom_line = Line()
            # Assign lines to region.
            r = Region(top_line, bottom_line)
            # res = r.update_region(self.thresh, i)
            res = r.update_region(self.gray_img, i)
            # Assign regions to lines
            if top_line.initial_valley_id != -1:
                top_line.below = r

            if bottom_line.initial_valley_id != -1:
                bottom_line.above = r
            if res is False:
                self.lines_region.append(r)
                if (r.height < self.predicted_line_height * 2.5):
                    self.avg_line_height += r.height
            print(np.shape(r))
        #print("LALLALALLA :::::")
        #print(np.shape(self.lines_region))



        # Just for calculating mean
        if len(self.lines_region) > 0:
            self.avg_line_height /= len(self.lines_region)
            print("Avg line height is {}".format(int(self.avg_line_height)))