Regalamiunsorriso/decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Foto.java

2052 lines
79 KiB
Java

package it.acxent.face;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifSubIFDDirectory;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import it.acxent.common.StatusMsg;
import it.acxent.db.ApplParm;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.dm.FaceDetectionMethod;
import it.acxent.face.api.FaceRecognitionApi;
import it.acxent.face.api.FaceRecognitionApiResult;
import it.acxent.face.pc.SaveScoreProcessor;
import it.acxent.util.FileWr;
import it.acxent.util.ImageConverter;
import it.acxent.util.ScaleImage;
import it.acxent.util.StringTokenizer;
import it.acxent.util.Timer;
import it.acxent.util.Vectumerator;
import it.acxent.videoj.ManageVideoJ;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.json.JSONArray;
import org.json.JSONObject;
public class Foto extends DBAdapter implements Serializable, FotoI {
public static final long FACE_DETECT_METHOD_H_DEFAULT = 0L;
public static final long FACE_DETECT_METHOD_H_ALT = 1L;
public static final long FACE_DETECT_METHOD_H_ALT2 = 2L;
public static final long FACE_DETECT_METHOD_H_ALT_TREE = 3L;
public static final long FACE_DETECT_METHOD_L_DEFAULT = 4L;
public static final long FACE_DETECT_METHOD_L_IMPROVED = 5L;
public static final long FACE_DETECT_METHOD_YUNET = 14L;
public static final long FACE_DETECT_METHOD_GOOGLE_VISION = 99L;
public static final long FACE_SCORING_DONE_NO_DETECT_0 = 0L;
public static final long FACE_SCORING_DONE_DETECT_OK_1 = 1L;
public static final long FACE_SCORING_DONE_NEAR_2 = 2L;
public static final long FACE_SCORING_DONE_GLOBAL_3 = 3L;
private static final long serialVersionUID = 1683972369916L;
class ThreadTrainig extends Thread {
private FotoCR CR;
public ThreadTrainig(FotoCR l_CR) {
this.CR = l_CR;
if (!Foto.isThreadTrainingRecognizing()) {
Foto.threadTrainingRecognizing = true;
start();
}
}
public void run() {
boolean debug = false;
String TAG_THREAD_MSG = "TRAINING " + this.CR.getEvento().getFaceRecognizer().getCodice();
try {
FotoFace ff = new FotoFace(Foto.this.getApFull());
ff.trainingByCR(this.CR, TAG_THREAD_MSG, true, true);
} catch (Exception e) {
Foto.this.handleDebug(e);
}
Foto.threadTrainingRecognizing = false;
}
}
class ThreadRecognizing extends Thread {
private FotoCR CR;
public ThreadRecognizing(FotoCR l_CR) {
this.CR = l_CR;
if (!Foto.isThreadTrainingRecognizing()) {
Foto.threadTrainingRecognizing = true;
start();
}
}
public void run() {
String TAG_THREAD_MSG = "RECOGNIZING " + this.CR.getFaceRecognizer().getCodice();
FotoFace ff = new FotoFace(Foto.this.getApFull());
ff.recognizeByCR(this.CR, TAG_THREAD_MSG, true);
Foto.threadTrainingRecognizing = false;
}
}
@Deprecated
class ThreadSelfieScoring extends Thread {
private FotoCR CR;
private FaceScoreTarget selfieOrFaceTarget;
public ThreadSelfieScoring(FaceScoreTarget l_selfie, FotoCR l_CR) {
this.CR = l_CR.getClone();
this.selfieOrFaceTarget = l_selfie;
if (!Foto.isThreadSelfieScoring()) {
Foto.threadSelfieScoring = true;
Foto.threadSelfieScoringSTOP = false;
start();
}
}
public void run() {
String targetType;
boolean debug = true;
this.CR.setFlgWithFaces(1L);
String TAG_THREAD_MSG = "SELFIE SCORING " + this.CR.getFaceRecognizer().getCodice();
Timer timer = new Timer();
long totFotoInviate = 0L;
long totImgTrovate = 0L;
timer.start();
ResParm rp = new ResParm(true);
int NUM_DIMENSIONE_PACCHETTO_FOTO_INVIATE = 12;
Foto foto = new Foto(Foto.this.getApFull());
int currentPage = 1;
long fotoCount = 0L;
long faceCount = 0L;
StringBuffer errMsg = new StringBuffer();
String targetDir = Foto.this.getParm("PATHFOTO_FACE").getTesto() + Foto.this.getParm("PATHFOTO_FACE").getTesto();
File targetDirFile = new File(targetDir);
if (!targetDirFile.exists())
targetDirFile.mkdirs();
FaceRecognitionApi frApi = new FaceRecognitionApi(Foto.this.getApFull());
FaceScore fs = new FaceScore(Foto.this.getApFull());
JSONObject jsonTarget = new JSONObject();
jsonTarget.put("path", this.selfieOrFaceTarget.getFacePath());
jsonTarget.put("md5", this.selfieOrFaceTarget.getMd5());
if (this.selfieOrFaceTarget.getId_fotoFace() > 0L) {
targetType = "face";
} else {
targetType = "selfie";
}
jsonTarget.put("type", targetType);
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "starting....");
Vectumerator<Foto> vecFoto;
while (!Foto.threadSelfieScoringSTOP && rp.getStatus() && (
vecFoto = foto.findByCR(this.CR, currentPage, NUM_DIMENSIONE_PACCHETTO_FOTO_INVIATE)).hasMoreElements()) {
JSONObject jsonData = new JSONObject();
double confDetectLevel = this.CR.getEvento().getDetectFaceConfidentThresold();
long dysType = Foto.this.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
jsonData.put("dis_type", dysType);
jsonData.put("conf_threshold", confDetectLevel);
jsonData.put("target", jsonTarget);
JSONArray jsonQuery = new JSONArray();
while (!Foto.threadSelfieScoringSTOP && vecFoto.hasMoreElements()) {
fotoCount++;
Foto rowFoto = (Foto)vecFoto.nextElement();
if (debug)
System.out.println(TAG_THREAD_MSG + "ciclo foto " + TAG_THREAD_MSG + " page " + rowFoto.getFileName() + "/" + currentPage + " foto n. " +
vecFoto.getTotNumberOfPages() + " face n. " + fotoCount + " " + faceCount);
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "ciclo foto " +
rowFoto.getFileName() + " page " + currentPage + "/" + vecFoto.getTotNumberOfPages() + " (" + NUM_DIMENSIONE_PACCHETTO_FOTO_INVIATE + ") foto n. " + fotoCount + " face n. " + faceCount + " " +
timer.getEta((long)vecFoto.getTotNumberOfPages(), (long)currentPage));
if (this.selfieOrFaceTarget.getId_fotoFace() > 0L) {
fs.findByFaceFoto(this.selfieOrFaceTarget.getId_fotoFace(), rowFoto.getId_foto());
} else {
fs.findBySelfieFoto(this.selfieOrFaceTarget.getId_selfie(), rowFoto.getId_foto());
}
if (fs.getId_faceScore() > 0L) {
if (debug)
System.out.println(TAG_THREAD_MSG + "ciclo foto " + TAG_THREAD_MSG + " page " + rowFoto.getFileName() + "/" + currentPage + " foto n. " +
vecFoto.getTotNumberOfPages() + " face n. " + fotoCount + " " + faceCount + " ------------> score trovato" +
timer.getEta((long)vecFoto.getTotNumberOfPages(), (long)currentPage));
continue;
}
JSONObject jsonQueryRow = new JSONObject();
jsonQueryRow.put("path", rowFoto.getFileNameFullPath());
jsonQueryRow.put("md5", rowFoto.getMd5());
jsonQueryRow.put("type", "photo");
jsonQuery.put(jsonQueryRow);
}
if (jsonQuery.length() > 0) {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "Scoring page " + currentPage + "/" +
vecFoto.getTotNumberOfPages() + " (" + NUM_DIMENSIONE_PACCHETTO_FOTO_INVIATE + ") foto n. " + fotoCount + " face n. " + faceCount + " ........ " +
timer.getEta((long)vecFoto.getTotNumberOfPages(), (long)currentPage));
jsonData.put("query", jsonQuery);
if (debug)
System.out.println(TAG_THREAD_MSG + "creato json data da inviare son data :\n" + TAG_THREAD_MSG);
String jsonDataFileName = targetDir + "jsonDataScoring_" + targetDir + ".json";
String jsonResFileName = targetDir + "jsonDataScoring_" + targetDir + "_res.json";
if (debug)
System.out.println(TAG_THREAD_MSG + "jsonDataFileName :" + TAG_THREAD_MSG);
try {
jsonData.put("debug", "Foto.threadselfiescoring");
FileWr fw = new FileWr(jsonDataFileName, false);
fw.writeLine(jsonData.toString(4));
fw.closeFile();
FaceRecognitionApiResult frar = frApi.__scoring(jsonDataFileName, jsonResFileName);
if (frar.isOk()) {
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "elaboro score " + currentPage + "/" +
vecFoto.getTotNumberOfPages() + " foto n. " + fotoCount + " face n. " + faceCount + " ........ " +
timer.getEta((long)vecFoto.getTotNumberOfPages(), (long)currentPage));
rp = fs.elaboraScoringResult(frar.getJSONObjectResult(), this.CR.getEvento(), true);
}
} catch (Exception e) {
Foto.this.handleDebug(e);
errMsg.append("\nScoring fallita <br>" + e.getMessage() + " page " + currentPage + "/" + currentPage);
Foto.threadSelfieScoringSTOP = true;
}
}
if (Foto.threadSelfieScoringSTOP) {
rp.setMsg("Trainig STOP MANUALE!.<br>Numero foto inviate:" + totFotoInviate + " totale immagini trovate : " + totImgTrovate + "<br> - Errori rilevati: " +
errMsg.toString());
} else {
rp.setMsg("Trainig completato.<br>Numero foto inviate:" + totFotoInviate + " totale immagini trovate : " + totImgTrovate + "<br> - Errori rilevati: " +
errMsg.toString());
}
rp.setStatus(true);
currentPage++;
}
SaveScoreProcessor ssProcessor = SaveScoreProcessor.getInstance(Foto.this.getApFull(), 10);
ssProcessor.shutdown();
timer.stop();
System.out.println(TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + " " + timer.getDurata());
StatusMsg.updateMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG, "Concluso: DURATA: " + timer.getDurata() + "\nRisultato: " + rp.getMsg());
try {
sleep(4000L);
} catch (Exception e) {}
StatusMsg.deleteMsgByTag(Foto.this.getApFull(), TAG_THREAD_MSG);
Foto.threadSelfieScoring = false;
}
}
private static boolean debug = false;
private long id_foto;
private String fileName;
private String pettorali;
private String fileNameMd5;
private String md5;
private Timestamp tsInserimento;
private long flgFotoSearch;
private Evento evento;
private long id_evento;
private long id_puntoFoto;
private PuntoFoto puntoFoto;
private Time tempo;
private long flgVideo;
private String fotoFaceRowid;
private long flgTrainingOk;
private long numOfFaces;
private long width;
private long height;
private long dimMinFotoFace;
private long flgFaceScoringDone;
private String labels;
private long flgIndexReady;
private transient Map<Long, FaceScore> selfieScoreCache = new HashMap<>();
private long id_fotoFace;
private FotoFace fotoFace;
private FaceDetectionMethod faceDetectionMethod;
private long id_faceDetectionMethod;
public static boolean threadSelfieScoring = false;
public static boolean threadSelfieScoringSTOP = false;
public static boolean threadTrainingRecognizing = false;
public static final String DIR_MP4_JPG = DBAdapter.SEPARATOR;
public Foto(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public long getTotFotoByPuntofoto(long l_id_puntofoto, boolean inviata) {
StringBuffer s_Sql_Find = new StringBuffer("select count(*) as _count from FOTO AS A");
WcString wc = new WcString();
wc.addWc("A.id_puntoFoto=" + l_id_puntofoto);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
return (long)getDoubleCol(stmt, "_count", true);
} catch (SQLException e) {
handleDebug(e);
return -1L;
}
}
public Foto() {}
public void setId_foto(long newId_foto) {
this.id_foto = newId_foto;
}
public void setFileName(String newFileName) {
this.fileName = newFileName;
}
public void setPettorali(String newPettorali) {
this.pettorali = newPettorali;
}
public void setFileNameMd5(String newFileNameMd5) {
this.fileNameMd5 = newFileNameMd5;
}
public void setMd5(String newMd5) {
this.md5 = newMd5;
}
public long getId_foto() {
return this.id_foto;
}
public String getFileName() {
return (this.fileName == null) ? "" : this.fileName.trim();
}
public String getPettorali() {
return (this.pettorali == null) ? "" : this.pettorali.trim();
}
public String getLabels() {
if (this.labels == null || this.labels.isEmpty()) {
Vectumerator<FotoFace> vec = getFotoFaces();
StringBuilder sb = new StringBuilder(",");
while (vec.hasMoreElements()) {
FotoFace row = (FotoFace)vec.nextElement();
if (row.getLabel() > 0L) {
sb.append(row.getLabel());
sb.append(",");
}
}
if (sb.length() > 1)
this.labels = sb.toString();
}
return (this.labels == null) ? "" : this.labels.trim();
}
public String getFileNameMd5() {
return (this.fileNameMd5 == null) ? "" : this.fileNameMd5.trim();
}
public String getMd5() {
return (this.md5 == null) ? "" : this.md5.trim();
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
protected void deleteCascade() {}
public static final ResParm loadFacesByFaceRecognition(FotoI foto, boolean detectNumbers, boolean force) {
boolean debug = false;
ResParm rp = new ResParm();
if (foto.getId_foto() == 0L || foto.getApFull() == null) {
rp.setStatus(false);
rp.setMsg("Errore! Foto non valida");
}
if (debug)
System.out.println("1-------------------- loadFacesByFaceRecognition ** ------------------------foto md5: " +
foto.getMd5());
if (!foto.hasFotoFaces() || force) {
if (debug)
System.out.println("loadFacesByFaceRecognition: " + foto.getId_foto() + " " + foto.getFileNameFaceRecognition());
String userFR = foto.getParm("FACE_RECOGNITION_API_USER").getTesto();
String pwdFR = foto.getParm("FACE_RECOGNITION_API_PWD").getTesto();
FaceRecognitionApi bean = new FaceRecognitionApi(foto.getApFull(), userFR, pwdFR);
if (debug)
System.out.println("2 loadFacesByFaceRecognition call api foto md5: " + foto.getMd5());
boolean usePath = foto.getApFull().getParm("FACE_DETECTION_USE_PATH").isTrue();
FaceRecognitionApiResult resF = bean.__detectFaces(foto.getFileNameFaceRecognition(), foto.getMd5(),
foto.getFaceDetectionMethodReal().getCodice(), detectNumbers, foto.getDetectFaceConfidentThresold(), usePath);
if (resF.isOk()) {
if (debug)
System.out.println("3 loadFacesByFaceRecognition ok... chiamo loadFacesByFaceRecognitionJson foto md5: " +
foto.getMd5());
foto.setId_faceDetectionMethod(foto.getFaceDetectionMethodReal().getId_faceDetectionMethod());
JsonObject resJO = (JsonObject)resF.getResult();
return loadFacesByFaceRecognitionJson(foto, resJO);
}
if (debug)
System.out.println("4 loadFacesByFaceRecognition KO foto md5: " + foto.getMd5());
rp.setStatus(false);
rp.setMsg(resF.getMsg() + " " + resF.getMsg());
return rp;
}
if (debug)
System.out.println("5 loadFacesByFaceRecognition solo ricalcolo.. che non faccio: " + foto.getId_foto() + " " +
foto.getFileNameFaceRecognition());
rp.setStatus(true);
rp.setMsg("Ricalcolo effettuato ");
return rp;
}
public static void main(String[] args) {
try {
String hostname = "localhost:3308";
String db = "fotoeventi4";
System.out.println("Db: " + db);
ApplParmFull apTarget = new ApplParmFull(new ApplParm(17, "//" + hostname + "/" + db, db, "root", "root", 1, 10, 300));
apTarget.setDebug(false);
Foto foto = new Foto(apTarget);
} catch (IOException e) {
e.printStackTrace();
}
}
public String getFileNameFaceRecognition() {
if (getEvento().getFrImageWidth() == 0L) {
updateIndexReady(1L);
return getFileNameFullPath();
}
int scaledWidth = (int)getEvento().getFrImageWidth();
String fileName = getPuntoFoto().getPathCompletoFoto() + "_" + getPuntoFoto().getPathCompletoFoto() + "W/" + scaledWidth;
if (!new File(fileName).exists()) {
ScaleImage si = new ScaleImage(getFileNameFullPath(), "_" + scaledWidth + "W/", 0L, scaledWidth, 0, false, false);
si.setAutoRotate(true);
ResParm rp = si.scaleIt();
if (!rp.getStatus())
fileName = getFileNameFullPath();
if (new File(fileName).exists()) {
updateIndexReady(1L);
} else {
updateIndexReady(0L);
}
}
return fileName;
}
public ResParm updateIndexReady(long l_flgIndexReady) {
if (getId_foto() <= 0L)
return new ResParm(true);
ResParm rp = update("update FOTO set flgIndexReady=" + this.flgIndexReady + " where id_foto=" + getId_foto());
if (rp.getStatus())
setFlgIndexReady(l_flgIndexReady);
return rp;
}
public String getFileNameFullPath() {
if (getFlgFotoSearch() == 1L)
return
DBAdapter.convertPathToCurrentFileSystemSeparator(getDocBase() + "_selfie/" + getDocBase() + DBAdapter.SEPARATOR);
return getPuntoFoto().getPathCompletoFoto() + getPuntoFoto().getPathCompletoFoto() + DBAdapter.SEPARATOR;
}
public ResParm _ricalcolaFotoFaces() {
ResParm rp = new ResParm();
StringBuilder sb = new StringBuilder();
FotoFace ff = new FotoFace(getApFull());
Vectumerator<FotoFace> vec = ff.findByFoto(getId_foto());
while (vec.hasMoreElements()) {
FotoFace row = (FotoFace)vec.nextElement();
rp = row.save();
if (!rp.getStatus()) {
sb.append(getFileName() + " " + getFileName());
sb.append("<br>");
}
}
rp.setMsg(sb.toString());
return rp;
}
public boolean hasFotoFaces() {
FotoFace ff = new FotoFace(getApFull());
Vectumerator<FotoFace> vec = ff.findByFoto(getId_foto());
return vec.hasMoreElements();
}
public Timestamp getTsInserimento() {
return this.tsInserimento;
}
public void setTsInserimento(Timestamp tsInserimento) {
this.tsInserimento = tsInserimento;
}
public long getFlgFotoSearch() {
return this.flgFotoSearch;
}
public void setFlgFotoSearch(long flgFotoSearch) {
this.flgFotoSearch = flgFotoSearch;
}
public void findByMd5(String l_md5) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.md5='" + l_md5 + "'");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
}
}
public FotoFace getFotoFaceFirst() {
if (getId_foto() > 0L && getApFull() != null) {
FotoFace ff = new FotoFace(getApFull());
ff.findFirstByFoto(getId_foto());
return ff;
}
return null;
}
public Vectumerator<FotoFace> getFotoFaces() {
if (getId_foto() > 0L && getApFull() != null) {
FotoFace ff = new FotoFace(getApFull());
return ff.findByFoto(getId_foto());
}
return null;
}
public ResParm elaboraFaceRecog(Vectumerator<Foto> vecFoto) {
ResParm rp = new ResParm();
if (getId_foto() > 0L) {
FotoFace ffSelfie = getFotoFaceFirst();
List<Double> fvSelfie = ffSelfie.getFetureVetctor1list();
int i = 0;
if (fvSelfie != null)
while (vecFoto.hasMoreElements()) {
Foto row = (Foto)vecFoto.nextElement();
if (row.getId_foto() == 5192210L)
println(row.getId_foto());
Vectumerator<FotoFace> vecFf = row.getFotoFaces();
if (vecFf != null)
while (vecFf.hasMoreElements()) {
i++;
FotoFace rowFf = (FotoFace)vecFf.nextElement();
if (rowFf.getFeatureVector1().isEmpty())
rowFf.save();
if (!rowFf.getFeatureVector1().isEmpty()) {
FaceRecog fr = new FaceRecog(getApFull());
fr.findByFotoFace1FotoFace2(ffSelfie.getId_fotoFace(), rowFf.getId_fotoFace());
fr.setId_fotoFace1(ffSelfie.getId_fotoFace());
fr.setId_fotoFace2(rowFf.getId_fotoFace());
List<Double> fvFF = rowFf.getFetureVetctor1list();
fr.setEDistance(FotoFace.calculateEuclideanDistance(fvSelfie, fvFF));
fr.setCosineSim(FotoFace.calculateDotProduct(fvSelfie, fvFF));
System.out.println("" + i + " ed: " + i + " cd: " + fr.getEDistance());
if (i == 129)
System.out.println("" + i + " stop!");
rp = fr.save();
continue;
}
System.out.println("" + i + " fotoface " + i + " foto " + rowFf.getId_fotoFace() + " nome: " + rowFf.getId_foto() + " senza fv");
}
}
}
return rp;
}
public Evento getEvento() {
this.evento = (Evento)getSecondaryObject(this.evento, Evento.class, getId_evento());
return this.evento;
}
public Vectumerator<FotoFace> findFotoFace() {
FotoFace ff = new FotoFace(getApFull());
return ff.findByFoto(getId_foto());
}
public void setEvento(Evento evento) {
this.evento = evento;
}
public long getId_evento() {
return this.id_evento;
}
public void setId_evento(long id_evento) {
this.id_evento = id_evento;
setEvento(null);
}
public long getNextId_foto(FotoCR CR) {
long l_id_foto = getId_foto();
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = " order by A.fileName ";
WcString wc = new WcString();
if (CR.getId_evento() != 0L)
wc.addWc("A.id_evento=" + CR.getId_evento());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
wc.addWc("A.fileName >'" + getFileName() + "'");
if (!CR.getFileName().isEmpty())
wc.addWc("A.fileName like '%" + CR.getFileName() + "%'");
if (!CR.getPettorale().isEmpty())
wc.addWc("A.pettorali like '%," + CR.getPettorale() + ",%'");
if (CR.getFlgIndicizzate() == 0L) {
wc.addWc("(A.pettorali is null or length(A.pettorali)=0)");
} else if (CR.getFlgIndicizzate() == 1L) {
wc.addWc("(A.pettorali is not null or length(A.pettorali)>0)");
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
Vectumerator<Foto> vec = findRows(stmt, 1, 1);
if (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
l_id_foto = row.getId_foto();
}
} catch (SQLException e) {
handleDebug(e);
}
return l_id_foto;
}
public long getPrevId_foto(FotoCR CR) {
long l_id_foto = getId_foto();
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = " order by A.fileName desc";
WcString wc = new WcString();
if (CR.getId_evento() != 0L)
wc.addWc("A.id_evento=" + CR.getId_evento());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
wc.addWc("A.fileName <'" + getFileName() + "'");
if (!CR.getFileName().isEmpty())
wc.addWc("A.fileName like '%" + CR.getFileName() + "%'");
if (!CR.getPettorale().isEmpty())
wc.addWc("A.pettorali like '%," + CR.getPettorale() + ",%'");
if (CR.getFlgIndicizzate() == 0L) {
wc.addWc("(A.pettorali is null or length(A.pettorali)=0)");
} else if (CR.getFlgIndicizzate() == 1L) {
wc.addWc("(A.pettorali is not null or length(A.pettorali)>0)");
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
Vectumerator<Foto> vec = findRows(stmt, 1, 1);
if (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
l_id_foto = row.getId_foto();
}
} catch (SQLException e) {
handleDebug(e);
}
return l_id_foto;
}
public boolean hasPuntoFotoFoto(long l_id_puntofoto) {
StringBuffer s_Sql_Find = new StringBuffer("select A.* from FOTO AS A");
WcString wc = new WcString();
wc.addWc("A.id_puntoFoto=" + l_id_puntofoto);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
Vectumerator vec = findRows(stmt, 1, 1);
if (vec.getTotNumberOfRecords() > 0)
return true;
return false;
} catch (SQLException e) {
handleDebug(e);
return false;
}
}
public long getId_puntoFoto() {
return this.id_puntoFoto;
}
public PuntoFoto getPuntoFoto() {
this.puntoFoto = (PuntoFoto)getSecondaryObject(this.puntoFoto, PuntoFoto.class, getId_puntoFoto());
return this.puntoFoto;
}
public void setId_puntoFoto(long id_puntoFoto) {
this.id_puntoFoto = id_puntoFoto;
setPuntoFoto(null);
}
public void setPuntoFoto(PuntoFoto newPuntoFoto) {
this.puntoFoto = newPuntoFoto;
}
public ResParm deleteFotoByPuntoFoto(long l_id_puntoFoto) {
ResParm rp = delete("DELETE FROM FOTO_FACE AS A where id_foto in (select id_foto from FOTO WHERE id_puntoFoto=" + l_id_puntoFoto + ")");
if (rp.getStatus())
return delete("delete from FOTO where id_puntoFoto=" + l_id_puntoFoto);
return rp;
}
public void findByFilenamePuntoFoto(String l_filename, long l_id_puntoFoto) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.filename='" + l_filename + "'");
wc.addWc("A.id_puntoFoto=" + l_id_puntoFoto);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findByFilenameEvento(String l_filename, long l_id_evento) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.filename='" + l_filename + "'");
wc.addWc("A.id_evento=" + l_id_evento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public static final synchronized ResParm syncAggiornaPettorale_2(Foto bean, String l_pettorali) {
String temp = l_pettorali.trim();
if (!temp.isEmpty()) {
if (!temp.startsWith(","))
temp = "," + temp;
if (!temp.endsWith(","))
temp = temp + ",";
while (temp.indexOf(",,") >= 0)
temp = temp.replaceAll(",,", ",");
}
String s_sql = "update FOTO SET pettorali='" + temp + "' where id_foto=" + bean.getId_foto();
ResParm rp = bean.update(s_sql);
if (rp.getStatus())
bean.setPettorali(temp);
return rp;
}
public Time getTempo() {
return this.tempo;
}
public void setTempo(Time newTempo) {
this.tempo = newTempo;
}
public long getFlgVideo() {
return this.flgVideo;
}
public void setFlgVideo(long flgVideo) {
this.flgVideo = flgVideo;
}
public Vectumerator<Foto> findByPuntofoto(long l_id_puntofoto) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = " ";
WcString wc = new WcString();
wc.addWc("A.id_puntofoto=" + l_id_puntofoto);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt);
} catch (SQLException e) {
return AB_EMPTY_VECTUMERATOR;
}
}
public boolean isPuntoFotoInviata(long l_id_puntofoto, boolean inviata) {
StringBuffer s_Sql_Find = new StringBuffer("select A.* from FOTO AS A");
WcString wc = new WcString();
wc.addWc("A.id_puntoFoto=" + l_id_puntofoto);
if (inviata) {
wc.addWc("(A.flgFotoInviata is null or A.flgFotoInviata=0)");
} else {
wc.addWc("A.flgFotoInviata =1");
}
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
Vectumerator vec = findRows(stmt, 1, 1);
if (vec.getTotNumberOfRecords() > 0)
return false;
return true;
} catch (SQLException e) {
handleDebug(e);
return false;
}
}
public Vectumerator<FaceRecog> findFaceRecogBySelfie(FotoI selfie) {
if (getId_foto() > 0L && selfie != null && selfie.getId_foto() > 0L) {
FaceRecog fr = new FaceRecog(getApFull());
return fr.findByFoto1Foto2(selfie.getId_foto(), getId_foto());
}
return AB_EMPTY_VECTUMERATOR;
}
public String getFileNameReale() {
if (getFileNameMd5().isEmpty())
return getFileName();
return getFileNameMd5();
}
public Vectumerator<Foto> findByCR(FotoCR CR, int pageNumber, int pageRows) {
if (!CR.getMd5FotoFace().isEmpty())
return findByScoreMd5(CR, pageNumber, pageRows);
boolean flgOttimizzo = true;
if (pageNumber == 0 && pageRows == 0)
flgOttimizzo = false;
StringBuffer s_Sql_Find = new StringBuffer("select A.* from FOTO AS A");
StringBuffer s_Sql_Order = new StringBuffer(" order by A.fileName ");
if (CR.getLabel() >= 0L || CR.getLabelSearch() >= 0L || CR.getFlgTrainingOk() >= 0L || CR.getFlgLabelPrincipale() >= 0L)
s_Sql_Order = new StringBuffer(" order by A.fileName,FF.faceTopVx, FF.id_fotoFace");
if (CR.getFlgOrderBy() == 9L) {
CR.setFlgFotoOrFace(1L);
s_Sql_Order = new StringBuffer(" order by FF.confidenceLBPH desc ");
}
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
if (CR.getLabel() >= 0L)
DBAdapter.printDebug(debug, " foto.findByCR con label: " + String.valueOf(s_Sql_Find) + wc.toString() + String.valueOf(s_Sql_Order));
try {
PreparedStatement stmt;
int start = -1;
int stop = -1;
if (pageNumber <= 0 || pageRows <= 0 || !flgOttimizzo) {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
} else {
if (pageNumber == 0)
pageNumber = 1;
start = (pageNumber - 1) * pageRows;
stop = start + pageRows;
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString() + " limit " + String.valueOf(s_Sql_Order) + "," + start);
}
if (!CR.getFileNameFrom().isEmpty())
System.out.println("find getFileNameFrom: " + String.valueOf(s_Sql_Find) + wc.toString() + String.valueOf(s_Sql_Order) + " limit " + start + "," + stop);
Vectumerator<Foto> vec = findRows(stmt, 1, pageRows);
vec.setPageNumber(pageNumber);
vec.setTotNumberOfRecords(findByCRTotRecord(CR));
return vec;
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
protected void findByCRCreateWC(FotoCR CR, StringBuffer s_Sql_Find, WcString wc) {
if (CR.getMd5FotoFace().isEmpty()) {
if (CR.getFlgFotoOrFace() == 1L || CR.getLabel() >= 0L || !CR.getPettorale().isEmpty() ||
CR.getLabelSearch() >= 0L || CR.getFlgTrainingOk() >= 0L || CR.getFlgLabelPrincipale() >= 0L ||
CR.getFlgTrainingInviate() >= 0L || CR.getFlgLabel0() >= 0L || CR.getConfidence() > 0.0D)
if (s_Sql_Find.indexOf("count") > 0) {
s_Sql_Find.replace(0, s_Sql_Find.length(), "select count(A.id_foto) as tot from FOTO AS A inner join FOTO_FACE AS FF ON A.id_foto=FF.id_foto");
} else {
s_Sql_Find.replace(0, s_Sql_Find.length(), "select A.*, FF.id_fotoFace as id_fotoFace from FOTO AS A inner join FOTO_FACE AS FF ON A.id_foto=FF.id_foto");
}
} else {
s_Sql_Find = new StringBuffer("select A.* from FOTO AS A inner join FOTO_FACE AS FF ON A.id_foto=FF.id_foto inner join FACE_SCORE AS FS ON ");
}
if (CR.getId_foto() != 0L)
wc.addWc("A.id_foto=" + CR.getId_foto());
if (!CR.getMd5FotoFace().isEmpty())
wc.addWc("FF.md5 = '" + CR.getMd5FotoFace() + "'");
if (CR.getId_evento() != 0L)
wc.addWc("A.id_evento=" + CR.getId_evento());
if (CR.getId_fotoS() != 0L)
wc.addWc("A.id_foto=" + CR.getId_fotoS());
if (CR.getFlgConPettorali() == 1L)
wc.addWc("A.pettorali is not null");
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
if (!CR.getFileName().isEmpty())
wc.addWc("A.fileName like '%" + CR.getFileName() + "%'");
if (CR.getFlgWithFaces() == 0L) {
wc.addWc("(A.numOfFaces IS NULL OR A.numOfFaces=0)");
} else if (CR.getFlgWithFaces() == 1L) {
wc.addWc("A.numOfFaces>0");
}
if (CR.getFlgFaceScoringDone() == 0L) {
wc.addWc("(A.flgFaceScoringDone is null or A.flgFaceScoringDone=0)");
} else if (CR.getFlgFaceScoringDone() == 1L) {
wc.addWc("A.flgFaceScoringDone=1");
}
if (!CR.getFileNameFrom().isEmpty())
wc.addWc("A.fileName>'" + CR.getFileNameFrom() + "'");
if (CR.getFlgIndicizzate() == 0L) {
wc.addWc("(A.pettorali is null or length(A.pettorali)=0)");
} else if (CR.getFlgIndicizzate() == 1L) {
wc.addWc("(A.pettorali is not null or length(A.pettorali)>0)");
}
if (CR.getFlgVideo() == 0L) {
wc.addWc("(A.flgVideo is null or A.flgVideo=0)");
} else if (CR.getFlgVideo() == 1L) {
wc.addWc("A.flgVideo=1");
}
if (!CR.getPettorale().isEmpty())
wc.addWc("FF.pettorale ='" + CR.getPettorale() + "'");
if (CR.getConfidence() > 0.0D)
wc.addWc("FF.confidence >=" + CR.getConfidence());
if (CR.getLabel() == 0L) {
wc.addWc("(FF.label is null or FF.label=0)");
} else if (CR.getLabel() > 0L) {
wc.addWc("FF.label =" + CR.getLabel());
}
if (CR.getLabelSearch() == 0L) {
wc.addWc("(FF.label is null or FF.label=0)");
} else if (CR.getLabelSearch() > 0L) {
wc.addWc("FF.label =" + CR.getLabelSearch());
}
if (CR.getFlgLabel0() == 0L) {
wc.addWc("FF.label is not null ");
} else if (CR.getFlgLabel0() == 1L) {
wc.addWc("(FF.label is null or FF.label='')");
}
if (CR.getFlgTrainingOk() == 0L) {
wc.addWc("(FF.flgTrainingOk is null or FF.flgTrainingOk=0)");
} else if (CR.getFlgTrainingOk() == 1L) {
wc.addWc("FF.flgTrainingOk=1");
}
if (CR.getFlgTrainingInviate() == 0L) {
wc.addWc("FF.tsTrainingFaceInviata is null ");
} else if (CR.getFlgTrainingInviate() == 1L) {
wc.addWc("FF.tsTrainingFaceInviata is not null");
}
if (CR.getFlgLabelPrincipale() == 0L) {
wc.addWc("(FF.md5<>FF.labelMd5)");
} else if (CR.getFlgLabelPrincipale() == 1L) {
wc.addWc("FF.md5=FF.labelMd5");
}
if (CR.getFlgHasFace() == 0L) {
wc.addWc("(A.numOfFaces is null or A.numOfFaces=0)");
} else if (CR.getFlgHasFace() == 1L) {
wc.addWc("A.numOfFaces>0");
}
if (!CR.getElencoFoto().isEmpty()) {
StringTokenizer st = new StringTokenizer(CR.getElencoFoto(), ",");
StringBuilder wcor = new StringBuilder("(");
while (st.hasMoreTokens()) {
String currentfoto = st.nextToken().trim();
wcor.append("A.fileName='" + currentfoto + "'");
if (st.hasMoreTokens())
wcor.append(" or ");
}
wcor.append(")");
wc.addWc(wcor.toString());
}
}
@Deprecated
public Vectumerator<Foto> findByCRFotoSelfieByLandmark(FotoCR CR, int pageNumber, int pageRows) {
if (CR.getFotoSelfie() == null)
return findByCR(CR, pageNumber, pageRows);
String s_Sql_Find1 = "select C.cosineSim , A.* from FOTO AS A inner join FOTO_FACE AS B ON A.id_foto=B.id_foto inner join FACE_RECOG AS C ON C.id_fotoFace2 = B.id_fotoFace inner join FOTO_FACE AS S ON S.id_fotoFace=C.id_fotoFace1";
String s_Sql_Find2 = "select C.cosineSim ,A.* from FOTO AS A inner join FOTO_FACE AS B ON A.id_foto=B.id_foto inner join FACE_RECOG AS C ON C.id_fotoFace2 = B.id_fotoFace";
String s_Sql_Order = " order by C.cosineSim DESC ";
if ((pageNumber == 0 && pageRows == 0) || pageRows == 999)
s_Sql_Order = " order by rand() ";
WcString wc = new WcString();
if (CR.getId_evento() != 0L)
wc.addWc("A.id_evento=" + CR.getId_evento());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
if (!CR.getFileName().isEmpty())
wc.addWc("A.fileName like '%" + CR.getFileName() + "%'");
String l_pettorale = "";
if (!CR.getPettorale().isEmpty())
l_pettorale = CR.getPettorale();
if (!l_pettorale.isEmpty())
wc.addWc("A.pettorali like'%," + l_pettorale + ",%'");
if (CR.getFlgVideo() == 0L) {
wc.addWc("(A.flgVideo is null or A.flgVideo=0)");
} else if (CR.getFlgVideo() == 1L) {
wc.addWc("A.flgVideo=1");
}
wc.addWc("S.id_foto=" + CR.getFotoSelfie().getId_foto());
double csim = CR.getPercIdx1() / 100.0D;
wc.addWc("C.cosineSim>=" + csim);
System.out.println(s_Sql_Find1 + s_Sql_Find1 + wc.toString());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find1 + s_Sql_Find1 + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<Foto> findByCRSelfie(FotoCR CR, int pageNumber, int pageRows) {
boolean debug = false;
long label = CR.getSelfie().getLabel();
ResParm rp = new ResParm(true);
if (label == 0L)
if (debug) {
label = 55L;
} else {
CR.getSelfie().recognize(CR.getFaceRecognizer());
label = CR.getSelfie().getLabel();
}
if (label == 0L) {
System.out.println("ERRORE.. recognize fallito... : " + rp.getMsg());
return AB_EMPTY_VECTUMERATOR;
}
StringBuffer s_Sql_Find = new StringBuffer("select distinct A.* from FOTO AS A");
StringBuffer s_Sql_Order = new StringBuffer(" order by A.fileName ");
WcString wc = new WcString();
if (CR.getId_evento() != 0L)
wc.addWc("A.id_evento=" + CR.getId_evento());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
if (!CR.getFileName().isEmpty())
wc.addWc("A.fileName like '%" + CR.getFileName() + "%'");
String l_pettorale = "";
if (!CR.getPettorale().isEmpty())
l_pettorale = CR.getPettorale();
if (!l_pettorale.isEmpty())
wc.addWc("A.pettorali like'%," + l_pettorale + ",%'");
if (CR.getFlgVideo() == 0L) {
wc.addWc("(A.flgVideo is null or A.flgVideo=0)");
} else if (CR.getFlgVideo() == 1L) {
wc.addWc("A.flgVideo=1");
}
if (label > 0L) {
s_Sql_Find.append(" inner join FOTO_FACE as B on A.id_foto=B.id_foto");
wc.addWc("B.label=" + label);
}
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<Foto> findByScoreMd5(FotoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select X.* from FOTO as X inner join FOTO_FACE AS FF ON X.id_foto=FF.id_foto where FF.id_fotoFace in (";
String s_Sql_Find_In1 = "select A.id_fotoFace2 from FACE_SCORE AS A INNER JOIN FOTO_FACE AS B ON A.id_fotoFace=B.id_fotoFace";
String s_Sql_Find_In2 = "select distinct A.id_fotoFace from FACE_SCORE AS A INNER JOIN FOTO_FACE AS B ON A.id_fotoFace=B.id_fotoFace";
String s_Sql_Order = " order by X.nomeFile ";
WcString wc = new WcString();
if (!CR.getMd5FotoFace().isEmpty()) {
FaceScore fs = new FaceScore(getApFull());
String l_realMd5 = fs.getTargetMd5ByMd5(CR.getMd5FotoFace());
wc.addWc("B.md5='" + l_realMd5 + "'");
}
if (CR.getId_puntoFoto() != 0L)
wc.addWc("X.id_puntoFoto=" + CR.getId_puntoFoto());
if (!CR.getFileName().isEmpty())
wc.addWc("X.fileName like '%" + CR.getFileName() + "%'");
String s_Sql = s_Sql_Find + s_Sql_Find + s_Sql_Find_In1 + ") union " + wc.toString() + s_Sql_Find + s_Sql_Find_In2 + ")";
System.out.println("findByScoreMd5:\n" + s_Sql);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
protected int findByCRTotRecord(FotoCR CR) {
StringBuffer s_Sql_Find = new StringBuffer("select count(A.id_foto) as tot from FOTO AS A");
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
return (int)getTots(stmt);
} catch (Exception e) {
handleDebug(e);
return 0;
}
}
public Vectumerator<Foto> findByPettoraliCR(FotoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = " order by A.fileName ";
if ((pageNumber == 0 && pageRows == 0) || pageRows == 999)
s_Sql_Order = " order by rand() ";
WcString wc = new WcString();
if (CR.getId_puntoFoto() == 0L) {
s_Sql_Find = s_Sql_Find + ", PUNTO_FOTO AS B";
wc.addWc("A.id_puntoFoto=B.id_puntoFoto");
}
if (CR.getId_evento() != 0L)
wc.addWc("A.id_evento=" + CR.getId_evento());
if (CR.getId_puntoFoto() != 0L)
wc.addWc("A.id_puntoFoto=" + CR.getId_puntoFoto());
if (!CR.getFileName().isEmpty())
wc.addWc("A.fileName like '%" + CR.getFileName() + "%'");
String l_pettorale = "";
if (!CR.getPettorale().isEmpty())
l_pettorale = CR.getPettorale();
if (!l_pettorale.isEmpty())
wc.addWc("A.pettorali like'%," + l_pettorale + ",%'");
if (CR.getFlgVideo() == 0L) {
wc.addWc("(A.flgVideo is null or A.flgVideo=0)");
} else if (CR.getFlgVideo() == 1L) {
wc.addWc("A.flgVideo=1");
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public String getFotoFaceRowid() {
return (this.fotoFaceRowid == null) ? "" : this.fotoFaceRowid.trim();
}
public void setFotoFaceRowid(String fotoFaceRowid) {
this.fotoFaceRowid = fotoFaceRowid;
}
public ResParm _ricalcolaFotoFacesSelfie() {
ResParm rp = new ResParm();
Vectumerator<Foto> vec = findSelfies(0L);
StringBuilder sb = new StringBuilder("N. Tot Selfie:" + vec.getTotNumberOfRecords() + "<br>");
while (vec.hasMoreElements()) {
Foto row = (Foto)vec.nextElement();
Foto foto = new Foto(getApFull());
foto.setId_foto(row.getId_foto());
rp = foto._ricalcolaFotoFaces();
if (!rp.getMsg().isEmpty())
sb.append(rp.getMsg());
}
rp.setMsg(sb.toString());
return rp;
}
public Vectumerator<Foto> findSelfies(long ggGreaterThan) {
String s_Sql_Find = "select A.* from FOTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.flgFotoSearch=1");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public ResParm updatePettoraliByFotoFace(boolean save) {
ResParm rp = new ResParm();
if (getId_foto() > 0L) {
FotoFace ff = new FotoFace(getApFull());
Vectumerator<FotoFace> vec = ff.findByFotoConPettorale(getId_foto());
if (vec.hasMoreElements()) {
StringBuilder sb = new StringBuilder(",");
while (vec.hasMoreElements()) {
FotoFace row = (FotoFace)vec.nextElement();
sb.append(row.getPettorale());
sb.append(",");
}
setPettorali(sb.toString().replaceAll(",,", ","));
} else {
setPettorali("");
}
if (save)
rp = save();
}
return rp;
}
protected void fillFields(ResultSet rst) {
super.fillFields(rst);
this.selfieScoreCache = null;
try {
if (isColumnInResultSet(rst, "id_fotoFace"))
setId_fotoFace(rst.getLong("id_fotoFace"));
} catch (Exception e) {
e.printStackTrace();
}
}
public ResParm save() {
if (getMd5().isEmpty())
setMd5(DBAdapter.getFileMd5(getFileNameFaceRecognition()));
setNumOfFaces(getTotFotoFaces());
if (getNumOfFaces() == 0L)
setFlgTrainingOk(0L);
if (getPettorali().isEmpty())
updatePettoraliByFotoFace(false);
ResParm rp = super.save();
if (rp.getStatus());
return rp;
}
protected void initFields() {
super.initFields();
setId_fotoFace(0L);
this.selfieScoreCache = null;
}
private long getTotFotoFaces() {
FotoFace ff = new FotoFace(getApFull());
Vectumerator<FotoFace> vec = ff.findByFoto(getId_foto());
return (long)vec.getTotNumberOfRecords();
}
protected static final ResParm loadFacesByFaceRecognitionJson(FotoI foto, JsonObject jo) {
ResParm rp = new ResParm();
boolean debug = false;
if (debug)
DBAdapter.printDebug(debug, "1-------------------- loadFacesByFaceRecognitionJson ------------------------foto md5: " +
foto.getMd5());
long minDimFoto = foto.getDimMinFotoFaceReal();
long marginTop = foto.getMargineFotoTop(), marginBottom = foto.getMargineFotoBottom(), marginLeft = foto.getMargineFotoSx();
long marginRight = foto.getMargineFotoDx();
long topY = 0L, bottomY = Long.MAX_VALUE, leftX = 0L, rightX = Long.MAX_VALUE;
if (marginTop != 0L || marginBottom != 0L || marginLeft != 0L || marginRight != 0L) {
topY = marginTop;
bottomY = foto.getHeight() - marginBottom;
leftX = marginLeft;
rightX = foto.getWidth() - marginRight;
}
try {
if (foto.getId_foto() == 0L || foto.getApFull() == null) {
rp.setStatus(false);
rp.setMsg("Errore! Foto non valida....");
}
StringBuilder msg = new StringBuilder();
int numOfNUmbers = 0, numOfFaces = 0, numOfSmallFaces = 0;
long totFaces = 0L;
FotoFace ff = new FotoFace(foto.getApFull());
ff.deleteFotoFaceByFoto(foto.getId_foto(), true);
JsonArray jaResponses = jo.getAsJsonArray("responses");
boolean visiTrovati = false;
if (jaResponses.size() > 0) {
JsonObject joResponse = jaResponses.get(0).getAsJsonObject().getAsJsonObject("response");
String md5Response = joResponse.get("md5").getAsString().trim();
if (md5Response.equals(foto.getMd5())) {
if (debug)
DBAdapter.printDebug(debug, "2 foto md5: " + foto.getMd5() + " joResponse:\n" + joResponse.toString());
HashMap<Long, Long> hmNumbers = new HashMap<>();
HashMap<Long, Long> hmNumbersY = new HashMap<>();
if (joResponse.has("numbers")) {
JsonArray jaNumbers = joResponse.getAsJsonArray("numbers");
for (int j = 0; j < jaNumbers.size(); j++) {
JsonObject joNumber = jaNumbers.get(j).getAsJsonObject();
if (!joNumber.get("value").getAsString().isEmpty()) {
hmNumbers.put(Long.valueOf(joNumber.get("xCenter").getAsLong()),
Long.valueOf(joNumber.get("value").getAsLong()));
hmNumbersY.put(Long.valueOf(joNumber.get("value").getAsLong()),
Long.valueOf(joNumber.get("yCenter").getAsLong()));
}
}
}
numOfNUmbers = hmNumbers.size();
if (joResponse.has("faceAnnotations")) {
visiTrovati = true;
JsonArray jaFaceAnnotations = joResponse.getAsJsonArray("faceAnnotations");
numOfFaces = jaFaceAnnotations.size();
for (int j = 0; j < jaFaceAnnotations.size(); j++) {
JsonObject joFaceAnnotation = jaFaceAnnotations.get(j).getAsJsonObject();
JsonObject joFace = new JsonObject();
JsonObject joFdBoundingPoly = joFaceAnnotation.getAsJsonObject("fdBoundingPoly");
joFace.add("fdBoundingPoly", (JsonElement)joFdBoundingPoly);
JsonArray jaVertices = joFdBoundingPoly.getAsJsonArray("vertices");
JsonObject joTopLeft = jaVertices.get(0).getAsJsonObject();
JsonObject joBottomRigth = jaVertices.get(2).getAsJsonObject();
boolean noDetect = false;
long faceBottomVx = 0L, faceBottomVy = 0L, faceTopVx = 0L, faceTopVy = 0L;
if (joBottomRigth.has("x")) {
faceBottomVx = joBottomRigth.get("x").getAsLong();
faceBottomVy = joBottomRigth.get("y").getAsLong();
} else {
noDetect = true;
}
if (joTopLeft.has("x")) {
faceTopVx = joTopLeft.get("x").getAsLong();
faceTopVy = joTopLeft.get("y").getAsLong();
} else {
noDetect = true;
}
if (!noDetect && faceTopVy > topY && faceTopVx > leftX && faceBottomVy < bottomY && faceBottomVx < rightX) {
DBAdapter.printDebug(debug, "3 foto md5: " +
foto.getMd5() + " salvo vertici : joface\n" + joFace.toString());
ff = new FotoFace(foto.getApFull());
ff.setId_foto(foto.getId_foto());
ff.setFaceBottomVx(faceBottomVx);
ff.setFaceBottomVy(faceBottomVy);
ff.setFaceTopVx(faceTopVx);
ff.setFaceTopVy(faceTopVy);
long latoX = faceBottomVx - faceTopVx;
if (latoX >= minDimFoto) {
ff.setJsonData(joFace.toString());
long sogliaW = latoX;
long sogliaH = faceBottomVy - faceTopVy;
long faceXCenter = faceTopVx + sogliaW / 2L;
long faceYCenter = faceTopVx + sogliaH / 2L;
for (Map.Entry<Long, Long> entry : hmNumbers.entrySet()) {
DBAdapter.printDebug(debug, "4 foto md5: " + foto.getMd5() + " Key : " + String.valueOf(entry.getKey()) + " Value : " +
String.valueOf(entry.getValue()));
if (Math.abs(entry.getKey() - faceXCenter) < sogliaW && faceYCenter >
hmNumbersY.get(entry.getValue())) {
ff.setPettorale(entry.getValue().toString());
hmNumbers.remove(entry.getKey());
break;
}
}
DBAdapter.printDebug(debug, "5 salvo fotoface:\n" + ff.getDescRecord() + "\n-------------5");
rp = ff.save();
totFaces++;
} else {
numOfSmallFaces++;
rp.setStatus(true);
}
if (!rp.getStatus()) {
msg.append("Errore: impossibile caricare fotoface da json per foto id " + foto.getId_foto() + ": " +
rp.getMsg() + "\n");
if (debug)
DBAdapter.printDebug(debug, "6 foto md5: " + foto.getMd5() + " errore : " + rp.getMsg());
}
}
}
}
if (!visiTrovati) {
ff = new FotoFace(foto.getApFull());
ff.setId_foto(foto.getId_foto());
StringBuilder pettorali = new StringBuilder(",");
for (Map.Entry<Long, Long> entry : hmNumbers.entrySet()) {
if (debug)
DBAdapter.printDebug(debug, "7 foto md5: " +
foto.getMd5() + " Key : " + String.valueOf(entry.getKey()) + " Value : " + String.valueOf(entry.getValue()));
pettorali.append(entry.getValue()).append(",");
}
ff.setPettorale(pettorali.toString());
rp = ff.save();
}
} else {
rp.setStatus(false);
rp.setMsg("ERRORE! md5 invio diverso da md5 response. md5:" + foto.getMd5() + " --> " + md5Response);
if (debug)
DBAdapter.printDebug(debug, " 9999 foto md5: " + foto.getMd5() + " md5 response: " + md5Response);
}
}
if (rp.getStatus())
rp.append(foto.save());
if (msg.length() > 0) {
rp.setStatus(false);
rp.setMsg(msg.toString());
}
if (rp.getStatus())
rp.setMsg("Trovati " + numOfFaces + "(" + totFaces + ") visi e " + numOfNUmbers + " numeri foto piccole: " + numOfSmallFaces);
} catch (Exception e) {
e.printStackTrace();
rp.setStatus(false);
rp.setMsg(e);
}
if (debug)
DBAdapter.printDebug(debug, " 8 foto md5: " + foto.getMd5() + " **************************** loadFacesByFaceRecognitionJson **************************");
return rp;
}
@Deprecated
protected static final ResParm loadFacesByFaceRecognitionJsonOrg(FotoI foto, JSONObject jo) {
ResParm rp = new ResParm();
boolean debug = true;
if (debug)
System.out.println("1-------------------- loadFacesByFaceRecognitionJson ------------------------foto md5: " +
foto.getMd5());
long minDimFoto = foto.getDimMinFotoFaceReal();
HashSet<FotoFace> hsFfSmall = new HashSet<>();
long marginTop = foto.getMargineFotoTop(), marginBottom = foto.getMargineFotoBottom(), marginLeft = foto.getMargineFotoSx();
long marginRight = foto.getMargineFotoDx();
long topY = 0L;
long bottomY = Long.MAX_VALUE;
long leftX = 0L;
long rightX = Long.MAX_VALUE;
if (marginTop != 0L || marginBottom != 0L || marginLeft != 0L || marginRight != 0L) {
topY = marginTop;
bottomY = foto.getHeight() - marginBottom;
leftX = marginLeft;
rightX = foto.getWidth() - marginRight;
}
try {
if (foto.getId_foto() == 0L || foto.getApFull() == null) {
rp.setStatus(false);
rp.setMsg("Errore! Foto non valida....");
}
StringBuilder msg = new StringBuilder();
int numOfNUmbers = 0;
int numOfFaces = 0;
int numOfSmallFaces = 0;
long totFaces = 0L;
FotoFace ff = new FotoFace(foto.getApFull());
ff.deleteFotoFaceByFoto(foto.getId_foto(), true);
JSONArray jaResponses = jo.getJSONArray("responses");
boolean visiTrovati = false;
if (jaResponses.length() > 0) {
JSONObject joResponse = jaResponses.getJSONObject(0).getJSONObject("response");
String md5Response = joResponse.getString("md5").trim();
if (md5Response.equals(foto.getMd5())) {
if (debug)
System.out.println("2 foto md5: " + foto.getMd5() + " joResponse:\n" + joResponse.toString(4));
HashMap<Long, Long> hmNumbers = new HashMap<>();
HashMap<Long, Long> hmNumbersY = new HashMap<>();
if (joResponse.has("numbers")) {
JSONArray jaNumbers = joResponse.getJSONArray("numbers");
for (int j = 0; j < jaNumbers.length(); j++) {
JSONObject joNumber = jaNumbers.getJSONObject(j);
if (!joNumber.getString("value").isEmpty()) {
hmNumbers.put(Long.valueOf(joNumber.getLong("xCenter")),
Long.valueOf(joNumber.getLong("value")));
hmNumbersY.put(Long.valueOf(joNumber.getLong("value")),
Long.valueOf(joNumber.getLong("yCenter")));
}
}
}
numOfNUmbers = hmNumbers.size();
if (joResponse.has("faceAnnotations")) {
visiTrovati = true;
JSONArray jaFaceAnnotations = joResponse.getJSONArray("faceAnnotations");
numOfFaces = jaFaceAnnotations.length();
for (int j = 0; j < jaFaceAnnotations.length(); j++) {
JSONObject joFaceAnnotation = jaFaceAnnotations.getJSONObject(j);
JSONObject joFace = new JSONObject();
JSONObject joFdBoundingPoly = joFaceAnnotation.getJSONObject("fdBoundingPoly");
joFace.put("fdBoundingPoly", joFdBoundingPoly);
JSONArray jaVertices = joFdBoundingPoly.getJSONArray("vertices");
JSONObject joTopLeft = jaVertices.getJSONObject(0);
JSONObject joBottomRigth = jaVertices.getJSONObject(2);
boolean noDetect = false;
long faceBottomVx = 0L, faceBottomVy = 0L, faceTopVx = 0L, faceTopVy = 0L;
if (joBottomRigth.has("x")) {
faceBottomVx = joBottomRigth.getLong("x");
faceBottomVy = joBottomRigth.getLong("y");
} else {
noDetect = true;
}
if (joTopLeft.has("x")) {
faceTopVx = joTopLeft.getLong("x");
faceTopVy = joTopLeft.getLong("y");
} else {
noDetect = true;
}
if (!noDetect && faceTopVy > topY && faceTopVx > leftX && faceBottomVy < bottomY && faceBottomVx < rightX) {
if (debug)
System.out.println("3 foto md5: " +
foto.getMd5() + " salvo vertici : joface\n" + joFace.toString(4));
ff = new FotoFace(foto.getApFull());
ff.setId_foto(foto.getId_foto());
ff.setFaceBottomVx(joBottomRigth.getLong("x"));
ff.setFaceBottomVy(joBottomRigth.getLong("y"));
ff.setFaceTopVx(joTopLeft.getLong("x"));
ff.setFaceTopVy(joTopLeft.getLong("y"));
long latoX = ff.getFaceBottomVx() - ff.getFaceTopVx();
if (latoX >= minDimFoto) {
ff.setJsonData(joFace.toString());
long sogliaW = ff.getFaceBottomVx() - ff.getFaceTopVx();
long sogliaH = ff.getFaceBottomVy() - ff.getFaceTopVy();
long faceXCenter = ff.getFaceTopVx() + sogliaW / 2L;
long faceYCenter = ff.getFaceTopVx() + sogliaH / 2L;
for (Map.Entry<Long, Long> entry : hmNumbers.entrySet()) {
if (debug)
System.out.println("4 foto md5: " + foto.getMd5() + " Key : " + String.valueOf(entry.getKey()) + " Value : " +
String.valueOf(entry.getValue()));
if (Math.abs(entry.getKey() - faceXCenter) < sogliaW)
if (faceYCenter > hmNumbersY.get(entry.getValue())) {
if (debug)
System.out.println("5 foto md5: " + foto.getMd5() + " Pettorale assegnato : " +
String.valueOf(entry.getValue()));
ff.setPettorale(entry.getValue().toString());
hmNumbers.remove(entry.getKey());
break;
}
}
rp = ff.save();
totFaces++;
} else {
numOfSmallFaces++;
rp.setStatus(true);
}
if (!rp.getStatus()) {
msg.append("Errore: impossibile caricare fotoface da json per foto id " + foto.getId_foto() + ": " +
rp.getMsg() + "\n");
if (debug)
System.out.println("6 foto md5: " + foto.getMd5() + " errore : " + rp.getMsg());
}
}
}
}
if (!visiTrovati) {
ff = new FotoFace(foto.getApFull());
ff.setId_foto(foto.getId_foto());
StringBuilder pettorali = new StringBuilder(",");
for (Map.Entry<Long, Long> entry : hmNumbers.entrySet()) {
if (debug)
System.out.println("7 foto md5: " +
foto.getMd5() + " Key : " + String.valueOf(entry.getKey()) + " Value : " + String.valueOf(entry.getValue()));
pettorali.append(entry.getValue());
pettorali.append(",");
}
ff.setPettorale(pettorali.toString());
rp = ff.save();
}
} else {
rp.setStatus(false);
rp.setMsg("ERRORE! md5 invio diverso da md5 response. md5:" + foto.getMd5() + " --> " + md5Response);
if (debug)
System.out.println(" 9999 foto md5: " + foto.getMd5() + " md5 response: " + md5Response + " **************************** loadFacesByFaceRecognitionJson **************************");
}
}
if (rp.getStatus())
rp.append(foto.save());
if (msg.length() > 0) {
rp.setStatus(false);
rp.setMsg(msg.toString());
}
if (rp.getStatus())
rp.setMsg("Trovati " + numOfFaces + "(" + totFaces + ") visi e " + numOfNUmbers + " numeri foto piccole: " + numOfSmallFaces);
} catch (Exception e) {
e.printStackTrace();
rp.setStatus(false);
rp.setMsg(e);
}
if (debug)
System.out.println(" 8 foto md5: " + foto.getMd5() + " **************************** loadFacesByFaceRecognitionJson **************************");
return rp;
}
public long getFlgTrainingOk() {
return this.flgTrainingOk;
}
public void setFlgTrainingOk(long flgTrainingOk) {
this.flgTrainingOk = flgTrainingOk;
}
public long getNumOfFaces() {
return this.numOfFaces;
}
public void setNumOfFaces(long numOfFaces) {
this.numOfFaces = numOfFaces;
}
public long getId_fotoFace() {
return this.id_fotoFace;
}
public void setId_fotoFace(long id_fotoFace) {
this.id_fotoFace = id_fotoFace;
setFotoFace(null);
}
public FotoFace getFotoFace() {
this.fotoFace = (FotoFace)getSecondaryObject(this.fotoFace, FotoFace.class, getId_fotoFace());
return this.fotoFace;
}
public void setFotoFace(FotoFace fotoFace) {
this.fotoFace = fotoFace;
}
public static boolean isThreadTrainingRecognizing() {
return threadTrainingRecognizing;
}
public final ResParm startTraining(FotoCR l_CR) {
if (!isThreadTrainingRecognizing()) {
new ThreadTrainig(l_CR);
return new ResParm(true, "Thread Training avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public final ResParm startRecognizer(FotoCR l_CR) {
if (!isThreadTrainingRecognizing()) {
new ThreadRecognizing(l_CR);
return new ResParm(true, "Thread Recognizer avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public long getWidth() {
if (this.width == 0L)
calcWH();
return this.width;
}
private boolean calcWH() {
ResParm rp = new ResParm();
if (getId_foto() > 0L) {
File file = new File(getFileNameFullPath());
if (file.exists()) {
try {
BufferedImage image = ImageIO.read(file);
if (image != null) {
setWidth((long)image.getWidth());
setHeight((long)image.getHeight());
rp = update("UPDATE FOTO SET width=" + this.width + ", height=" + this.height + " where id_foto=" + getId_foto());
return rp.getStatus();
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
}
return false;
}
public void setWidth(long width) {
this.width = width;
}
public long getHeight() {
if (this.height == 0L)
calcWH();
return this.height;
}
public void setHeight(long height) {
this.height = height;
}
public FaceDetectionMethod getFaceDetectionMethodReal() {
if (getId_faceDetectionMethod() > 0L)
return getFaceDetectionMethod();
return getPuntoFoto().getFaceDetectionMethodReal();
}
public long getMargineFotoBottom() {
return getEvento().getMargineFotoBottom();
}
public long getMargineFotoTop() {
return getEvento().getMargineFotoTop();
}
public long getMargineFotoSx() {
return getEvento().getMargineFotoSx();
}
public long getMargineFotoDx() {
return getEvento().getMargineFotoDx();
}
public long getDimMinFotoFace() {
return this.dimMinFotoFace;
}
public long getDimMinFotoFaceReal() {
if (getDimMinFotoFace() > 0L)
return getDimMinFotoFace();
return getPuntoFoto().getDimMinFotoFaceReal();
}
public void setDimMinFotoFace(long dimMinFotoFace) {
this.dimMinFotoFace = dimMinFotoFace;
}
public FaceDetectionMethod getFaceDetectionMethod() {
this.faceDetectionMethod = (FaceDetectionMethod)getSecondaryObject(this.faceDetectionMethod, FaceDetectionMethod.class,
getId_faceDetectionMethod());
return this.faceDetectionMethod;
}
public long getId_faceDetectionMethod() {
return this.id_faceDetectionMethod;
}
public void setFaceDetectionMethod(FaceDetectionMethod faceDetectionMethod) {
this.faceDetectionMethod = faceDetectionMethod;
}
public void setId_faceDetectionMethod(long id_faceDetectionMethod) {
this.id_faceDetectionMethod = id_faceDetectionMethod;
setFaceDetectionMethod(null);
}
public ResParm indexFoto(PuntoFoto puntoFoto, File theFoto, long l_id_user) {
ResParm rp = new ResParm();
String res = "";
StringBuffer errMsg = new StringBuffer();
StringBuilder sb = new StringBuilder();
if (puntoFoto.getId_evento() == 0L || puntoFoto.getId_puntoFoto() == 0L || theFoto == null) {
rp.setMsg("Indicizzazione singola foto: Bean gara o punto foto non caricato");
rp.setStatus(false);
handleDebug("Indicizzazione singola foto: Bean gara o punto foto non caricato", 2);
return rp;
}
try {
sb = new StringBuilder();
String l_nomeFoto = "", l_nomeFotoMd5 = "", l_md5 = "";
String l_pettorali = "";
Foto foto = new Foto(getApFull());
try {
l_nomeFoto = theFoto.getName();
if (theFoto.getName().toLowerCase().endsWith(".jpg") && (float)theFoto.getName().toLowerCase().indexOf(".mp4") < 0.0F) {
if (l_nomeFoto.length() > 16) {
StringTokenizer st = new StringTokenizer(l_nomeFoto, "-");
if (st.countToken() == 3) {
l_nomeFotoMd5 = l_nomeFoto;
l_nomeFoto = st.getToken(0);
l_md5 = st.getToken(1);
l_pettorali = st.getToken(2).replace(".jpg", "");
}
} else {
l_nomeFotoMd5 = "";
l_md5 = "";
l_pettorali = "";
}
foto.findByFilenamePuntoFoto(l_nomeFoto, puntoFoto.getId_puntoFoto());
if (foto.getDBState() == 0) {
res = "Nuova Foto";
foto.setId_evento(puntoFoto.getId_evento());
foto.setLastUpdId_user(l_id_user);
foto.setId_puntoFoto(puntoFoto.getId_puntoFoto());
foto.setFileName(l_nomeFoto);
foto.setMd5(l_md5);
foto.setFileNameMd5(l_nomeFotoMd5);
if (!l_pettorali.isEmpty())
foto.setPettorali(l_pettorali);
try {
File jpegFile = new File(theFoto.getCanonicalPath());
Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
ExifSubIFDDirectory exifSubIFDDirectory = (ExifSubIFDDirectory)metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
if (exifSubIFDDirectory.containsTag(36867)) {
Date theDate = exifSubIFDDirectory.getDate(36867);
foto.setTempo(new Time(theDate.getTime()));
} else {
res = "Foto Errata";
errMsg.append("<br>Attenzione " +
theFoto.getName() + ": impossibile determinare il tag data creazione!");
}
} catch (Exception e) {
res = "Foto Errata";
errMsg.append("<br>Attenzione " + theFoto.getName() + ": impossibile determinare il tag data creazione. Eccezione: " +
e.getMessage());
}
rp = foto.save();
if (!rp.getStatus()) {
errMsg.append("<br>Salvataggio fallito:" + rp.getMsg() + " foto:" + foto.getFileName());
res = "Foto Errata";
}
}
} else if (theFoto.getName().toLowerCase().endsWith(".mp4")) {
try {
boolean creaJpg = false;
l_nomeFotoMd5 = "";
l_md5 = "";
l_pettorali = "";
foto.findByFilenamePuntoFoto(l_nomeFoto, puntoFoto.getId_puntoFoto());
if (foto.getDBState() == 0) {
res = "Nuovo Video";
creaJpg = true;
foto.setId_evento(puntoFoto.getId_evento());
foto.setId_puntoFoto(puntoFoto.getId_puntoFoto());
foto.setFileName(l_nomeFoto);
foto.setFlgVideo(1L);
foto.setMd5(l_md5);
foto.setFileNameMd5(l_nomeFotoMd5);
if (!l_pettorali.isEmpty())
foto.setPettorali(l_pettorali);
String dirFoto = getParm("PATHFOTO_FACE").getTesto() + getParm("PATHFOTO_FACE").getTesto() +
puntoFoto.getEvento().getPathEvento();
sb = new StringBuilder("inizio estrazione..");
LinkedHashSet<String> frames = ManageVideoJ.extractNFrames(dirFoto + dirFoto + DBAdapter.SEPARATOR, dirFoto + dirFoto, l_nomeFoto, 4);
sb = new StringBuilder("andata bene: " + frames.toString());
String[] source = (String[])frames.toArray(new String[0]);
String brandFileName = foto.getEvento().getImgWmSlomoFilename();
ImageConverter.creaGifAnimato(dirFoto + dirFoto + DIR_MP4_JPG + ".gif", source, 640, 1000, true, brandFileName);
rp = foto.save();
if (!rp.getStatus()) {
errMsg.append("<br>Salvataggio fallito:" + rp.getMsg() + " video:" + foto.getFileName() + " " +
sb.toString());
res = "Foto Errata";
}
}
} catch (Exception e) {
e.printStackTrace();
errMsg.append("<br>ECCEZIONE! Salvataggio foto MP4 fallito:" + rp.getMsg() + " video:" + foto.getFileName() + " " +
sb.toString());
res = "Foto Errata";
}
} else {
handleDebug("File non jpg:" + theFoto.getName(), 1);
}
} catch (Exception e) {
handleDebug(e);
errMsg.append("\nIndicizzazione fallita sul file " + theFoto.getName() + "<br>" + e.getMessage());
}
if (errMsg.length() > 0) {
rp.setMsg("Indicizzazione singola foto " + foto.getFileName() + " completata: " + res + "<br> - Errori rilevati: " +
errMsg.toString());
rp.setStatus(false);
} else {
rp.setMsg("Indicizzazione singola foto " + foto.getFileName() + " completata: " + res);
rp.setStatus(true);
}
} catch (Exception e) {
rp.setMsg("ERRORE!! " + e.getMessage());
rp.setStatus(false);
}
return rp;
}
public Vectumerator<FaceScore> findFacesScore() {
FaceScore fs = new FaceScore(getApFull());
return fs.findByFoto(getId_foto());
}
public static boolean isThreadSelfieScoring() {
return threadSelfieScoring;
}
public final ResParm startSelfieScoring(FaceScoreTarget l_selfie, FotoCR l_CR) {
if (!isThreadSelfieScoring()) {
new ThreadSelfieScoring(l_selfie, l_CR);
return new ResParm(true, "Thread Selfie Scoring avviato");
}
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
}
public final ResParm stopSelfieScoring() {
if (!isThreadSelfieScoring())
return new ResParm(false, "ATTENZIONE!! Thread NON in esecuzione!!!");
threadSelfieScoringSTOP = true;
return new ResParm(true, "Stop Selfie Scoring inviato!!!");
}
public double getDetectFaceConfidentThresold() {
return getEvento().getDetectFaceConfidentThresold();
}
public long getFlgFaceScoringDone() {
return this.flgFaceScoringDone;
}
public final String getFaceScoringDone() {
return getFaceScoringDone(getFlgFaceScoringDone());
}
public ResParm updateCurrentFlgFaceScoringDone(long l_FlgFaceScoringDone) {
if (getId_foto() == 0L)
return new ResParm(false, "Foto con id a 0");
ResParm rp = update("UPDATE FOTO SET flgFaceScoringDone=" + l_FlgFaceScoringDone + " where id_foto=" + getId_foto());
if (rp.getStatus())
setFlgFaceScoringDone(l_FlgFaceScoringDone);
return rp;
}
public static final ResParm updateCurrentFlgFaceScoringDone(long l_id_foto, long l_FlgFaceScoringDone, DBAdapter dbAdapter) {
if (l_id_foto == 0L)
return new ResParm(false, "Foto con id a 0");
ResParm rp = dbAdapter.update("UPDATE FOTO SET flgFaceScoringDone=" + l_FlgFaceScoringDone + " where id_foto=" + l_id_foto);
return rp;
}
public static final String getFaceScoringDone(long l_flgFaceScoringDone) {
if (l_flgFaceScoringDone == 0L)
return "Da elaborare";
if (l_flgFaceScoringDone == 1L)
return "Detect Face ok (1)";
if (l_flgFaceScoringDone == 2L)
return "Si foto vicine (2)";
if (l_flgFaceScoringDone == 3L)
return "Si target su target (3)";
return "??";
}
public void setFlgFaceScoringDone(long flgFaceScoringDone) {
this.flgFaceScoringDone = flgFaceScoringDone;
}
public long getFaceSize() {
return getEvento().getFaceRecognizer().getFaceSize();
}
public void setLabels(String labels) {
this.labels = labels;
}
public FaceScore getSelfieScore(long l_id_selfie) {
if (l_id_selfie == 0L || getId_foto() == 0L || getFileName().isEmpty())
return new FaceScore(getApFull());
if (this.selfieScoreCache == null)
this.selfieScoreCache = new HashMap<>();
FaceScore cached = this.selfieScoreCache.get(Long.valueOf(l_id_selfie));
if (cached != null)
return cached;
FaceScore fs = new FaceScore(getApFull());
fs.findScoresBySelfieEventoFilenamefoto(l_id_selfie, getId_evento(), getFileName());
this.selfieScoreCache.put(Long.valueOf(l_id_selfie), fs);
return fs;
}
public long getFlgIndexReady() {
return this.flgIndexReady;
}
public void setFlgIndexReady(long flgIndexReady) {
this.flgIndexReady = flgIndexReady;
}
public Vectumerator<Foto> findByEventoFaceScoringDone(long l_id_evento, long l_flgFaceScoringDone) {
String s_Sql_Find = "select A.* from FOTO AS A inner join PUNTO_FOTO AS B on A.id_puntoFoto=B.id_puntoFoto";
String s_Sql_Order = " order by B.descrizione, A.fileName ";
WcString wc = new WcString();
wc.addWc("A.id_evento=" + l_id_evento);
if (l_flgFaceScoringDone == 0L) {
wc.addWc("(A.flgFaceScoringDone=0 or A.flgFaceScoringDone is null)");
} else {
wc.addWc("A.flgFaceScoringDone=" + l_flgFaceScoringDone);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<Foto> findByPuntoFotoFaceScoringDone(long l_id_puntoFoto, long l_flgFaceScoringDone) {
return findFotoFaceByPuntoFotoFaceScoringDone(l_id_puntoFoto, l_flgFaceScoringDone, 0L);
}
public Vectumerator<Foto> findFotoFaceByPuntoFotoFaceScoringDone(long l_id_puntoFoto, long l_flgFaceScoringDone, long range) {
boolean debug = true;
if (range > 0L) {
String str1 = "select A.*, FF.id_fotoFace as id_fotoFace from FOTO AS A inner join FOTO_FACE AS FF ON A.id_foto=FF.id_foto";
String str2 = " order by fileName ";
String s_Sql_Order2 = " order by A.fileName desc";
long l_flgFaceScoringDone2 = l_flgFaceScoringDone + 1L;
WcString wc1 = new WcString();
wc1.addWc("A.id_puntoFoto=" + l_id_puntoFoto);
if (l_flgFaceScoringDone == 0L) {
wc1.addWc("(A.flgFaceScoringDone=0 or A.flgFaceScoringDone is null)");
} else {
wc1.addWc("A.flgFaceScoringDone=" + l_flgFaceScoringDone);
}
WcString wc2 = new WcString();
wc2.addWc("A.id_puntoFoto=" + l_id_puntoFoto);
if (l_flgFaceScoringDone == 0L) {
wc2.addWc("(A.flgFaceScoringDone=0 or A.flgFaceScoringDone is null)");
} else {
wc2.addWc("A.flgFaceScoringDone=" + l_flgFaceScoringDone2);
}
String s_sql = "(" + str1 + wc1.toString() + ") UNION ALL ( SELECT * FROM (" + str1 + wc2.toString() + s_Sql_Order2 + " LIMIT " + range + ") AS ultimi)" + str2;
DBAdapter.printDebug(debug, s_sql);
try {
PreparedStatement stmt = getConn().prepareStatement(s_sql);
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
String s_Sql_Find = "select A.*, FF.id_fotoFace as id_fotoFace from FOTO AS A inner join FOTO_FACE AS FF ON A.id_foto=FF.id_foto";
String s_Sql_Order = " order by A.fileName ";
WcString wc = new WcString();
wc.addWc("A.id_puntoFoto=" + l_id_puntoFoto);
if (l_flgFaceScoringDone == 0L) {
wc.addWc("(A.flgFaceScoringDone=0 or A.flgFaceScoringDone is null)");
} else {
wc.addWc("A.flgFaceScoringDone=" + l_flgFaceScoringDone);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
DBAdapter.printDebug(debug, s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public long getNumFotoFaceByPuntoFotoFaceScoringDone(long l_id_puntoFoto, long l_flgFaceScoringDone) {
boolean debug = true;
String s_Sql_Find = "select count(*) as _c from FOTO AS A inner join FOTO_FACE AS FF ON A.id_foto=FF.id_foto ";
WcString wc = new WcString();
wc.addWc("A.id_puntoFoto=" + l_id_puntoFoto);
if (l_flgFaceScoringDone == 0L) {
wc.addWc("(A.flgFaceScoringDone=0 or A.flgFaceScoringDone is null)");
} else {
wc.addWc("A.flgFaceScoringDone=" + l_flgFaceScoringDone);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
DBAdapter.printDebug(debug, s_Sql_Find + s_Sql_Find);
return getCount(stmt, "_c");
} catch (SQLException e) {
handleDebug(e);
return -1L;
}
}
public long getNumFotoFaceByEventoFaceScoringDone(long l_id_evento, long l_flgFaceScoringDone) {
boolean debug = true;
String s_Sql_Find = "select count(*) as _c from FOTO AS A inner join FOTO_FACE AS FF ON A.id_foto=FF.id_foto ";
WcString wc = new WcString();
wc.addWc("A.id_evento=" + l_id_evento);
if (l_flgFaceScoringDone == 0L) {
wc.addWc("(A.flgFaceScoringDone=0 or A.flgFaceScoringDone is null)");
} else {
wc.addWc("A.flgFaceScoringDone=" + l_flgFaceScoringDone);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
DBAdapter.printDebug(debug, s_Sql_Find + s_Sql_Find);
return getCount(stmt, "_c");
} catch (SQLException e) {
handleDebug(e);
return -1L;
}
}
}