|
@@ -10,10 +10,12 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -42,7 +44,8 @@ public class FaceVerifyTest {
|
|
|
FaceVerifyProperties properties = new FaceVerifyProperties();
|
|
|
properties.setBaiduLocalEnabled(true);
|
|
|
properties.setBaiduLocalAppId("test");
|
|
|
- properties.setBaiduLocalUrlPrefix("http://192.168.10.102:8301");
|
|
|
+ // properties.setBaiduLocalUrlPrefix("http://192.168.10.102:8301");
|
|
|
+ properties.setBaiduLocalUrlPrefix("http://192.168.0.117:8300");
|
|
|
|
|
|
faceVerifyService = new FaceVerifyServiceImpl();
|
|
|
faceVerifyService.setProperties(properties);
|
|
@@ -53,7 +56,7 @@ public class FaceVerifyTest {
|
|
|
String excelFile = dir + "/" + fileName + ".xlsx";
|
|
|
List<String[]> lines = ExcelReader.readSheetBySax(excelFile, 1, 8);
|
|
|
|
|
|
- int batchNum = 10;
|
|
|
+ int batchNum = 50;
|
|
|
int totalLines = lines.size() - 1;
|
|
|
List<String[]> batchList = new ArrayList<>();
|
|
|
long startTime = System.currentTimeMillis();
|
|
@@ -82,19 +85,24 @@ public class FaceVerifyTest {
|
|
|
|
|
|
long cost = (System.currentTimeMillis() - startTime) / 1000L;
|
|
|
float passRate = passNum.get() * 100f / totalNum.get();
|
|
|
- System.out.printf("totalLines:%s passNum:%s 通过率:%s%% 不通过率:%s%% 耗时:%s秒 %n", totalNum.get(), passNum.get(), passRate, 100 - passRate, cost);
|
|
|
-
|
|
|
- // 修改阈值,重新计算通过率
|
|
|
- // int passNum = 0;
|
|
|
- // double passScore = 75d;
|
|
|
- // for (Map.Entry<String, Double> entry : scores.entrySet()) {
|
|
|
- // // System.out.println(entry.getKey() + " " + entry.getValue());
|
|
|
- // if (entry.getValue() >= passScore) {
|
|
|
- // passNum++;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // float passRate2 = passNum * 100f / totalNum.get();
|
|
|
- // System.out.printf("totalLines:%s passNum:%s 通过率:%s%% 不通过率:%s%% %n", totalNum.get(), passNum, passRate2, 100 - passRate2);
|
|
|
+ System.out.printf("totalLines:%s passNum:%s 通过率:%s%% 不通过率:%s%% 耗时:%s秒 %n%n", totalNum.get(), passNum.get(), passRate, 100 - passRate, cost);
|
|
|
+
|
|
|
+ // 重新计算不同阈值下的通过率
|
|
|
+ Map<Double, Integer> statisticMaps = new TreeMap<>();
|
|
|
+ for (int n = 65; n <= 80; n++) {
|
|
|
+ statisticMaps.put((double) n, 1);
|
|
|
+ }
|
|
|
+ for (Map.Entry<String, Double> entry : scores.entrySet()) {
|
|
|
+ for (Map.Entry<Double, Integer> map : statisticMaps.entrySet()) {
|
|
|
+ if (entry.getValue() >= map.getKey()) {
|
|
|
+ statisticMaps.put(map.getKey(), map.getValue() + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Map.Entry<Double, Integer> map : statisticMaps.entrySet()) {
|
|
|
+ double newPassRate = round(map.getValue() * 100d / totalNum.get(), 2);
|
|
|
+ System.out.printf("百度阈值:%s 通过率:%s%% 不通过率:%s%% %n", map.getKey(), newPassRate, round(100d - newPassRate, 2));
|
|
|
+ }
|
|
|
|
|
|
service.shutdown();
|
|
|
}
|
|
@@ -133,8 +141,10 @@ public class FaceVerifyTest {
|
|
|
String x = FileUtil.readFile(resultFile).get(0);
|
|
|
if (x.contains("true")) {
|
|
|
passNum.incrementAndGet();
|
|
|
+ } else {
|
|
|
+ // System.out.println(x + " | " + photoPath + " | " + capturePhotoPath);
|
|
|
}
|
|
|
- // scores.put(photoUrl + "|" + capturePhotoUrl, Double.valueOf(x.split("\\|")[1]));
|
|
|
+ scores.put(photoUrl + "|" + capturePhotoUrl, Double.valueOf(x.split("\\|")[1]));
|
|
|
} else {
|
|
|
FaceResult result = faceVerifyService.faceCompareByBaidu(photoFile, capturePhotoFile);
|
|
|
// System.out.println(new JsonHelper().toJson(result));
|
|
@@ -187,4 +197,11 @@ public class FaceVerifyTest {
|
|
|
return prefix + url;
|
|
|
}
|
|
|
|
|
|
+ private double round(double value, int n) {
|
|
|
+ if (n < 0) n = 0;
|
|
|
+ BigDecimal _value = new BigDecimal(Double.toString(value));
|
|
|
+ BigDecimal one = new BigDecimal("1");
|
|
|
+ return _value.divide(one, n, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ }
|
|
|
+
|
|
|
}
|