Skip to content

Commit 7d406c0

Browse files
committed
Tweak live ODT code.
Change-Id: I1c23ab8b523404a054525c0e8ac7cbb54897abb0
1 parent 341bd87 commit 7d406c0

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/java/objectdetection/ObjectDetectorProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void stop() {
3636
try {
3737
detector.close();
3838
} catch (IOException e) {
39-
Log.e(TAG, "Exception thrown while trying to close Face Contour Detector: " + e);
39+
Log.e(TAG, "Exception thrown while trying to close object detector!", e);
4040
}
4141
}
4242

@@ -65,7 +65,6 @@ protected void onSuccess(
6565

6666
@Override
6767
protected void onFailure(@NonNull Exception e) {
68-
Log.e(TAG, "Object detection failed " + e);
68+
Log.e(TAG, "Object detection failed!", e);
6969
}
7070
}
71-

mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/java/objectdetection/ObjectGraphic.java

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,26 @@
1313
/** Draw the detected object info in preview. */
1414
public class ObjectGraphic extends Graphic {
1515

16-
private static final int TEXT_COLOR = Color.WHITE;
1716
private static final float TEXT_SIZE = 54.0f;
1817
private static final float STROKE_WIDTH = 4.0f;
1918

20-
private final Paint rectPaint;
21-
private final Paint labelPaint;
22-
private final Paint idPaint;
23-
private final Paint scorePaint;
24-
private final Paint entityIdPaint;
2519
private final FirebaseVisionObject object;
20+
private final Paint boxPaint;
21+
private final Paint textPaint;
2622

2723
ObjectGraphic(GraphicOverlay overlay, FirebaseVisionObject object) {
2824
super(overlay);
2925

3026
this.object = object;
3127

32-
rectPaint = new Paint();
33-
rectPaint.setColor(TEXT_COLOR);
34-
rectPaint.setStyle(Style.STROKE);
35-
rectPaint.setStrokeWidth(STROKE_WIDTH);
28+
boxPaint = new Paint();
29+
boxPaint.setColor(Color.WHITE);
30+
boxPaint.setStyle(Style.STROKE);
31+
boxPaint.setStrokeWidth(STROKE_WIDTH);
3632

37-
labelPaint = new Paint();
38-
labelPaint.setColor(TEXT_COLOR);
39-
labelPaint.setTextSize(TEXT_SIZE);
40-
41-
idPaint = new Paint();
42-
idPaint.setColor(TEXT_COLOR);
43-
idPaint.setTextSize(TEXT_SIZE);
44-
45-
scorePaint = new Paint();
46-
scorePaint.setColor(TEXT_COLOR);
47-
scorePaint.setTextSize(TEXT_SIZE);
48-
49-
entityIdPaint = new Paint();
50-
entityIdPaint.setColor(TEXT_COLOR);
51-
entityIdPaint.setTextSize(TEXT_SIZE);
33+
textPaint = new Paint();
34+
textPaint.setColor(Color.WHITE);
35+
textPaint.setTextSize(TEXT_SIZE);
5236
}
5337

5438
@Override
@@ -59,19 +43,18 @@ public void draw(Canvas canvas) {
5943
rect.top = translateY(rect.top);
6044
rect.right = translateX(rect.right);
6145
rect.bottom = translateY(rect.bottom);
62-
canvas.drawRect(rect, rectPaint);
63-
64-
// Renders the label at the bottom of the box.
46+
canvas.drawRect(rect, boxPaint);
6547

48+
// Draws other object info.
6649
canvas.drawText(
67-
getLabel(object.getClassificationCategory()), rect.left, rect.bottom, labelPaint);
68-
canvas.drawText("id: " + object.getTrackingId(), rect.left, rect.top, idPaint);
50+
getCategoryName(object.getClassificationCategory()), rect.left, rect.bottom, textPaint);
51+
canvas.drawText("trackingId: " + object.getTrackingId(), rect.left, rect.top, textPaint);
6952
canvas.drawText(
70-
"confidence: " + object.getClassificationConfidence(), rect.right, rect.bottom, idPaint);
71-
canvas.drawText("eid:" + object.getEntityId(), rect.right, rect.top, labelPaint);
53+
"confidence: " + object.getClassificationConfidence(), rect.right, rect.bottom, textPaint);
54+
canvas.drawText("eid:" + object.getEntityId(), rect.right, rect.top, textPaint);
7255
}
7356

74-
private static String getLabel(@FirebaseVisionObject.Category int category) {
57+
private static String getCategoryName(@FirebaseVisionObject.Category int category) {
7558
switch (category) {
7659
case FirebaseVisionObject.CATEGORY_UNKNOWN:
7760
return "Unknown";

0 commit comments

Comments
 (0)