From a62194de9f6031d6141e09c1759331a4218efbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=A4fer?= Date: Sun, 23 Apr 2017 23:01:54 +0200 Subject: [PATCH] Draw image detections other than traffic signs in a different color (green instead of orange) Also, now only for traffic signs the icon is drawn onto the image. --- .../mapillary/gui/MapillaryImageDisplay.java | 20 +++--- .../mapillary/model/ImageDetection.java | 14 +++- .../mapillary/utils/MapillaryColorScheme.java | 3 +- .../utils/api/JsonImageDetectionDecoder.java | 5 +- .../data/api/v3/responses/imageDetection.json | 1 + .../v3/responses/searchImageDetections.json | 70 ++++++++++--------- .../api/JsonImageDetectionDecoderTest.java | 40 +++++------ 7 files changed, 86 insertions(+), 67 deletions(-) diff --git a/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java b/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java index eda635727..56c561f00 100644 --- a/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java +++ b/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java @@ -426,18 +426,20 @@ public void paintComponent(Graphics g) { AffineTransform unit2compTransform = AffineTransform.getTranslateInstance(upperLeft.getX(), upperLeft.getY()); unit2compTransform.concatenate(AffineTransform.getScaleInstance(lowerRight.getX() - upperLeft.getX(), lowerRight.getY() - upperLeft.getY())); - Graphics2D g2d = (Graphics2D) g; + final Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(2)); - g2d.setColor(MapillaryColorScheme.TRAFFICSIGNS_ORANGE); for (ImageDetection d : detections) { - Shape shape = d.getShape().createTransformedShape(unit2compTransform); - g2d.drawImage( - MapObject.getIcon(d.getValue()).getImage(), - shape.getBounds().x, shape.getBounds().y, - shape.getBounds().width, shape.getBounds().height, - null - ); + final Shape shape = d.getShape().createTransformedShape(unit2compTransform); + g2d.setColor(d.isTrafficSign() ? MapillaryColorScheme.IMAGEDETECTION_TRAFFICSIGN : MapillaryColorScheme.IMAGEDETECTION_UNKNOWN); g2d.draw(shape); + if (d.isTrafficSign()) { + g2d.drawImage( + MapObject.getIcon(d.getValue()).getImage(), + shape.getBounds().x, shape.getBounds().y, + shape.getBounds().width, shape.getBounds().height, + null + ); + } } } } diff --git a/src/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java b/src/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java index a692f8a9e..794d663a0 100644 --- a/src/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java +++ b/src/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java @@ -5,15 +5,23 @@ public class ImageDetection extends SpecialImageArea { + private static final String PACKAGE_TRAFFIC_SIGNS = "trafficsign"; + + private final String packag; private final double score; private final String value; - public ImageDetection(final Path2D shape, final String image, final String key, final double score, final String value) { + public ImageDetection(final Path2D shape, final String image, final String key, final double score, final String packag, final String value) { super(shape, image, key); + this.packag = packag; this.score = score; this.value = value; } + public String getPackage() { + return packag; + } + public double getScore() { return score; } @@ -22,4 +30,8 @@ public String getValue() { return value; } + public boolean isTrafficSign() { + return PACKAGE_TRAFFIC_SIGNS.equals(packag); + } + } diff --git a/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryColorScheme.java b/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryColorScheme.java index 026ca8bd5..5f672e726 100644 --- a/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryColorScheme.java +++ b/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryColorScheme.java @@ -41,7 +41,8 @@ public final class MapillaryColorScheme { public static final Color MAPILLARY_GREEN = new Color(0x35af6d); public static final Color TOOLBAR_DARK_GREY = new Color(0x242528); - public static final Color TRAFFICSIGNS_ORANGE = new Color(0xffc01b); + public static final Color IMAGEDETECTION_TRAFFICSIGN = new Color(0xffc01b); + public static final Color IMAGEDETECTION_UNKNOWN = new Color(0x33bb44); private MapillaryColorScheme() { // Private constructor to avoid instantiation diff --git a/src/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java b/src/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java index 2cbed4fd3..89a071db2 100644 --- a/src/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java +++ b/src/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java @@ -32,13 +32,14 @@ public static ImageDetection decodeImageDetection(final JsonObject json) { final JsonValue properties = json.get("properties"); if (properties instanceof JsonObject) { final String key = ((JsonObject) properties).getString("key", null); + final String packag = ((JsonObject) properties).getString("package", null); final String imageKey = ((JsonObject) properties).getString("image_key", null); final String value = ((JsonObject) properties).getString("value", null); final JsonValue scoreVal = ((JsonObject) properties).get("score"); final Double score = scoreVal instanceof JsonNumber ? ((JsonNumber) scoreVal).doubleValue() : null; final Shape shape = decodeShape(((JsonObject) properties).get("shape")); - if (shape instanceof Path2D && imageKey != null && key != null && score != null && value != null) { - return new ImageDetection((Path2D) shape, imageKey, key, score, value); + if (shape instanceof Path2D && imageKey != null && key != null && score != null && packag != null && value != null) { + return new ImageDetection((Path2D) shape, imageKey, key, score, packag, value); } } return null; diff --git a/test/data/api/v3/responses/imageDetection.json b/test/data/api/v3/responses/imageDetection.json index b74b6950b..cb4a0d3e3 100644 --- a/test/data/api/v3/responses/imageDetection.json +++ b/test/data/api/v3/responses/imageDetection.json @@ -4,6 +4,7 @@ "area": 0.0015604496002197266, "image_key": "QhRcdlGS_Rn_a1_HTclefg", "key": "gn0llgitnnuqonecevbmf52ino", + "package": "trafficsign", "score": 0.710661225175, "shape": { "type": "Polygon", diff --git a/test/data/api/v3/responses/searchImageDetections.json b/test/data/api/v3/responses/searchImageDetections.json index 881ec6199..96494b879 100644 --- a/test/data/api/v3/responses/searchImageDetections.json +++ b/test/data/api/v3/responses/searchImageDetections.json @@ -4,88 +4,90 @@ { "type": "Feature", "properties": { - "area": 0.0009162808641975282, - "image_key": "LNuUpMXZax88-VuqNoiqEQ", - "key": "u0lvc577hes4a0k8pgkak6pr5g", - "score": 0.999222, + "area": 0.00010585784912109375, + "image_key": "33zgql54_tBVvmIij0zrcA", + "key": "bzqdn10wz1s1xd3lae3hawgja0", + "package": "trafficsign", + "score": 0.000001, "shape": { "type": "Polygon", "coordinates": [ [ [ - 0.74365234375, - 0.530029296875 + 0.42724609375, + 0.69091796875 ], [ - 0.7646484375, - 0.530029296875 + 0.436279296875, + 0.69091796875 ], [ - 0.7646484375, - 0.573974609375 + 0.436279296875, + 0.70263671875 ], [ - 0.74365234375, - 0.573974609375 + 0.42724609375, + 0.70263671875 ], [ - 0.74365234375, - 0.530029296875 + 0.42724609375, + 0.69091796875 ] ] ] }, - "value": "regulatory--go-straight--g1" + "value": "information--pedestrians-crossing--g1" }, "geometry": { "type": "Point", "coordinates": [ - 32.20263300647002, - 50.22795119437956 + 12.995127, + 55.550739 ] } }, { "type": "Feature", "properties": { - "area": 0.0003740798811354602, - "image_key": "8Crlqn_Tq3Gbj_QrTSeJqQ", - "key": "as4sbsi48vbfk4555q18rq9jnj", - "score": 0.985142, + "area": 0.00010585784912109375, + "image_key": "33zgql54_tBVvmIij0zrcA", + "key": "uzve1xkyk5qbjwrzaq0do09u1x", + "package": "trafficsign", + "score": 0.000001, "shape": { "type": "Polygon", "coordinates": [ [ [ - 0.828125, - 0.490478515625 + 0.42724609375, + 0.69091796875 ], [ - 0.846923828125, - 0.490478515625 + 0.436279296875, + 0.69091796875 ], [ - 0.846923828125, - 0.510498046875 + 0.436279296875, + 0.70263671875 ], [ - 0.828125, - 0.510498046875 + 0.42724609375, + 0.70263671875 ], [ - 0.828125, - 0.490478515625 + 0.42724609375, + 0.69091796875 ] ] ] }, - "value": "regulatory--u-turn--g1" + "value": "information--pedestrians-crossing--g1" }, "geometry": { "type": "Point", "coordinates": [ - 32.28697069999998, - 50.2510178 + 12.995127, + 55.550739 ] } } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java index c0ef3cc7e..5cf8b96b1 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java @@ -46,32 +46,32 @@ public void testDecodeImageDetections() { detections.put(detection.getKey(), detection); } - final ImageDetection id1 = detections.get("u0lvc577hes4a0k8pgkak6pr5g"); - assertEquals("LNuUpMXZax88-VuqNoiqEQ", id1.getImageKey()); - assertEquals("u0lvc577hes4a0k8pgkak6pr5g", id1.getKey()); - assertEquals(0.999222, id1.getScore(), 1e-9); - assertEquals("regulatory--go-straight--g1", id1.getValue()); + final ImageDetection id1 = detections.get("bzqdn10wz1s1xd3lae3hawgja0"); + assertEquals("33zgql54_tBVvmIij0zrcA", id1.getImageKey()); + assertEquals("bzqdn10wz1s1xd3lae3hawgja0", id1.getKey()); + assertEquals(0.000001, id1.getScore(), 1e-9); + assertEquals("information--pedestrians-crossing--g1", id1.getValue()); final PathIterator pi1 = id1.getShape().getPathIterator(new AffineTransform()); - testPathSegment(pi1, PathIterator.SEG_MOVETO, 0.74365234375, 0.530029296875); - testPathSegment(pi1, PathIterator.SEG_LINETO, 0.7646484375, 0.530029296875); - testPathSegment(pi1, PathIterator.SEG_LINETO, 0.7646484375, 0.573974609375); - testPathSegment(pi1, PathIterator.SEG_LINETO, 0.74365234375, 0.573974609375); - testPathSegment(pi1, PathIterator.SEG_LINETO, 0.74365234375, 0.530029296875); + testPathSegment(pi1, PathIterator.SEG_MOVETO, 0.42724609375, 0.69091796875); + testPathSegment(pi1, PathIterator.SEG_LINETO, 0.436279296875, 0.69091796875); + testPathSegment(pi1, PathIterator.SEG_LINETO, 0.436279296875, 0.70263671875); + testPathSegment(pi1, PathIterator.SEG_LINETO, 0.42724609375, 0.70263671875); + testPathSegment(pi1, PathIterator.SEG_LINETO, 0.42724609375, 0.69091796875); testPathSegment(pi1, PathIterator.SEG_CLOSE, 0, 0); - final ImageDetection id2 = detections.get("as4sbsi48vbfk4555q18rq9jnj"); - assertEquals("8Crlqn_Tq3Gbj_QrTSeJqQ", id2.getImageKey()); - assertEquals("as4sbsi48vbfk4555q18rq9jnj", id2.getKey()); - assertEquals(0.985142, id2.getScore(), 1e-9); - assertEquals("regulatory--u-turn--g1", id2.getValue()); + final ImageDetection id2 = detections.get("uzve1xkyk5qbjwrzaq0do09u1x"); + assertEquals("33zgql54_tBVvmIij0zrcA", id2.getImageKey()); + assertEquals("uzve1xkyk5qbjwrzaq0do09u1x", id2.getKey()); + assertEquals(0.000001, id2.getScore(), 1e-9); + assertEquals("information--pedestrians-crossing--g1", id2.getValue()); final PathIterator pi2 = id2.getShape().getPathIterator(new AffineTransform()); - testPathSegment(pi2, PathIterator.SEG_MOVETO, 0.828125, 0.490478515625); - testPathSegment(pi2, PathIterator.SEG_LINETO, 0.846923828125, 0.490478515625); - testPathSegment(pi2, PathIterator.SEG_LINETO, 0.846923828125, 0.510498046875); - testPathSegment(pi2, PathIterator.SEG_LINETO, 0.828125, 0.510498046875); - testPathSegment(pi2, PathIterator.SEG_LINETO, 0.828125, 0.490478515625); + testPathSegment(pi2, PathIterator.SEG_MOVETO, 0.42724609375, 0.69091796875); + testPathSegment(pi2, PathIterator.SEG_LINETO, 0.436279296875, 0.69091796875); + testPathSegment(pi2, PathIterator.SEG_LINETO, 0.436279296875, 0.70263671875); + testPathSegment(pi2, PathIterator.SEG_LINETO, 0.42724609375, 0.70263671875); + testPathSegment(pi2, PathIterator.SEG_LINETO, 0.42724609375, 0.69091796875); testPathSegment(pi2, PathIterator.SEG_CLOSE, 0, 0); }