Ejemplo n.º 1
0
    def _segment(self, doc, sort_by_columns, expected):
        self.assertEqual(5, len(doc.items))
        doc.set_items([])
        self.assertEqual(0, len(doc.items))

        segment_doc = SegmentDocument(sort_by_columns=sort_by_columns)
        doc, display_image = segment_doc.segment(doc)

        # Compare the rects in pixels
        actual = doc.scanned.from_normalised([i['rect'] for i in doc.items])
        self.assertEqual(list(expected), list(actual))
Ejemplo n.º 2
0
    def _segment(self, doc, sort_by_columns, expected):
        self.assertEqual(5, len(doc.items))
        doc.set_items([])
        self.assertEqual(0, len(doc.items))

        segment_doc = SegmentDocument(sort_by_columns=sort_by_columns)
        doc, display_image = segment_doc.segment(doc)

        # Compare the rects in pixels
        actual = doc.scanned.from_normalised([i['rect'] for i in doc.items])
        self.assertEqual(list(expected), list(actual))
Ejemplo n.º 3
0
def segment(dir, sort_by_columns):
    dir = Path(dir)
    segment_doc = SegmentDocument(sort_by_columns)
    for p in dir.glob('*' + InselectDocument.EXTENSION):
        doc = InselectDocument.load(p)
        if not doc.items:
            print('Segmenting [{0}]'.format(p))
            try:
                debug_print('Will segment [{0}]'.format(p))
                doc, display_image = segment_doc.segment(doc)
                del display_image  # We don't use this
                doc.save()
            except KeyboardInterrupt:
                raise
            except Exception:
                print('Error segmenting [{0}]'.format(p))
                traceback.print_exc()
            else:
                print('Segmented [{0}]'.format(doc))
        else:
            print('Skipping [{0}] as it already contains items'.format(p))
Ejemplo n.º 4
0
def segment(dir, sort_by_columns):
    dir = Path(dir)
    segment_doc = SegmentDocument(sort_by_columns)
    for p in dir.glob('*' + InselectDocument.EXTENSION):
        doc = InselectDocument.load(p)
        if not doc.items:
            print('Segmenting [{0}]'.format(p))
            try:
                debug_print('Will segment [{0}]'.format(p))
                doc, display_image = segment_doc.segment(doc)
                del display_image    # We don't use this
                doc.save()
            except KeyboardInterrupt:
                raise
            except Exception:
                print('Error segmenting [{0}]'.format(p))
                traceback.print_exc()
            else:
                print('Segmented [{0}]'.format(doc))
        else:
            print('Skipping [{0}] as it already contains items'.format(p))
Ejemplo n.º 5
0
    def __call__(self, progress):
        debug_print('SubsegmentPlugin.__call__')

        # Points as a list of tuples, with coordinates relative to
        # the top-left of the sub-segmentation window
        seeds = [(int(p.x()), int(p.y())) for p in self.seeds]

        items, display_image = SegmentDocument(self.sort_choice).subsegment(
            self.document, self.row, seeds, callback=progress)

        self.items, self.display = items, display_image

        debug_print('SegmentPlugin.__call__ exiting. Found [{0}] boxes'.format(
            len(items)))