forked from wkentaro/labelme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# flake8: noqa | ||
|
||
from labelme import testing | ||
from labelme import utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
import os.path as osp | ||
|
||
import labelme.utils | ||
|
||
|
||
def assert_labelfile_sanity(filename): | ||
assert osp.exists(filename) | ||
|
||
data = json.load(open(filename)) | ||
|
||
assert 'imagePath' in data | ||
imageData = data.get('imageData', None) | ||
if imageData is None: | ||
assert osp.exists(data['imagePath']) | ||
img = labelme.utils.img_b64_to_arr(imageData) | ||
|
||
H, W = img.shape[:2] | ||
assert 'shapes' in data | ||
for shape in data['shapes']: | ||
assert 'label' in shape | ||
assert 'points' in shape | ||
for x, y in shape['points']: | ||
assert 0 <= x <= W | ||
assert 0 <= y <= H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os.path as osp | ||
import shutil | ||
import tempfile | ||
|
||
import labelme.app | ||
import labelme.testing | ||
|
||
|
||
here = osp.dirname(osp.abspath(__file__)) | ||
data_dir = osp.join(here, 'data') | ||
|
||
|
||
def test_MainWindow_open(qtbot): | ||
win = labelme.app.MainWindow() | ||
qtbot.addWidget(win) | ||
win.show() | ||
win.close() | ||
|
||
|
||
def test_MainWindow_open_json(qtbot): | ||
filename = osp.join(data_dir, 'apc2016_obj3.json') | ||
labelme.testing.assert_labelfile_sanity(filename) | ||
win = labelme.app.MainWindow(filename=filename) | ||
qtbot.addWidget(win) | ||
win.show() | ||
win.close() | ||
|
||
|
||
def test_MainWindow_annotate_jpg(qtbot): | ||
tmp_dir = tempfile.mkdtemp() | ||
filename = osp.join(tmp_dir, 'apc2016_obj3.jpg') | ||
shutil.copy(osp.join(data_dir, 'apc2016_obj3.jpg'), | ||
filename) | ||
output = osp.join(tmp_dir, 'apc2016_obj3.json') | ||
|
||
win = labelme.app.MainWindow(filename=filename, output=output) | ||
qtbot.addWidget(win) | ||
win.show() | ||
|
||
def check_imageData(): | ||
assert hasattr(win, 'imageData') | ||
assert win.imageData is not None | ||
|
||
qtbot.waitUntil(check_imageData) # wait for loadFile | ||
|
||
label = 'shelf' | ||
points = [ | ||
(26, 70), | ||
(176, 730), | ||
(986, 742), | ||
(1184, 102), | ||
] | ||
shape = label, points, None, None | ||
shapes = [shape] | ||
win.loadLabels(shapes) | ||
win.saveFile() | ||
|
||
labelme.testing.assert_labelfile_sanity(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters