Skip to content

Commit

Permalink
Draw image detections other than traffic signs in a different color (…
Browse files Browse the repository at this point in the history
…green instead of orange)

Also, now only for traffic signs the icon is drawn onto the image.
  • Loading branch information
floscher committed Apr 27, 2017
1 parent a865af6 commit a62194d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -22,4 +30,8 @@ public String getValue() {
return value;
}

public boolean isTrafficSign() {
return PACKAGE_TRAFFIC_SIGNS.equals(packag);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/data/api/v3/responses/imageDetection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"area": 0.0015604496002197266,
"image_key": "QhRcdlGS_Rn_a1_HTclefg",
"key": "gn0llgitnnuqonecevbmf52ino",
"package": "trafficsign",
"score": 0.710661225175,
"shape": {
"type": "Polygon",
Expand Down
70 changes: 36 additions & 34 deletions test/data/api/v3/responses/searchImageDetections.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit a62194d

Please sign in to comment.