How to use the pyclipper.SimplifyPolygon function in pyclipper

To help you get started, we’ve selected a few pyclipper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cwig / start_follow_read / utils / PAGE_xml.py View on Github external
try:
            pc.AddPath(p, pyclipper.PT_CLIP, True)
        except:
            total_areas.append(np.inf)
            background_scores.append(np.inf)
            # print p
            print "Failed to assign text line, probably not an issue"
            continue
        pc.AddPaths([r['bounding_poly'] for r in regions], pyclipper.PT_SUBJECT, True)
        solution = pc.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO)

        area = 0
        for path in solution:
            area += pyclipper.Area(path)

        simple_path = pyclipper.SimplifyPolygon(p, pyclipper.PFT_NONZERO)
        total_area = 0
        for path in simple_path:
            total_area += pyclipper.Area(path)

        total_areas.append(total_area)
        background_score = total_area - area
        background_scores.append(background_score)

    return np.array(scores), np.array(background_scores), np.array(total_areas)