我不知道为什么我得到平均值= 0.下面的代码显示了我如何计算它,下面张贴的图像显示了我得到的输出
代码
float avg = (goodMatchesList.size()/rawMatchesListSorted.size()) * 100;
Log.D(TAG, "descMatcher", "avg: " + avg);
Log.D(TAG, "descMatcher", "min: " + minDist);
Log.D(TAG, "descMatcher", "max: " + maxDist);
Log.D(TAG, "descMatcher", "objComputedDescExt.rows: " + matFactory.getComputedDescExtMatAt(0).rows());
Log.D(TAG, "descMatcher", "rawMatchesListSorted.size: " + rawMatchesListSorted.size());
Log.D(TAG, "descMatcher", "goodMatchesList.size: " + goodMatchesList.size());
答案 0 :(得分:5)
您正在划分两个整数 - (goodMatchesList.size()/rawMatchesListSorted.size())
,因此如果结果小于1,则它变为0。
对于浮点除法,请使用强制转换:
((float)goodMatchesList.size()/rawMatchesListSorted.size())*100
如果您不关心分数,则在分割之前或乘以100:
100*goodMatchesList.size()/rawMatchesListSorted.size()