在图像检测Android应用中将颜色设置为文本

时间:2018-10-20 09:52:29

标签: java android android-studio tensorflow-lite

在使用tensorflow lite的图像检测android应用中,我想为检测到的标签的值设置红色,该标签的值> 0.5(例如) 我编写了此代码,但该值未显示红色,所有数字仅显示默认颜色(黑色),这是我的代码

private String printTopKLabels() {
for (int i = 0; i < labelList.size(); ++i) {
   sortedLabels.add(
 new AbstractMap.SimpleEntry<>(labelList.get(i), labelProbArray[0] [i]));
  if (sortedLabels.size() > RESULTS_TO_SHOW) {
    sortedLabels.poll();
  }
}
String textToShow = "";
final int size = sortedLabels.size();
for (int i = 0; i < size; ++i) {
  Map.Entry<String, Float> label = sortedLabels.poll();

  int color;
  if (label.getValue() > GOOD_PROB_THRESHOLD) {
    color = Color.RED;

  } else {
    color = SMALL_COLOR;
  }
  textToShow =    
String.format("\n%s:%4.2f",label.getKey(),label.getValue(),color)+textToShow
 ;
  } 

return textToShow;
 }

0 个答案:

没有答案