www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,21 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.FaceRecognizer;
|
||||
import it.acxent.face.FotoFace;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class FotoFaceRecognizerByModelCallable implements Callable<ResParm> {
|
||||
private FotoFace row;
|
||||
|
||||
private FaceRecognizer faceRecognizer;
|
||||
|
||||
public FotoFaceRecognizerByModelCallable(FotoFace row, FaceRecognizer faceRecognizer) {
|
||||
this.row = row;
|
||||
this.faceRecognizer = faceRecognizer;
|
||||
}
|
||||
|
||||
public ResParm call() throws Exception {
|
||||
return this.row.recognize(this.faceRecognizer, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Foto;
|
||||
import it.acxent.face.PuntoFoto;
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class IndexFotoCallable implements Callable<ResParm> {
|
||||
private Foto foto;
|
||||
|
||||
private PuntoFoto puntoFoto;
|
||||
|
||||
private File theFoto;
|
||||
|
||||
private long id_users;
|
||||
|
||||
public IndexFotoCallable(Foto foto, PuntoFoto puntoFoto, File theFoto, long id_users) {
|
||||
this.foto = foto;
|
||||
this.puntoFoto = puntoFoto;
|
||||
this.theFoto = theFoto;
|
||||
this.id_users = id_users;
|
||||
}
|
||||
|
||||
public ResParm call() throws Exception {
|
||||
ResParm rp = this.foto.indexFoto(this.puntoFoto, this.theFoto, this.id_users);
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Foto;
|
||||
import it.acxent.face.FotoI;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class IndexFotoFaceCallable implements Callable<ResParm> {
|
||||
private FotoI foto;
|
||||
|
||||
private boolean force = false;
|
||||
|
||||
private boolean detectNumbers = false;
|
||||
|
||||
public IndexFotoFaceCallable(FotoI foto, boolean detectNumbers, boolean force) {
|
||||
this.foto = foto;
|
||||
this.detectNumbers = detectNumbers;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
public ResParm call() throws Exception {
|
||||
ResParm rp = new ResParm();
|
||||
try {
|
||||
rp = Foto.loadFacesByFaceRecognition(getFoto(), this.detectNumbers, this.force);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(getFoto().getFileNameFaceRecognition()
|
||||
.substring(getFoto().getFileNameFaceRecognition().lastIndexOf("/") + 1) + " " + getFoto().getFileNameFaceRecognition().substring(getFoto().getFileNameFaceRecognition().lastIndexOf("/") + 1));
|
||||
rp.setMsg(ex);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public FotoI getFoto() {
|
||||
return this.foto;
|
||||
}
|
||||
|
||||
public void setFoto(FotoI foto) {
|
||||
this.foto = foto;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,296 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Evento;
|
||||
import it.acxent.face.FaceScore;
|
||||
import it.acxent.face.Foto;
|
||||
import it.acxent.face.FotoCR;
|
||||
import it.acxent.face.PuntoFoto;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.util.Timer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class Scoring1PuntoFotoCallableOld implements Callable<ResParm> {
|
||||
private PuntoFoto puntofoto;
|
||||
|
||||
private Evento evento;
|
||||
|
||||
private String TAG_THREAD_MSG;
|
||||
|
||||
public Scoring1PuntoFotoCallableOld(Evento evento, PuntoFoto puntofoto, String tAG_THREAD_MSG) {
|
||||
this.evento = evento;
|
||||
this.puntofoto = puntofoto;
|
||||
this.TAG_THREAD_MSG = tAG_THREAD_MSG;
|
||||
}
|
||||
|
||||
public ResParm call() throws Exception {
|
||||
boolean debug = false;
|
||||
ResParm rp = new ResParm();
|
||||
Timer timer = new Timer();
|
||||
LinkedHashMap<Long, JsonObject> lhmFaceTarget = new LinkedHashMap<>();
|
||||
LinkedHashMap<Long, JsonObject> lhmFaceQuery = new LinkedHashMap<>();
|
||||
HashSet<Long> hsTargetTrovatiId = new HashSet<>();
|
||||
int maxNumberOfThread = this.evento.getParm("MAX_NUMBER_OF_THREAD_SCORING_LVL_1").getNumeroInt();
|
||||
int NUM_QUERY_CALLABLE = this.evento.getParm("NUM_QUERY_CALLABLE_LVL_1").getNumeroInt();
|
||||
if (maxNumberOfThread <= 0)
|
||||
maxNumberOfThread = 200;
|
||||
if (NUM_QUERY_CALLABLE <= 0)
|
||||
NUM_QUERY_CALLABLE = 95;
|
||||
timer.start();
|
||||
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
|
||||
long dysType = this.evento.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
|
||||
double scoreThresold = this.evento.getScoreThresold();
|
||||
FaceRecognitionApi frApi = new FaceRecognitionApi(this.evento.getApFull());
|
||||
Foto foto = new Foto(getApFull());
|
||||
FotoCR fCR = new FotoCR(getApFull());
|
||||
fCR.setFileNameFrom(this.puntofoto.getLastFotoFileScore1());
|
||||
fCR.setFlgWithFaces(1L);
|
||||
fCR.setId_puntoFoto(this.puntofoto.getId_puntoFoto());
|
||||
fCR.setFlgFotoOrFace(1L);
|
||||
FaceScore fs = new FaceScore(getApFull());
|
||||
long fotoCount = 0L;
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
String targetDir = foto.getParm("PATHFOTO_FACE").getTesto() + foto.getParm("PATHFOTO_FACE").getTesto();
|
||||
File targetDirFile = new File(targetDir);
|
||||
if (!targetDirFile.exists())
|
||||
targetDirFile.mkdirs();
|
||||
int numFotoNoScore = (int)this.evento.getNumFotoNoScore();
|
||||
StatusMsg.updateMsgByTag(getApFull(), this.TAG_THREAD_MSG, "Callable Punto foto " +
|
||||
this.puntofoto.getDescrizione() + " RICERCA FACE PER PUNTO FOTO...........");
|
||||
Vectumerator<Foto> vecFoto = foto.findByCR(fCR, 0, 0);
|
||||
int i = 0;
|
||||
int totFacesTarget = 0;
|
||||
int totFacesQuery = 0;
|
||||
long l_id_currentFoto = 0L;
|
||||
boolean isFirstFoto = true;
|
||||
while (vecFoto.hasMoreElements() && !Evento.threadEventoScoringSTOP) {
|
||||
Foto currentFoto = (Foto)vecFoto.nextElement();
|
||||
StatusMsg.updateMsgByTag(getApFull(), this.TAG_THREAD_MSG, " punto foto:" +
|
||||
this.puntofoto.getDescrizione() + " (" + i + "/" + vecFoto.getTotNumberOfRecords() + ") tot facestarget:facesquery " + totFacesTarget + ":" + totFacesQuery + " CICLO PREPARAZIONE HASH TABLE TARGET E QUERY...... ETA preparazione: " +
|
||||
|
||||
|
||||
timer.getEta((long)vecFoto.getTotNumberOfRecords(), (long)i));
|
||||
totFacesTarget++;
|
||||
JsonObject jsonQueryRow = new JsonObject();
|
||||
jsonQueryRow.addProperty("id", Long.valueOf(currentFoto.getId_fotoFace()));
|
||||
jsonQueryRow.addProperty("path", currentFoto.getFotoFace().getFacePath());
|
||||
jsonQueryRow.addProperty("md5", currentFoto.getFotoFace().getMd5());
|
||||
jsonQueryRow.addProperty("fileName", currentFoto.getFileName());
|
||||
jsonQueryRow.addProperty("id_foto", Long.valueOf(currentFoto.getId_foto()));
|
||||
jsonQueryRow.addProperty("type", "face");
|
||||
lhmFaceTarget.put(Long.valueOf(currentFoto.getId_fotoFace()), jsonQueryRow);
|
||||
if (l_id_currentFoto > 0L && l_id_currentFoto != currentFoto.getId_foto())
|
||||
isFirstFoto = false;
|
||||
l_id_currentFoto = currentFoto.getId_foto();
|
||||
if (!isFirstFoto)
|
||||
if (!fs.hasLegamiQueryByFace(currentFoto.getId_fotoFace())) {
|
||||
totFacesQuery++;
|
||||
lhmFaceQuery.put(Long.valueOf(currentFoto.getId_fotoFace()), jsonQueryRow);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, "INIZIO CICLO PRINCIPALE ........... lhmFaceTarget size: " + lhmFaceTarget.size());
|
||||
String eta = "...";
|
||||
long numFotoScore = 0L;
|
||||
long totNumFotoScore = 0L;
|
||||
i = 0;
|
||||
long l_id_fotoTarget = 0L;
|
||||
long l_id_fotoQuery = 0L;
|
||||
int querySize = 0;
|
||||
long l_id_curretFoto = 0L;
|
||||
for (Map.Entry<Long, JsonObject> currentTargetEntry : lhmFaceTarget.entrySet()) {
|
||||
boolean scoringTrovato;
|
||||
Long fsTargetMainKey = currentTargetEntry.getKey();
|
||||
JsonObject fsTargetMainJO = currentTargetEntry.getValue();
|
||||
i++;
|
||||
if (Evento.threadEventoScoringSTOP)
|
||||
break;
|
||||
l_id_fotoTarget = fsTargetMainJO.get("id_foto").getAsLong();
|
||||
lhmFaceQuery.remove(fsTargetMainKey);
|
||||
querySize = lhmFaceQuery.size();
|
||||
if (hsTargetTrovatiId.contains(fsTargetMainKey)) {
|
||||
DBAdapter.printDebug(debug, "currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " ......... SALTO TARGET!!!! " + fsTargetMainKey + " FACCIA SU FOTO " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString());
|
||||
continue;
|
||||
}
|
||||
hsTargetTrovatiId.add(fsTargetMainKey);
|
||||
DBAdapter.printDebug(debug, "currentFoto " + fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " ......... inizio scoring do while");
|
||||
l_id_currentFoto = 0L;
|
||||
do {
|
||||
fotoCount = 1L;
|
||||
scoringTrovato = false;
|
||||
JsonObject jsonData = new JsonObject();
|
||||
jsonData.addProperty("dis_type", Long.valueOf(dysType));
|
||||
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
|
||||
jsonData.add("target", (JsonElement)fsTargetMainJO);
|
||||
JsonArray jsonQuery = new JsonArray();
|
||||
LinkedHashMap<Long, JsonObject> lhmFaceQueryCopy = new LinkedHashMap<>(lhmFaceQuery);
|
||||
for (Map.Entry<Long, JsonObject> currentQueryEntry : lhmFaceQueryCopy.entrySet()) {
|
||||
if (Evento.threadEventoScoringSTOP)
|
||||
break;
|
||||
Long fsQueryMainKey = currentQueryEntry.getKey();
|
||||
JsonObject fsQueryMainJO = currentQueryEntry.getValue();
|
||||
l_id_fotoQuery = fsQueryMainJO.get("id_foto").getAsLong();
|
||||
if (l_id_fotoQuery == l_id_fotoTarget) {
|
||||
DBAdapter.printDebug(debug, "currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " ......... SALTO QUERY!!!! " + fsQueryMainKey + " FACCIA SU FOTO " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString());
|
||||
continue;
|
||||
}
|
||||
if (l_id_currentFoto > 0L && l_id_currentFoto != l_id_fotoQuery)
|
||||
fotoCount++;
|
||||
l_id_currentFoto = fsQueryMainJO.get("id_foto").getAsLong();
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey);
|
||||
if (numFotoNoScore == 0 || fotoCount <= (long)numFotoNoScore) {
|
||||
jsonQuery.add((JsonElement)fsQueryMainJO);
|
||||
continue;
|
||||
}
|
||||
fotoCount = 1L;
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey + " faccio scoring ...");
|
||||
if (jsonQuery.size() > 0) {
|
||||
numFotoScore = chiamaApiEElabora(targetDir, jsonData, jsonQuery, frApi, fs, scoreThresold, errMsg, lhmFaceQuery, hsTargetTrovatiId, maxNumberOfThread, NUM_QUERY_CALLABLE);
|
||||
totNumFotoScore += numFotoScore;
|
||||
scoringTrovato = (numFotoScore > 0L);
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey + " NO SCORING PERCHé NON HO TROVATO FACE NELLE NUMFOTONOSCORE SUCCESSIVE!! ");
|
||||
scoringTrovato = false;
|
||||
}
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey + " scoring trovato: " + scoringTrovato);
|
||||
if (scoringTrovato) {
|
||||
jsonQuery = new JsonArray();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!scoringTrovato)
|
||||
continue;
|
||||
if (jsonQuery.size() <= 0)
|
||||
continue;
|
||||
StatusMsg.updateMsgByTag(getApFull(), this.TAG_THREAD_MSG, "Callable Punto foto " +
|
||||
this.puntofoto.getDescrizione() + " foto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face n. " + i + "/" +
|
||||
lhmFaceTarget.size() + " score trovati: " + totNumFotoScore + " query size: " + querySize + " current query size" +
|
||||
jsonQuery.size() + " " + eta);
|
||||
numFotoScore = chiamaApiEElabora(targetDir, jsonData, jsonQuery, frApi, fs, scoreThresold, errMsg, lhmFaceQuery, hsTargetTrovatiId, maxNumberOfThread, NUM_QUERY_CALLABLE);
|
||||
totNumFotoScore += numFotoScore;
|
||||
scoringTrovato = false;
|
||||
} while (scoringTrovato);
|
||||
if (l_id_curretFoto == 0L) {
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
} else if (l_id_curretFoto != l_id_fotoTarget) {
|
||||
foto.findByPrimaryKey(l_id_curretFoto);
|
||||
foto.updateCurrentFlgFaceScoringDone(2L);
|
||||
if (foto.getId_foto() > 0L) {
|
||||
this.puntofoto.setLastFotoFileScore1(foto.getFileName());
|
||||
this.puntofoto.save();
|
||||
}
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
}
|
||||
eta = timer.getEta((long)lhmFaceTarget.size(), (long)i);
|
||||
}
|
||||
StatusMsg.deleteMsgByTag(getApFull(), this.TAG_THREAD_MSG);
|
||||
rp.setReturnObj(this.puntofoto);
|
||||
return rp;
|
||||
}
|
||||
|
||||
private ApplParmFull getApFull() {
|
||||
return this.puntofoto.getApFull();
|
||||
}
|
||||
|
||||
private long chiamaApiEElabora(String targetDir, JsonObject jsonData, JsonArray jsonQuery, FaceRecognitionApi frApi, FaceScore fs, double scoreThresold, StringBuilder errMsg, LinkedHashMap<Long, JsonObject> lhpFaceQuery, HashSet<Long> hsTargetTrovatiId, int maxNumberOfThread, int NUM_QUERY_CALLABLE) {
|
||||
long numFotoScore = 0L;
|
||||
long totNumFotoScore = 0L;
|
||||
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThread);
|
||||
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
|
||||
int idxQuery = 0;
|
||||
JsonArray jsonQueryC = new JsonArray();
|
||||
for (int i = 0; i < jsonQuery.size(); i++) {
|
||||
JsonObject jsonQueryRow = jsonQuery.get(i).getAsJsonObject();
|
||||
if (idxQuery > 0 && idxQuery % NUM_QUERY_CALLABLE == 0) {
|
||||
JsonObject jsonDataCallable = jsonData.deepCopy();
|
||||
jsonDataCallable.add("query", (JsonElement)jsonQueryC);
|
||||
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, true);
|
||||
vecF.add(pool.submit(ifc));
|
||||
jsonQueryC = new JsonArray();
|
||||
}
|
||||
jsonQueryC.add((JsonElement)jsonQueryRow);
|
||||
idxQuery++;
|
||||
}
|
||||
if (jsonQueryC.size() > 0) {
|
||||
JsonObject jsonDataCallable = jsonData.deepCopy();
|
||||
jsonDataCallable.add("query", (JsonElement)jsonQueryC);
|
||||
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, true);
|
||||
vecF.add(pool.submit(ifc));
|
||||
}
|
||||
try {
|
||||
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
|
||||
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
|
||||
ResParm rp = currentFuture.get();
|
||||
numFotoScore = elaboraAfterScoring(rp, errMsg, lhpFaceQuery, hsTargetTrovatiId);
|
||||
totNumFotoScore += numFotoScore;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
pool.shutdown();
|
||||
}
|
||||
return totNumFotoScore;
|
||||
}
|
||||
|
||||
private long elaboraAfterScoring(ResParm rp, StringBuilder errMsg, LinkedHashMap<Long, JsonObject> lhpFaceQuery, HashSet<Long> hsTargetTrovatiId) {
|
||||
boolean debug = false;
|
||||
long numFotoScore = 0L;
|
||||
if (!rp.getStatus()) {
|
||||
errMsg.append(rp.getErrMsg()).append("\n");
|
||||
if (debug)
|
||||
DBAdapter.printDebug(" ******************************** elaboraAfterScoring error: " + rp.getErrMsg());
|
||||
} else {
|
||||
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
|
||||
if (hsFs != null && !hsFs.isEmpty()) {
|
||||
DBAdapter.printDebug(" ******************************** elaboraAfterScoring fsTargetSul2. hsFs.size(): " + hsFs.size() + " rpmsg:" +
|
||||
rp.getMsg());
|
||||
for (FaceScore fsTargetSul2 : hsFs) {
|
||||
numFotoScore++;
|
||||
lhpFaceQuery.remove(Long.valueOf(fsTargetSul2.getId_fotoFace2()));
|
||||
hsTargetTrovatiId.add(Long.valueOf(fsTargetSul2.getId_fotoFace2()));
|
||||
DBAdapter.printDebug(debug, " ******************************** elaboraAfterScoring: NUOVA LSH SIZE: " +
|
||||
lhpFaceQuery.size() + " numfotoscore:" + numFotoScore);
|
||||
}
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, " ******************************** elaboraAfterScoring NESSUN RISULTATO!!: " + rp.getErrMsg());
|
||||
numFotoScore = 0L;
|
||||
}
|
||||
}
|
||||
DBAdapter.printDebug(" ******************************** elaboraAfterScoring numFotoScore: " + numFotoScore);
|
||||
return numFotoScore;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,311 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Evento;
|
||||
import it.acxent.face.FaceScore;
|
||||
import it.acxent.face.Foto;
|
||||
import it.acxent.face.PuntoFoto;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.face.dispatcher.EventoProcessingDispatcher;
|
||||
import it.acxent.util.Timer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class Scoring2PuntoFotoCallable implements Callable<ResParm> {
|
||||
private PuntoFoto puntofoto;
|
||||
|
||||
private Evento evento;
|
||||
|
||||
private String TAG_THREAD_MSG;
|
||||
|
||||
private EventoProcessingDispatcher epd;
|
||||
|
||||
public Scoring2PuntoFotoCallable(EventoProcessingDispatcher epd, PuntoFoto puntofoto, String tAG_THREAD_MSG) {
|
||||
this.evento = epd.getEvento();
|
||||
this.puntofoto = puntofoto;
|
||||
this.epd = epd;
|
||||
this.TAG_THREAD_MSG = tAG_THREAD_MSG;
|
||||
}
|
||||
|
||||
public ResParm call() throws Exception {
|
||||
boolean debug = false;
|
||||
ResParm rp = new ResParm();
|
||||
Timer timer = new Timer();
|
||||
LinkedHashMap<Long, JsonObject> lhmFaceTarget = new LinkedHashMap<>();
|
||||
LinkedHashMap<Long, JsonObject> lhmFaceQuery = new LinkedHashMap<>();
|
||||
HashSet<Long> hsTargetTrovatiId = new HashSet<>();
|
||||
int maxNumberOfThread = this.evento.getParm("MAX_NUMBER_OF_THREAD_SCORING_LVL_1").getNumeroInt();
|
||||
int NUM_QUERY_CALLABLE = this.evento.getParm("NUM_QUERY_CALLABLE_LVL_1").getNumeroInt();
|
||||
if (maxNumberOfThread <= 0)
|
||||
maxNumberOfThread = 200;
|
||||
if (NUM_QUERY_CALLABLE <= 0)
|
||||
NUM_QUERY_CALLABLE = 95;
|
||||
timer.start();
|
||||
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
|
||||
long dysType = this.evento.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
|
||||
double scoreThresold = this.evento.getScoreThresold();
|
||||
FaceRecognitionApi frApi = new FaceRecognitionApi(this.evento.getApFull());
|
||||
Foto foto = new Foto(getApFull());
|
||||
FaceScore fs = new FaceScore(getApFull());
|
||||
long fotoCount = 0L;
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
String targetDir = foto.getParm("PATHFOTO_FACE").getTesto() + foto.getParm("PATHFOTO_FACE").getTesto();
|
||||
File targetDirFile = new File(targetDir);
|
||||
if (!targetDirFile.exists())
|
||||
targetDirFile.mkdirs();
|
||||
int numFotoNoScore = (int)this.evento.getNumFotoNoScore();
|
||||
StatusMsg.updateMsgByTag(getApFull(), this.TAG_THREAD_MSG, "Callable Punto foto " +
|
||||
this.puntofoto.getDescrizione() + " RICERCA FACE PER PUNTO FOTO...........");
|
||||
Vectumerator<Foto> vecFoto = foto.findFotoFaceByPuntoFotoFaceScoringDone(this.puntofoto.getId_puntoFoto(), 1L, (long)numFotoNoScore);
|
||||
DBAdapter.printDebug(debug, "SCORING1PUNTOFOTOCALLABLE vecFoto.getTotNumberOfRecords(): " + vecFoto.getTotNumberOfRecords() + " epd.threadSTOP: " +
|
||||
this.epd.isThreadSTOP());
|
||||
int i = 0;
|
||||
int totFacesTarget = 0;
|
||||
int totFacesQuery = 0;
|
||||
long l_id_currentFoto = 0L;
|
||||
boolean isFirstFoto = true;
|
||||
while (vecFoto.hasMoreElements() && !this.epd.isThreadSTOP()) {
|
||||
Foto currentFoto = (Foto)vecFoto.nextElement();
|
||||
DBAdapter.printDebug(false, "SCORING1PUNTOFOTOCALLABLE currentfoto : " + currentFoto.getFileName() + " " + i + "/" +
|
||||
vecFoto.getTotNumberOfRecords());
|
||||
if (currentFoto.getNumOfFaces() == 0L) {
|
||||
DBAdapter.printDebug(debug, "SCORING1PUNTOFOTOCALLABLE currentfoto : " + currentFoto.getFileName() + " SENZA FACCE...CONTINUE... " + i + "/" +
|
||||
vecFoto.getTotNumberOfRecords());
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
StatusMsg.updateMsgByTag(getApFull(), this.TAG_THREAD_MSG, " punto foto:" +
|
||||
this.puntofoto.getDescrizione() + " (" + i + "/" + vecFoto.getTotNumberOfRecords() + ") tot facestarget:facesquery " + totFacesTarget + ":" + totFacesQuery + " CICLO PREPARAZIONE HASH TABLE TARGET E QUERY...... ETA preparazione: " +
|
||||
|
||||
|
||||
timer.getEta((long)vecFoto.getTotNumberOfRecords(), (long)i));
|
||||
totFacesTarget++;
|
||||
JsonObject jsonQueryRow = new JsonObject();
|
||||
jsonQueryRow.addProperty("id", Long.valueOf(currentFoto.getId_fotoFace()));
|
||||
jsonQueryRow.addProperty("path", currentFoto.getFotoFace().getFacePath());
|
||||
jsonQueryRow.addProperty("md5", currentFoto.getFotoFace().getMd5());
|
||||
jsonQueryRow.addProperty("fileName", currentFoto.getFileName());
|
||||
jsonQueryRow.addProperty("id_foto", Long.valueOf(currentFoto.getId_foto()));
|
||||
jsonQueryRow.addProperty("type", "face");
|
||||
lhmFaceTarget.put(Long.valueOf(currentFoto.getId_fotoFace()), jsonQueryRow);
|
||||
if (l_id_currentFoto > 0L && l_id_currentFoto != currentFoto.getId_foto())
|
||||
isFirstFoto = false;
|
||||
l_id_currentFoto = currentFoto.getId_foto();
|
||||
if (!isFirstFoto)
|
||||
if (!fs.hasLegamiQueryByFace(currentFoto.getId_fotoFace())) {
|
||||
totFacesQuery++;
|
||||
lhmFaceQuery.put(Long.valueOf(currentFoto.getId_fotoFace()), jsonQueryRow);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
DBAdapter.printDebug(debug, "INIZIO CICLO PRINCIPALE ........... lhmFaceTarget size: " + lhmFaceTarget.size());
|
||||
String eta = "...";
|
||||
long numFotoScore = 0L;
|
||||
long totNumFotoScore = 0L;
|
||||
i = 0;
|
||||
long l_id_fotoTarget = 0L;
|
||||
long l_id_fotoQuery = 0L;
|
||||
int querySize = 0;
|
||||
long l_id_curretFoto = 0L;
|
||||
for (Map.Entry<Long, JsonObject> currentTargetEntry : lhmFaceTarget.entrySet()) {
|
||||
boolean scoringTrovato;
|
||||
Long fsTargetMainKey = currentTargetEntry.getKey();
|
||||
JsonObject fsTargetMainJO = currentTargetEntry.getValue();
|
||||
i++;
|
||||
if (Evento.threadEventoScoringSTOP)
|
||||
break;
|
||||
l_id_fotoTarget = fsTargetMainJO.get("id_foto").getAsLong();
|
||||
lhmFaceQuery.remove(fsTargetMainKey);
|
||||
querySize = lhmFaceQuery.size();
|
||||
if (hsTargetTrovatiId.contains(fsTargetMainKey)) {
|
||||
DBAdapter.printDebug(debug, "currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " ......... SALTO TARGET!!!! " + fsTargetMainKey + " FACCIA SU FOTO " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString());
|
||||
continue;
|
||||
}
|
||||
hsTargetTrovatiId.add(fsTargetMainKey);
|
||||
DBAdapter.printDebug(debug, "currentFoto " + fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " ......... inizio scoring do while");
|
||||
l_id_currentFoto = 0L;
|
||||
do {
|
||||
fotoCount = 1L;
|
||||
scoringTrovato = false;
|
||||
JsonObject jsonData = new JsonObject();
|
||||
jsonData.addProperty("dis_type", Long.valueOf(dysType));
|
||||
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
|
||||
jsonData.add("target", (JsonElement)fsTargetMainJO);
|
||||
JsonArray jsonQuery = new JsonArray();
|
||||
LinkedHashMap<Long, JsonObject> lhmFaceQueryCopy = new LinkedHashMap<>(lhmFaceQuery);
|
||||
for (Map.Entry<Long, JsonObject> currentQueryEntry : lhmFaceQueryCopy.entrySet()) {
|
||||
if (Evento.threadEventoScoringSTOP)
|
||||
break;
|
||||
Long fsQueryMainKey = currentQueryEntry.getKey();
|
||||
JsonObject fsQueryMainJO = currentQueryEntry.getValue();
|
||||
l_id_fotoQuery = fsQueryMainJO.get("id_foto").getAsLong();
|
||||
if (l_id_fotoQuery == l_id_fotoTarget) {
|
||||
DBAdapter.printDebug(debug, "currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " ......... SALTO QUERY!!!! " + fsQueryMainKey + " FACCIA SU FOTO " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString());
|
||||
continue;
|
||||
}
|
||||
if (l_id_currentFoto > 0L && l_id_currentFoto != l_id_fotoQuery)
|
||||
fotoCount++;
|
||||
l_id_currentFoto = fsQueryMainJO.get("id_foto").getAsLong();
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey);
|
||||
if (numFotoNoScore == 0 || fotoCount <= (long)numFotoNoScore) {
|
||||
jsonQuery.add((JsonElement)fsQueryMainJO);
|
||||
continue;
|
||||
}
|
||||
fotoCount = 1L;
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey + " faccio scoring ...");
|
||||
if (jsonQuery.size() > 0) {
|
||||
numFotoScore = chiamaApiEElabora(targetDir, jsonData, jsonQuery, frApi, fs, scoreThresold, errMsg, lhmFaceQuery, hsTargetTrovatiId, maxNumberOfThread, NUM_QUERY_CALLABLE);
|
||||
totNumFotoScore += numFotoScore;
|
||||
scoringTrovato = (numFotoScore > 0L);
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey + " NO SCORING PERCHé NON HO TROVATO FACE NELLE NUMFOTONOSCORE SUCCESSIVE!! ");
|
||||
scoringTrovato = false;
|
||||
}
|
||||
DBAdapter.printDebug(debug, " foto count:" + fotoCount + " su " + numFotoNoScore + " currentFoto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face: " + fsTargetMainKey + " foto query: " +
|
||||
fsQueryMainJO.get("fileName").getAsString() + " face query: " + fsQueryMainKey + " scoring trovato: " + scoringTrovato);
|
||||
if (scoringTrovato) {
|
||||
jsonQuery = new JsonArray();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (scoringTrovato)
|
||||
if (jsonQuery.size() > 0) {
|
||||
StatusMsg.updateMsgByTag(getApFull(), this.TAG_THREAD_MSG, "Callable Punto foto " +
|
||||
this.puntofoto.getDescrizione() + " foto " +
|
||||
fsTargetMainJO.get("fileName").getAsString() + " face n. " + i + "/" +
|
||||
lhmFaceTarget.size() + " score trovati: " + totNumFotoScore + " query size: " + querySize + " current query size" +
|
||||
jsonQuery.size() + " " + eta);
|
||||
numFotoScore = chiamaApiEElabora(targetDir, jsonData, jsonQuery, frApi, fs, scoreThresold, errMsg, lhmFaceQuery, hsTargetTrovatiId, maxNumberOfThread, NUM_QUERY_CALLABLE);
|
||||
totNumFotoScore += numFotoScore;
|
||||
scoringTrovato = false;
|
||||
}
|
||||
if (l_id_curretFoto == 0L) {
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
} else if (l_id_curretFoto != l_id_fotoTarget) {
|
||||
Foto.updateCurrentFlgFaceScoringDone(l_id_curretFoto, 2L, foto);
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
}
|
||||
} while (scoringTrovato);
|
||||
if (l_id_curretFoto == 0L) {
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
} else if (l_id_curretFoto != l_id_fotoTarget) {
|
||||
Foto.updateCurrentFlgFaceScoringDone(l_id_curretFoto, 2L, foto);
|
||||
if (foto.getId_foto() > 0L) {
|
||||
this.puntofoto.setLastFotoFileScore1(foto.getFileName());
|
||||
this.puntofoto.save();
|
||||
}
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
}
|
||||
eta = timer.getEta((long)lhmFaceTarget.size(), (long)i);
|
||||
}
|
||||
StatusMsg.deleteMsgByTag(getApFull(), this.TAG_THREAD_MSG);
|
||||
rp.setReturnObj(this.puntofoto);
|
||||
return rp;
|
||||
}
|
||||
|
||||
private ApplParmFull getApFull() {
|
||||
return this.puntofoto.getApFull();
|
||||
}
|
||||
|
||||
private long chiamaApiEElabora(String targetDir, JsonObject jsonData, JsonArray jsonQuery, FaceRecognitionApi frApi, FaceScore fs, double scoreThresold, StringBuilder errMsg, LinkedHashMap<Long, JsonObject> lhpFaceQuery, HashSet<Long> hsTargetTrovatiId, int maxNumberOfThread, int NUM_QUERY_CALLABLE) {
|
||||
boolean debug = false;
|
||||
DBAdapter.printDebug(debug, " ===================== chiamaApiEElabora =====================");
|
||||
long numFotoScore = 0L;
|
||||
long totNumFotoScore = 0L;
|
||||
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThread);
|
||||
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
|
||||
int idxQuery = 0;
|
||||
JsonArray jsonQueryC = new JsonArray();
|
||||
for (int i = 0; i < jsonQuery.size(); i++) {
|
||||
JsonObject jsonQueryRow = jsonQuery.get(i).getAsJsonObject();
|
||||
if (idxQuery > 0 && idxQuery % NUM_QUERY_CALLABLE == 0) {
|
||||
JsonObject jsonDataCallable = jsonData.deepCopy();
|
||||
jsonDataCallable.add("query", (JsonElement)jsonQueryC);
|
||||
DBAdapter.printDebug(debug, " chiamaApiEElabora---> ScoringFaceCallableGson submit ");
|
||||
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, true);
|
||||
vecF.add(pool.submit(ifc));
|
||||
jsonQueryC = new JsonArray();
|
||||
}
|
||||
jsonQueryC.add((JsonElement)jsonQueryRow);
|
||||
idxQuery++;
|
||||
}
|
||||
if (jsonQueryC.size() > 0) {
|
||||
JsonObject jsonDataCallable = jsonData.deepCopy();
|
||||
jsonDataCallable.add("query", (JsonElement)jsonQueryC);
|
||||
DBAdapter.printDebug(debug, " chiamaApiEElabora---> ScoringFaceCallableGson submit ultima");
|
||||
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(this.evento, jsonDataCallable, targetDir, true);
|
||||
vecF.add(pool.submit(ifc));
|
||||
}
|
||||
try {
|
||||
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
|
||||
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
|
||||
ResParm rp = currentFuture.get();
|
||||
numFotoScore = elaboraAfterScoring(rp, errMsg, lhpFaceQuery, hsTargetTrovatiId);
|
||||
totNumFotoScore += numFotoScore;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
pool.shutdown();
|
||||
}
|
||||
return totNumFotoScore;
|
||||
}
|
||||
|
||||
private long elaboraAfterScoring(ResParm rp, StringBuilder errMsg, LinkedHashMap<Long, JsonObject> lhpFaceQuery, HashSet<Long> hsTargetTrovatiId) {
|
||||
boolean debug = false;
|
||||
long numFotoScore = 0L;
|
||||
if (!rp.getStatus()) {
|
||||
errMsg.append(rp.getErrMsg()).append("\n");
|
||||
if (debug)
|
||||
DBAdapter.printDebug(" ******************************** elaboraAfterScoring error: " + rp.getErrMsg());
|
||||
} else {
|
||||
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
|
||||
if (hsFs != null && !hsFs.isEmpty()) {
|
||||
DBAdapter.printDebug(" ******************************** elaboraAfterScoring fsTargetSul2. hsFs.size(): " + hsFs.size() + " rpmsg:" +
|
||||
rp.getMsg());
|
||||
for (FaceScore fsTargetSul2 : hsFs) {
|
||||
numFotoScore++;
|
||||
lhpFaceQuery.remove(Long.valueOf(fsTargetSul2.getId_fotoFace2()));
|
||||
hsTargetTrovatiId.add(Long.valueOf(fsTargetSul2.getId_fotoFace2()));
|
||||
DBAdapter.printDebug(debug, " ******************************** elaboraAfterScoring: NUOVA LSH SIZE: " +
|
||||
lhpFaceQuery.size() + " numfotoscore:" + numFotoScore);
|
||||
}
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, " ******************************** elaboraAfterScoring NESSUN RISULTATO!!: " + rp.getErrMsg());
|
||||
numFotoScore = 0L;
|
||||
}
|
||||
}
|
||||
DBAdapter.printDebug(" ******************************** elaboraAfterScoring numFotoScore: " + numFotoScore);
|
||||
return numFotoScore;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Evento;
|
||||
import it.acxent.face.FaceScore;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.face.api.FaceRecognitionApiResult;
|
||||
import it.acxent.util.FileWr;
|
||||
import java.util.concurrent.Callable;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@Deprecated
|
||||
public class ScoringFaceCallable implements Callable<ResParm> {
|
||||
private JSONObject jsonData;
|
||||
|
||||
private String targetDir;
|
||||
|
||||
private Evento evento;
|
||||
|
||||
private boolean saveFaceScore;
|
||||
|
||||
public ScoringFaceCallable(Evento evento, JSONObject jsonData, String targetDir, boolean saveFaceScore) {
|
||||
this.evento = evento;
|
||||
this.jsonData = jsonData;
|
||||
this.targetDir = targetDir;
|
||||
this.saveFaceScore = saveFaceScore;
|
||||
}
|
||||
|
||||
public ResParm call() throws Exception {
|
||||
ResParm rp = new ResParm();
|
||||
try {
|
||||
rp = scoring(this.evento, this.targetDir, this.jsonData, this.saveFaceScore);
|
||||
} catch (Exception e) {
|
||||
rp.setStatus(false);
|
||||
rp.setException(e);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public static ResParm scoring(Evento evento, String targetDir, JSONObject jsonData, boolean saveFaceScore) {
|
||||
boolean debug = false;
|
||||
ResParm rp = new ResParm(true);
|
||||
FaceRecognitionApi frApi = new FaceRecognitionApi(evento.getApFull());
|
||||
FaceScore fs = new FaceScore(evento.getApFull());
|
||||
DBAdapter.printDebug(debug, " ******************************** ScoringFaceCallable:scoring jsondata: " + jsonData.toString(4));
|
||||
String jsonDataFileName = targetDir + "jsonDataScoring_" + targetDir + ".json";
|
||||
String jsonResFileName = targetDir + "jsonDataScoring_" + targetDir + "_res.json";
|
||||
jsonData.put("debug", "ScoringFaceCallable.scoring");
|
||||
FileWr fw = new FileWr(jsonDataFileName);
|
||||
try {
|
||||
fw.writeLine(jsonData.toString(4));
|
||||
fw.closeFile();
|
||||
FaceRecognitionApiResult frar = frApi.__scoring(jsonDataFileName, jsonResFileName);
|
||||
if (frar.isOk()) {
|
||||
if (debug)
|
||||
System.out.println(
|
||||
String.valueOf(DBAdapter.getNowTs()) + " ******************************** ScoringFaceCallable:scoring json reponse: " + String.valueOf(DBAdapter.getNowTs()));
|
||||
rp = fs.elaboraScoringResult(frar.getJSONObjectResult(), evento, saveFaceScore);
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, " ******************************** ScoringFaceCallable:scoring KO: " + frar.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug(debug, " ******************************** ScoringFaceCallable:scoring ex: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Evento;
|
||||
import it.acxent.face.FaceScore;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.face.api.FaceRecognitionApiResult;
|
||||
import it.acxent.util.FileWr;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class ScoringFaceCallableGson implements Callable<ResParm> {
|
||||
private JsonObject jsonData;
|
||||
|
||||
private String targetDir;
|
||||
|
||||
private Evento evento;
|
||||
|
||||
private boolean saveFaceScore;
|
||||
|
||||
private String idx;
|
||||
|
||||
public ScoringFaceCallableGson(Evento evento, JsonObject jsonData, String targetDir, boolean saveFaceScore) {
|
||||
this.evento = evento;
|
||||
this.jsonData = jsonData;
|
||||
this.targetDir = targetDir;
|
||||
this.saveFaceScore = saveFaceScore;
|
||||
this.idx = DBAdapter.getNowTs().toString();
|
||||
}
|
||||
|
||||
public ResParm call() throws Exception {
|
||||
boolean debug = true;
|
||||
ResParm rp = new ResParm();
|
||||
try {
|
||||
DBAdapter.printDebug(debug, "call scoring idx: " + getIdx());
|
||||
rp = scoring(this.evento, this.targetDir, this.jsonData, this.saveFaceScore);
|
||||
} catch (Exception e) {
|
||||
rp.setStatus(false);
|
||||
rp.setException(e);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public static ResParm scoring(Evento evento, String targetDir, JsonObject jsonData, boolean saveFaceScore) {
|
||||
boolean debug = false;
|
||||
ResParm rp = new ResParm(true);
|
||||
String tag = DBAdapter.getTimeNameForFileUpload();
|
||||
FaceRecognitionApi frApi = new FaceRecognitionApi(evento.getApFull());
|
||||
FaceScore fs = new FaceScore(evento.getApFull());
|
||||
if (debug)
|
||||
DBAdapter.printDebug(tag + " ******************************** ScoringFaceCallable:scoring jsondata: " + tag);
|
||||
String jsonDataFileName = targetDir + "jsonDataScoring_" + targetDir + ".json";
|
||||
String jsonResFileName = targetDir + "jsonDataScoring_" + targetDir + "_res.json";
|
||||
jsonData.addProperty("debug", "ScoringFaceCallable.scoring");
|
||||
FileWr fw = new FileWr(jsonDataFileName, false);
|
||||
try {
|
||||
fw.writeLine(DBAdapter.gsonToString(jsonData));
|
||||
fw.closeFile();
|
||||
FaceRecognitionApiResult frar = frApi.__scoring(jsonDataFileName, jsonResFileName);
|
||||
if (frar.isOk()) {
|
||||
DBAdapter.printDebug(debug, " ******************************** ScoringFaceCallable:scoring json reponse: " +
|
||||
DBAdapter.gsonToString(frar.getJsonObjectResult()));
|
||||
rp = fs.elaboraScoringResultGson(frar.getJsonObjectResult(), evento, saveFaceScore);
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, " ******************************** ScoringFaceCallable:scoring KO: " + frar.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug(debug, " ******************************** ScoringFaceCallable:scoring ex: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public String getIdx() {
|
||||
return (this.idx == null) ? "" : this.idx.trim();
|
||||
}
|
||||
|
||||
public void setIdx(String idx) {
|
||||
this.idx = idx;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package it.acxent.face.callable;
|
||||
|
||||
import it.acxent.face.FotoFace;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.face.api.FaceRecognitionApiResult;
|
||||
import it.acxent.face.api.TrainingImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class TrainingSendTask implements Callable<FaceRecognitionApiResult> {
|
||||
private final FaceRecognitionApi frApi;
|
||||
|
||||
private final long faceRecognizerId;
|
||||
|
||||
private final List<TrainingImage> imageFilenames;
|
||||
|
||||
public TrainingSendTask(FaceRecognitionApi frApi, long faceRecognizerId, List<TrainingImage> imageFilenames) {
|
||||
this.frApi = frApi;
|
||||
this.faceRecognizerId = faceRecognizerId;
|
||||
this.imageFilenames = imageFilenames;
|
||||
}
|
||||
|
||||
public FaceRecognitionApiResult call() throws Exception {
|
||||
FaceRecognitionApiResult resF = this.frApi.__trainingSendImages(this.faceRecognizerId, this.imageFilenames, false);
|
||||
handleApiResponse(resF);
|
||||
if (resF.isOk() && resF.getResult() != null) {
|
||||
JSONObject jres = (JSONObject)resF.getResult();
|
||||
if (jres.has("noImg")) {
|
||||
List<TrainingImage> missingImages = new ArrayList<>();
|
||||
JSONArray jNoimgA = jres.getJSONArray("noImg");
|
||||
for (int k = 0; k < jNoimgA.length(); k++) {
|
||||
JSONObject jNoImgRow = jNoimgA.getJSONObject(k);
|
||||
FotoFace ff = new FotoFace(this.frApi.getApFull());
|
||||
ff.findByMd5(jNoImgRow.getString("md5"));
|
||||
if (ff.getId_fotoFace() > 0L)
|
||||
missingImages.add(new TrainingImage(ff.getFullFaceImgPath(), ff.getLabel(), ff.getMd5()));
|
||||
}
|
||||
if (!missingImages.isEmpty()) {
|
||||
FaceRecognitionApiResult missingResF = this.frApi.__trainingSendImages(this.faceRecognizerId, missingImages, true);
|
||||
handleApiResponse(missingResF);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resF;
|
||||
}
|
||||
|
||||
private void handleApiResponse(FaceRecognitionApiResult resF) {
|
||||
if (resF.isOk() && resF.getResult() != null) {
|
||||
JSONObject jres = (JSONObject)resF.getResult();
|
||||
if (jres.has("labels"))
|
||||
FotoFace.updateLabels(this.frApi.getApFull(), jres);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.callable;
|
||||
Loading…
Add table
Add a link
Reference in a new issue