From 4085190b3dbce68434c3eb1f806dea0c69a247f4 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sat, 2 Dec 2023 15:33:43 +0900 Subject: [PATCH 1/2] Increase resolution of polygon approximation --- labelme/ai/models/segment_anything.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/labelme/ai/models/segment_anything.py b/labelme/ai/models/segment_anything.py index 527e4b765..2eb3aaee7 100644 --- a/labelme/ai/models/segment_anything.py +++ b/labelme/ai/models/segment_anything.py @@ -170,9 +170,10 @@ def _compute_polygon_from_points( contours = skimage.measure.find_contours(np.pad(mask, pad_width=1)) contour = max(contours, key=_get_contour_length) + POLYGON_APPROX_TOLERANCE = 0.004 polygon = skimage.measure.approximate_polygon( coords=contour, - tolerance=np.ptp(contour, axis=0).max() / 100, + tolerance=np.ptp(contour, axis=0).max() * POLYGON_APPROX_TOLERANCE, ) polygon = np.clip(polygon, (0, 0), (mask.shape[0] - 1, mask.shape[1] - 1)) polygon = polygon[:-1] # drop last point that is duplicate of first point From f0f4e59b1f5464ba8aab945c14f513a01655ef63 Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sat, 2 Dec 2023 16:02:12 +0900 Subject: [PATCH 2/2] Stop using test function to get window instance --- tests/labelme_tests/test_app.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/labelme_tests/test_app.py b/tests/labelme_tests/test_app.py index 53ce3a872..2cf99c7f1 100644 --- a/tests/labelme_tests/test_app.py +++ b/tests/labelme_tests/test_app.py @@ -55,8 +55,7 @@ def test_MainWindow_open_json(qtbot): win.close() -@pytest.mark.gui -def test_MainWindow_open_dir(qtbot): +def create_MainWindow_with_directory(qtbot): directory = osp.join(data_dir, "raw") win = labelme.app.MainWindow(filename=directory) qtbot.addWidget(win) @@ -66,13 +65,13 @@ def test_MainWindow_open_dir(qtbot): @pytest.mark.gui def test_MainWindow_openNextImg(qtbot): - win = test_MainWindow_open_dir(qtbot) + win = create_MainWindow_with_directory(qtbot) win.openNextImg() @pytest.mark.gui def test_MainWindow_openPrevImg(qtbot): - win = test_MainWindow_open_dir(qtbot) + win = create_MainWindow_with_directory(qtbot) win.openNextImg()