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,223 @@
|
|||
package it.acxent.dm;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class FaceDetectionMethod extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1705937095434L;
|
||||
|
||||
private long id_faceDetectionMethod;
|
||||
|
||||
private long codice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private long flgDetectionType;
|
||||
|
||||
private String descrizioneLunga;
|
||||
|
||||
private String pathModello;
|
||||
|
||||
private long flgBtn;
|
||||
|
||||
public static final long FACE_DETECTION_TYPE_OCV = 0L;
|
||||
|
||||
public static final long FACE_DETECTION_TYPE_GOOGLE = 1L;
|
||||
|
||||
public static final long FACE_DETECTION_TYPE_YUNET = 2L;
|
||||
|
||||
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 = 20L;
|
||||
|
||||
public static final long FACE_DETECT_METHOD_GOOGLE_VISION = 99L;
|
||||
|
||||
public static final String getDetectionType(long l_flgDetectionType) {
|
||||
if (l_flgDetectionType == 0L)
|
||||
return "Open CV";
|
||||
if (l_flgDetectionType == 1L)
|
||||
return "Google Vision";
|
||||
if (l_flgDetectionType == 2L)
|
||||
return "Yunet zoo";
|
||||
return "";
|
||||
}
|
||||
|
||||
public final String getDetectionType() {
|
||||
return getDetectionType(getFlgDetectionType());
|
||||
}
|
||||
|
||||
public FaceDetectionMethod(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceDetectionMethod() {}
|
||||
|
||||
public void setId_faceDetectionMethod(long newId_faceDetectionMethod) {
|
||||
this.id_faceDetectionMethod = newId_faceDetectionMethod;
|
||||
}
|
||||
|
||||
public void setCodice(long newCodice) {
|
||||
this.codice = newCodice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setFlgDetectionType(long newFlgDectectionType) {
|
||||
this.flgDetectionType = newFlgDectectionType;
|
||||
}
|
||||
|
||||
public void setDescrizioneLunga(String newDescrizioneLunga) {
|
||||
this.descrizioneLunga = newDescrizioneLunga;
|
||||
}
|
||||
|
||||
public void setPathModello(String newPathModello) {
|
||||
this.pathModello = newPathModello;
|
||||
}
|
||||
|
||||
public long getId_faceDetectionMethod() {
|
||||
return this.id_faceDetectionMethod;
|
||||
}
|
||||
|
||||
public long getCodice() {
|
||||
return this.codice;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public long getFlgDetectionType() {
|
||||
return this.flgDetectionType;
|
||||
}
|
||||
|
||||
public String getDescrizioneLunga() {
|
||||
return (this.descrizioneLunga == null) ? "" : this.descrizioneLunga.trim();
|
||||
}
|
||||
|
||||
public String getPathModello() {
|
||||
return (this.pathModello == null) ? "" : this.pathModello.trim();
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return getPathModello();
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FaceDetectionMethod> findByBtn() {
|
||||
String s_Sql_Find = "select A.* from FACE_DETECTION_METHOD AS A";
|
||||
String s_Sql_Order = " order by A.codice";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.flgBtn=1");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void findByCodice(long l_codice) {
|
||||
String s_Sql_Find = "select A.* from FACE_DETECTION_METHOD AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (l_codice == 0L) {
|
||||
wc.addWc("(A.codice=0 or A.codice is null)");
|
||||
} else {
|
||||
wc.addWc("A.codice=" + l_codice);
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ResParm syncJson(JSONArray jaFdm) {
|
||||
ResParm rp = new ResParm();
|
||||
boolean debug = false;
|
||||
if (debug)
|
||||
System.out.println("syncJson:\n" + jaFdm.toString());
|
||||
FaceDetectionMethod row = new FaceDetectionMethod(getApFull());
|
||||
for (int i = 0; i < jaFdm.length(); i++) {
|
||||
JSONObject jRow = jaFdm.getJSONObject(i);
|
||||
if (debug)
|
||||
System.out.println("syncJson: codice " + jRow.getLong("codice") + " desc: " +
|
||||
jRow.getString("descrizione"));
|
||||
row.findByCodice(jRow.getLong("codice"));
|
||||
row.setCodice(jRow.getLong("codice"));
|
||||
row.setFlgDetectionType(jRow.getLong("flgDetectionType"));
|
||||
row.setDescrizione(jRow.getString("descrizione"));
|
||||
row.setDescrizioneLunga(jRow.getString("descrizioneLunga"));
|
||||
row.save();
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
protected String sqlStringfindAll() {
|
||||
return "select A.* from FACE_DETECTION_METHOD AS A order by codice";
|
||||
}
|
||||
|
||||
public long getFlgBtn() {
|
||||
return this.flgBtn;
|
||||
}
|
||||
|
||||
public void setFlgBtn(long flgBtn) {
|
||||
this.flgBtn = flgBtn;
|
||||
}
|
||||
|
||||
public Vectumerator<FaceDetectionMethod> findByCR(FaceDetectionMethodCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_DETECTION_METHOD AS A";
|
||||
String s_Sql_Order = " order by codice";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package it.acxent.dm;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FaceDetectionMethodCR extends CRAdapter {
|
||||
private static final long serialVersionUID = -7539345269995197440L;
|
||||
|
||||
private long id_faceDetectionMethod;
|
||||
|
||||
private long codice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private long flgDetectionType = -1L;
|
||||
|
||||
private String descrizioneLunga;
|
||||
|
||||
private String pathModello;
|
||||
|
||||
private long flgBtn = -1L;
|
||||
|
||||
public static final String getDetectionType(long l_flgDetectionTYpe) {
|
||||
return FaceDetectionMethod.getDetectionType(l_flgDetectionTYpe);
|
||||
}
|
||||
|
||||
public final String getDetectionType() {
|
||||
return FaceDetectionMethod.getDetectionType(getFlgDetectionType());
|
||||
}
|
||||
|
||||
public FaceDetectionMethodCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceDetectionMethodCR() {}
|
||||
|
||||
public void setId_faceDetectionMethod(long newId_faceDetectionMethod) {
|
||||
this.id_faceDetectionMethod = newId_faceDetectionMethod;
|
||||
}
|
||||
|
||||
public void setCodice(long newCodice) {
|
||||
this.codice = newCodice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setFlgDetectionType(long newFlgDectectionType) {
|
||||
this.flgDetectionType = newFlgDectectionType;
|
||||
}
|
||||
|
||||
public void setDescrizioneLunga(String newDescrizioneLunga) {
|
||||
this.descrizioneLunga = newDescrizioneLunga;
|
||||
}
|
||||
|
||||
public void setPathModello(String newPathModello) {
|
||||
this.pathModello = newPathModello;
|
||||
}
|
||||
|
||||
public long getId_faceDetectionMethod() {
|
||||
return this.id_faceDetectionMethod;
|
||||
}
|
||||
|
||||
public long getCodice() {
|
||||
return this.codice;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public long getFlgDetectionType() {
|
||||
return this.flgDetectionType;
|
||||
}
|
||||
|
||||
public String getDescrizioneLunga() {
|
||||
return (this.descrizioneLunga == null) ? "" : this.descrizioneLunga.trim();
|
||||
}
|
||||
|
||||
public String getPathModello() {
|
||||
return (this.pathModello == null) ? "" : this.pathModello.trim();
|
||||
}
|
||||
|
||||
public long getFlgBtn() {
|
||||
return this.flgBtn;
|
||||
}
|
||||
|
||||
public void setFlgBtn(long flgBtn) {
|
||||
this.flgBtn = flgBtn;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package it.acxent.dm;
|
||||
|
||||
public class FaceJsonAttribute {
|
||||
public static final String J_ATTRIBUTE_FILENAME = "fileName";
|
||||
|
||||
public static final String J_ATTRIBUTE_MD5 = "md5";
|
||||
|
||||
public static final String J_ATTRIBUTE_ID_FOTO = "id_foto";
|
||||
|
||||
public static final String J_ATTRIBUTE_ORIGINAL_PATH = "originalPath";
|
||||
|
||||
public static final String J_ATTRIBUTE_LABELS = "labels";
|
||||
|
||||
public static final String J_ATTRIBUTE_REQUEST_IMAGE = "reqImage";
|
||||
|
||||
public static final String J_ATTRIBUTE_VALUE = "value";
|
||||
|
||||
public static final String J_ATTRIBUTE_X_CENTER = "xCenter";
|
||||
|
||||
public static final String J_ATTRIBUTE_Y_CENTER = "yCenter";
|
||||
|
||||
public static final String J_ATTRIBUTE_RESPONSE = "response";
|
||||
|
||||
public static final String J_ATTRIBUTE_FACE_ANNOTATIONS = "faceAnnotations";
|
||||
|
||||
public static final String J_ATTRIBUTE_FD_BOUNDING_POLY = "fdBoundingPoly";
|
||||
|
||||
public static final String J_ATTRIBUTE_VERTICES = "vertices";
|
||||
|
||||
public static final String J_ATTRIBUTE_Y = "y";
|
||||
|
||||
public static final String J_ATTRIBUTE_X = "x";
|
||||
|
||||
public static final String J_ATTRIBUTE_NUMBERS = "numbers";
|
||||
|
||||
public static final String J_ATTRIBUTE_RESPONSES = "responses";
|
||||
|
||||
public static final String J_ATTRIBUTE_MSG = "msg";
|
||||
|
||||
public static final String J_ATTRIBUTE_STATUS = "status";
|
||||
|
||||
public static final String J_ATTRIBUTE_SUCCESS = "success";
|
||||
|
||||
public static final String J_ATTRIBUTE_FACE_DETECTION_TYPE = "faceDetectionType";
|
||||
|
||||
public static final String J_ATTRIBUTE_FACE_RECOGNIZER_TYPE = "recognizerType";
|
||||
|
||||
public static final String J_ATTRIBUTE_CONTENT = "content";
|
||||
|
||||
public static final String J_ATTRIBUTE_IMAGE = "image";
|
||||
|
||||
public static final String J_ATTRIBUTE_REQUESTS = "requests";
|
||||
|
||||
public static final String J_ATTRIBUTE_CODGARA = "id_gara";
|
||||
|
||||
public static final String J_ATTRIBUTE_CODE = "code";
|
||||
|
||||
public static final String J_ATTRIBUTE_DESCRIPTION = "description";
|
||||
|
||||
public static final String J_ATTRIBUTE_NOIMG = "noImg";
|
||||
|
||||
public static final String J_ATTRIBUTE_ID = "id";
|
||||
|
||||
public static final String J_ATTRIBUTE_LABEL = "label";
|
||||
|
||||
public static final String J_ATTRIBUTE_LABEL_MD5 = "labelMd5";
|
||||
|
||||
public static final String J_ATTRIBUTE_NUMBERTRAININGIMAGES = "numberTrainingImages";
|
||||
|
||||
public static final String J_ATTRIBUTE_CONFIDENCE = "confidence";
|
||||
|
||||
public static final String J_ATTRIBUTE_NUM_OF_FACES = "numOfFaces";
|
||||
|
||||
public static final String J_ATTRIBUTE_NUM_OF_NUMBERS = "numOfNumbers";
|
||||
|
||||
public static final String J_ATTRIBUTE_SEND_NOTIFICHE = "sendNotifiche";
|
||||
|
||||
public static final String J_ATTRIBUTE_SOURCE = "source";
|
||||
|
||||
public static final String J_ATTRIBUTE_IMAGEURI = "imageUri";
|
||||
|
||||
public static final String J_ATTRIBUTE_POSITION = "position";
|
||||
|
||||
public static final String J_ATTRIBUTE_LANDMARKS = "landmarks";
|
||||
|
||||
public static final String J_ATTRIBUTE_Z = "z";
|
||||
|
||||
public static final String J_ATTRIBUTE_RECOGNIZER_TYPE = "recognizerType";
|
||||
|
||||
public static final String J_ATTRIBUTE_ADD_LABEL = "addLabel";
|
||||
|
||||
public static final String J_ATTRIBUTE_FACE_DETECTION_METHODS = "faceDetectionMethods";
|
||||
|
||||
public static final String J_ATTRIBUTE_CODICE = "codice";
|
||||
|
||||
public static final String J_ATTRIBUTE_FLG_DETECTION_TYPE = "flgDetectionType";
|
||||
|
||||
public static final String J_ATTRIBUTE_DESCRIZIONE = "descrizione";
|
||||
|
||||
public static final String J_ATTRIBUTE_DESCRIZIONE_LUNGA = "descrizioneLunga";
|
||||
|
||||
public static final String J_ATTRIBUTE_JSON_DATA_PATH = "json_data_path";
|
||||
|
||||
public static final String J_ATTRIBUTE_JSON_RES_PATH = "json_res_path";
|
||||
|
||||
public static final String J_ATTRIBUTE_DIS_TYPE = "dis_type";
|
||||
|
||||
public static final String J_ATTRIBUTE_TARGET = "target";
|
||||
|
||||
public static final String J_ATTRIBUTE_QUERY = "query";
|
||||
|
||||
public static final String J_ATTRIBUTE_PATH = "path";
|
||||
|
||||
public static final String J_ATTRIBUTE_SCORE = "score";
|
||||
|
||||
public static final String J_ATTRIBUTE_DETECTION_CONFIDENCE_THRESOLD = "conf_threshold";
|
||||
|
||||
public static final String J_ATTRIBUTE_TYPE = "type";
|
||||
|
||||
public static final String J_ATTRIBUTE_DB = "db";
|
||||
|
||||
public static final String J_ATTRIBUTE_TYPE_VALUE_SELFIE = "selfie";
|
||||
|
||||
public static final String J_ATTRIBUTE_TYPE_VALUE_FACE = "face";
|
||||
|
||||
public static final String J_ATTRIBUTE_TYPE_VALUE_PHOTO = "photo";
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
package it.acxent.dm;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Date;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public abstract class FaceRecognizer extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1701089773600L;
|
||||
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private long flgTipo;
|
||||
|
||||
private String codice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private long nTrainingImages;
|
||||
|
||||
private Date dataTraining;
|
||||
|
||||
private Timestamp tsStart;
|
||||
|
||||
private Timestamp tsStop;
|
||||
|
||||
private long faceSize;
|
||||
|
||||
public static final long RECOGNIZER_LBPH = 0L;
|
||||
|
||||
public static final long RECOGNIZER_FISH = 1L;
|
||||
|
||||
public static final long RECOGNIZER_EIGEN = 2L;
|
||||
|
||||
public static final int TOPT_NUMB_RECOGNIZER = 1;
|
||||
|
||||
public FaceRecognizer(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecognizer() {}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFlgTipo(long newFlgTipo) {
|
||||
this.flgTipo = newFlgTipo;
|
||||
}
|
||||
|
||||
public void setCodice(String newCodice) {
|
||||
this.codice = newCodice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setFileName(String newFileName) {
|
||||
this.fileName = newFileName;
|
||||
}
|
||||
|
||||
public void setNTrainingImages(long newNTrainingImages) {
|
||||
this.nTrainingImages = newNTrainingImages;
|
||||
}
|
||||
|
||||
public void setDataTraining(Date newDataTraining) {
|
||||
this.dataTraining = newDataTraining;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public long getFlgTipo() {
|
||||
return this.flgTipo;
|
||||
}
|
||||
|
||||
public String getCodice() {
|
||||
return (this.codice == null) ? "" : this.codice.trim();
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return (this.fileName == null) ? getCodice() : this.fileName.trim();
|
||||
}
|
||||
|
||||
public long getNTrainingImages() {
|
||||
return this.nTrainingImages;
|
||||
}
|
||||
|
||||
public Date getDataTraining() {
|
||||
return this.dataTraining;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FaceRecognizer> findByCR(FaceRecognizerCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void findByCode(String l_code) {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.code='" + l_code + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findBySessionId(String l_sessionId) {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.sessionId='" + l_sessionId + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Timestamp getTsStart() {
|
||||
return this.tsStart;
|
||||
}
|
||||
|
||||
public void setTsStart(Timestamp tsStart) {
|
||||
this.tsStart = tsStart;
|
||||
}
|
||||
|
||||
public Timestamp getTsStop() {
|
||||
return this.tsStop;
|
||||
}
|
||||
|
||||
public void setTsStop(Timestamp tsStop) {
|
||||
this.tsStop = tsStop;
|
||||
}
|
||||
|
||||
public static final String getTipo(long l_flgTipo) {
|
||||
if (l_flgTipo == 2L)
|
||||
return "EIGEN";
|
||||
if (l_flgTipo == 0L)
|
||||
return "LBPH";
|
||||
if (l_flgTipo == 1L)
|
||||
return "FISH";
|
||||
return "xx";
|
||||
}
|
||||
|
||||
public final String getTipo() {
|
||||
return getTipo(getFlgTipo());
|
||||
}
|
||||
|
||||
public long getFaceSize() {
|
||||
return (this.faceSize == 0L) ? 96L : this.faceSize;
|
||||
}
|
||||
|
||||
public void setFaceSize(long faceSize) {
|
||||
this.faceSize = faceSize;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package it.acxent.dm;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import java.sql.Date;
|
||||
|
||||
public class FaceRecognizerCR extends CRAdapter {
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private String flgTIpo;
|
||||
|
||||
private String codice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private String sessionId;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private long nTrainingImages;
|
||||
|
||||
private Date dataTraining;
|
||||
|
||||
public FaceRecognizerCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecognizerCR() {}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFlgTIpo(String newFlgTIpo) {
|
||||
this.flgTIpo = newFlgTIpo;
|
||||
}
|
||||
|
||||
public void setCodice(String newCodice) {
|
||||
this.codice = newCodice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setSessionId(String newSessionId) {
|
||||
this.sessionId = newSessionId;
|
||||
}
|
||||
|
||||
public void setFileName(String newFileName) {
|
||||
this.fileName = newFileName;
|
||||
}
|
||||
|
||||
public void setNTrainingImages(long newNTrainingImages) {
|
||||
this.nTrainingImages = newNTrainingImages;
|
||||
}
|
||||
|
||||
public void setDataTraining(Date newDataTraining) {
|
||||
this.dataTraining = newDataTraining;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public String getFlgTIpo() {
|
||||
return (this.flgTIpo == null) ? "" : this.flgTIpo.trim();
|
||||
}
|
||||
|
||||
public String getCodice() {
|
||||
return (this.codice == null) ? "" : this.codice.trim();
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return (this.sessionId == null) ? "" : this.sessionId.trim();
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return (this.fileName == null) ? "" : this.fileName.trim();
|
||||
}
|
||||
|
||||
public long getNTrainingImages() {
|
||||
return this.nTrainingImages;
|
||||
}
|
||||
|
||||
public Date getDataTraining() {
|
||||
return this.dataTraining;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.dm;
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
public class AppStats {
|
||||
public static volatile double scoring1CurrentTargetVelox;
|
||||
|
||||
public static volatile double scoring7CurrentTargetVelox;
|
||||
|
||||
public static volatile String scoring1ETA;
|
||||
|
||||
public static volatile String scoring7ETA;
|
||||
|
||||
public static volatile int numberOfCores;
|
||||
|
||||
public static volatile int numCudaDevices;
|
||||
|
||||
public static volatile int threadsPerCudaProcessor;
|
||||
|
||||
public static volatile int maxNumberOfThreads;
|
||||
|
||||
public static volatile int currentNumQueryCallable;
|
||||
|
||||
public static volatile int currentThreadCount;
|
||||
|
||||
public static volatile int semaphoreAvailablePermits;
|
||||
|
||||
public static volatile int semaphoreQueueLength;
|
||||
|
||||
public static volatile int poolActiveThreads;
|
||||
|
||||
public static volatile long poolTotalTasks;
|
||||
|
||||
public static volatile long poolCompletedTasks;
|
||||
|
||||
public static volatile int poolQueuedTasks;
|
||||
|
||||
public static void updateFromPoolAndSemaphore(ThreadPoolExecutor pool, Semaphore semaphore) {
|
||||
if (pool != null) {
|
||||
poolActiveThreads = pool.getActiveCount();
|
||||
poolTotalTasks = pool.getTaskCount();
|
||||
poolCompletedTasks = pool.getCompletedTaskCount();
|
||||
poolQueuedTasks = pool.getQueue().size();
|
||||
}
|
||||
if (semaphore != null) {
|
||||
semaphoreAvailablePermits = semaphore.availablePermits();
|
||||
semaphoreQueueLength = semaphore.getQueueLength();
|
||||
}
|
||||
}
|
||||
|
||||
public static double getScoring1CurrentTargetVelox() {
|
||||
return scoring1CurrentTargetVelox;
|
||||
}
|
||||
|
||||
public static void setScoring1CurrentTargetVelox(double scoring1CurrentTargetVelox) {
|
||||
AppStats.scoring1CurrentTargetVelox = scoring1CurrentTargetVelox;
|
||||
}
|
||||
|
||||
public static double getScoring7CurrentTargetVelox() {
|
||||
return scoring7CurrentTargetVelox;
|
||||
}
|
||||
|
||||
public static void setScoring7CurrentTargetVelox(double scoring7CurrentTargetVelox) {
|
||||
AppStats.scoring7CurrentTargetVelox = scoring7CurrentTargetVelox;
|
||||
}
|
||||
|
||||
public static int getNumberOfCores() {
|
||||
return numberOfCores;
|
||||
}
|
||||
|
||||
public static void setNumberOfCores(int numberOfCores) {
|
||||
AppStats.numberOfCores = numberOfCores;
|
||||
}
|
||||
|
||||
public static int getNumCudaDevices() {
|
||||
return numCudaDevices;
|
||||
}
|
||||
|
||||
public static void setNumCudaDevices(int numCudaDevices) {
|
||||
AppStats.numCudaDevices = numCudaDevices;
|
||||
}
|
||||
|
||||
public static int getThreadsPerCudaProcessor() {
|
||||
return threadsPerCudaProcessor;
|
||||
}
|
||||
|
||||
public static void setThreadsPerCudaProcessor(int threadsPerCudaProcessor) {
|
||||
AppStats.threadsPerCudaProcessor = threadsPerCudaProcessor;
|
||||
}
|
||||
|
||||
public static int getMaxNumberOfThreads() {
|
||||
return maxNumberOfThreads;
|
||||
}
|
||||
|
||||
public static void setMaxNumberOfThreads(int maxNumberOfThreads) {
|
||||
AppStats.maxNumberOfThreads = maxNumberOfThreads;
|
||||
}
|
||||
|
||||
public static int getCurrentNumQueryCallable() {
|
||||
return currentNumQueryCallable;
|
||||
}
|
||||
|
||||
public static void setCurrentNumQueryCallable(int currentNumQueryCallable) {
|
||||
AppStats.currentNumQueryCallable = currentNumQueryCallable;
|
||||
}
|
||||
|
||||
public static int getCurrentThreadCount() {
|
||||
return currentThreadCount;
|
||||
}
|
||||
|
||||
public static void setCurrentThreadCount(int currentThreadCount) {
|
||||
AppStats.currentThreadCount = currentThreadCount;
|
||||
}
|
||||
|
||||
public static int getSemaphoreAvailablePermits() {
|
||||
return semaphoreAvailablePermits;
|
||||
}
|
||||
|
||||
public static void setSemaphoreAvailablePermits(int semaphoreAvailablePermits) {
|
||||
AppStats.semaphoreAvailablePermits = semaphoreAvailablePermits;
|
||||
}
|
||||
|
||||
public static int getSemaphoreQueueLength() {
|
||||
return semaphoreQueueLength;
|
||||
}
|
||||
|
||||
public static void setSemaphoreQueueLength(int semaphoreQueueLength) {
|
||||
AppStats.semaphoreQueueLength = semaphoreQueueLength;
|
||||
}
|
||||
|
||||
public static int getPoolActiveThreads() {
|
||||
return poolActiveThreads;
|
||||
}
|
||||
|
||||
public static void setPoolActiveThreads(int poolActiveThreads) {
|
||||
AppStats.poolActiveThreads = poolActiveThreads;
|
||||
}
|
||||
|
||||
public static long getPoolTotalTasks() {
|
||||
return poolTotalTasks;
|
||||
}
|
||||
|
||||
public static void setPoolTotalTasks(long poolTotalTasks) {
|
||||
AppStats.poolTotalTasks = poolTotalTasks;
|
||||
}
|
||||
|
||||
public static long getPoolCompletedTasks() {
|
||||
return poolCompletedTasks;
|
||||
}
|
||||
|
||||
public static void setPoolCompletedTasks(long poolCompletedTasks) {
|
||||
AppStats.poolCompletedTasks = poolCompletedTasks;
|
||||
}
|
||||
|
||||
public static int getPoolQueuedTasks() {
|
||||
return poolQueuedTasks;
|
||||
}
|
||||
|
||||
public static void setPoolQueuedTasks(int poolQueuedTasks) {
|
||||
AppStats.poolQueuedTasks = poolQueuedTasks;
|
||||
}
|
||||
|
||||
public static String getScoring1ETA() {
|
||||
return scoring1ETA;
|
||||
}
|
||||
|
||||
public static void setScoring1ETA(String scoring1eta) {
|
||||
scoring1ETA = scoring1eta;
|
||||
}
|
||||
|
||||
public static String getScoring7ETA() {
|
||||
return scoring7ETA;
|
||||
}
|
||||
|
||||
public static void setScoring7ETA(String scoring7eta) {
|
||||
scoring7ETA = scoring7eta;
|
||||
}
|
||||
}
|
||||
3312
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Evento.java
Normal file
3312
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Evento.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,111 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.anag.Clifor;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import java.sql.Date;
|
||||
|
||||
public class EventoCR extends CRAdapter {
|
||||
private static final long serialVersionUID = -1740315027120006003L;
|
||||
|
||||
private long id_evento;
|
||||
|
||||
private long id_clifor;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private Date dataEvento;
|
||||
|
||||
private String codiceEventoCliente;
|
||||
|
||||
private Clifor clifor;
|
||||
|
||||
private long anno;
|
||||
|
||||
private Date dataA;
|
||||
|
||||
private Date dataDa;
|
||||
|
||||
public EventoCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public EventoCR() {}
|
||||
|
||||
public void setId_evento(long newId_evento) {
|
||||
this.id_evento = newId_evento;
|
||||
}
|
||||
|
||||
public void setId_clifor(long newId_clifor) {
|
||||
this.id_clifor = newId_clifor;
|
||||
setClifor(null);
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setDataEvento(Date newDataGara) {
|
||||
this.dataEvento = newDataGara;
|
||||
}
|
||||
|
||||
public void setCodiceEventoCliente(String newCodiceEventoCliente) {
|
||||
this.codiceEventoCliente = newCodiceEventoCliente;
|
||||
}
|
||||
|
||||
public long getId_evento() {
|
||||
return this.id_evento;
|
||||
}
|
||||
|
||||
public long getId_clifor() {
|
||||
return this.id_clifor;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public Date getDataEvento() {
|
||||
return this.dataEvento;
|
||||
}
|
||||
|
||||
public String getCodiceEventoCliente() {
|
||||
return (this.codiceEventoCliente == null) ? "" : this.codiceEventoCliente.trim();
|
||||
}
|
||||
|
||||
public void setClifor(Clifor newClifor) {
|
||||
this.clifor = newClifor;
|
||||
}
|
||||
|
||||
public Clifor getClifor() {
|
||||
this.clifor = (Clifor)getSecondaryObject((DBAdapter)this.clifor, Clifor.class,
|
||||
|
||||
getId_clifor());
|
||||
return this.clifor;
|
||||
}
|
||||
|
||||
public long getAnno() {
|
||||
return this.anno;
|
||||
}
|
||||
|
||||
public void setAnno(long anno) {
|
||||
this.anno = anno;
|
||||
}
|
||||
|
||||
public Date getDataA() {
|
||||
return this.dataA;
|
||||
}
|
||||
|
||||
public void setDataA(Date dataA) {
|
||||
this.dataA = dataA;
|
||||
}
|
||||
|
||||
public Date getDataDa() {
|
||||
return this.dataDa;
|
||||
}
|
||||
|
||||
public void setDataDa(Date dataDa) {
|
||||
this.dataDa = dataDa;
|
||||
}
|
||||
}
|
||||
473
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Face.java
Normal file
473
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Face.java
Normal file
|
|
@ -0,0 +1,473 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.util.DoubleOperator;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class Face {
|
||||
public static final String RIGHT_CHEEK_CENTER = "RIGHT_CHEEK_CENTER";
|
||||
|
||||
public static final String LEFT_CHEEK_CENTER = "LEFT_CHEEK_CENTER";
|
||||
|
||||
public static final String CHIN_RIGHT_GONION = "CHIN_RIGHT_GONION";
|
||||
|
||||
public static final String CHIN_LEFT_GONION = "CHIN_LEFT_GONION";
|
||||
|
||||
public static final String CHIN_GNATHION = "CHIN_GNATHION";
|
||||
|
||||
public static final String FOREHEAD_GLABELLA = "FOREHEAD_GLABELLA";
|
||||
|
||||
public static final String RIGHT_EAR_TRAGION = "RIGHT_EAR_TRAGION";
|
||||
|
||||
public static final String LEFT_EAR_TRAGION = "LEFT_EAR_TRAGION";
|
||||
|
||||
public static final String RIGHT_EYEBROW_UPPER_MIDPOINT = "RIGHT_EYEBROW_UPPER_MIDPOINT";
|
||||
|
||||
public static final String LEFT_EYEBROW_UPPER_MIDPOINT = "LEFT_EYEBROW_UPPER_MIDPOINT";
|
||||
|
||||
public static final String RIGHT_EYE_LEFT_CORNER = "RIGHT_EYE_LEFT_CORNER";
|
||||
|
||||
public static final String RIGHT_EYE_BOTTOM_BOUNDARY = "RIGHT_EYE_BOTTOM_BOUNDARY";
|
||||
|
||||
public static final String RIGHT_EYE_RIGHT_CORNER = "RIGHT_EYE_RIGHT_CORNER";
|
||||
|
||||
public static final String RIGHT_EYE_TOP_BOUNDARY = "RIGHT_EYE_TOP_BOUNDARY";
|
||||
|
||||
public static final String LEFT_EYE_LEFT_CORNER = "LEFT_EYE_LEFT_CORNER";
|
||||
|
||||
public static final String LEFT_EYE_BOTTOM_BOUNDARY = "LEFT_EYE_BOTTOM_BOUNDARY";
|
||||
|
||||
public static final String LEFT_EYE_RIGHT_CORNER = "LEFT_EYE_RIGHT_CORNER";
|
||||
|
||||
public static final String LEFT_EYE_TOP_BOUNDARY = "LEFT_EYE_TOP_BOUNDARY";
|
||||
|
||||
public static final String NOSE_BOTTOM_CENTER = "NOSE_BOTTOM_CENTER";
|
||||
|
||||
public static final String NOSE_BOTTOM_LEFT = "NOSE_BOTTOM_LEFT";
|
||||
|
||||
public static final String NOSE_BOTTOM_RIGHT = "NOSE_BOTTOM_RIGHT";
|
||||
|
||||
public static final String MOUTH_CENTER = "MOUTH_CENTER";
|
||||
|
||||
public static final String MOUTH_RIGHT = "MOUTH_RIGHT";
|
||||
|
||||
public static final String MOUTH_LEFT = "MOUTH_LEFT";
|
||||
|
||||
public static final String LOWER_LIP = "LOWER_LIP";
|
||||
|
||||
public static final String NOSE_TIP = "NOSE_TIP";
|
||||
|
||||
public static final String MIDPOINT_BETWEEN_EYES = "MIDPOINT_BETWEEN_EYES";
|
||||
|
||||
public static final String RIGHT_OF_RIGHT_EYEBROW = "RIGHT_OF_RIGHT_EYEBROW";
|
||||
|
||||
public static final String LEFT_OF_RIGHT_EYEBROW = "LEFT_OF_RIGHT_EYEBROW";
|
||||
|
||||
public static final String RIGHT_OF_LEFT_EYEBROW = "RIGHT_OF_LEFT_EYEBROW";
|
||||
|
||||
public static final String LEFT_OF_LEFT_EYEBROW = "LEFT_OF_LEFT_EYEBROW";
|
||||
|
||||
public static final String RIGHT_EYE = "RIGHT_EYE";
|
||||
|
||||
public static final String LEFT_EYE = "LEFT_EYE";
|
||||
|
||||
public static final String UPPER_LIP = "UPPER_LIP";
|
||||
|
||||
private Point B_TOP_LEFT;
|
||||
|
||||
private Point B_TOP_RIGHT;
|
||||
|
||||
private Point B_BOTTOM_LEFT;
|
||||
|
||||
private Point B_BOTTOM_RIGHT;
|
||||
|
||||
private Point EBL_L;
|
||||
|
||||
private Point EBL_M;
|
||||
|
||||
private Point EBL_R;
|
||||
|
||||
private Point EBR_L;
|
||||
|
||||
private Point EBR_R;
|
||||
|
||||
private Point EBR_M;
|
||||
|
||||
private Point EL_L;
|
||||
|
||||
private Point EL_T;
|
||||
|
||||
private Point EL_R;
|
||||
|
||||
private Point EL_B;
|
||||
|
||||
private Point EL_C;
|
||||
|
||||
private Point ER_L;
|
||||
|
||||
private Point ER_T;
|
||||
|
||||
private Point ER_R;
|
||||
|
||||
private Point ER_B;
|
||||
|
||||
private Point ER_C;
|
||||
|
||||
private Point E_C;
|
||||
|
||||
private Point EA_L;
|
||||
|
||||
private Point EA_R;
|
||||
|
||||
private Point FORH;
|
||||
|
||||
private Point N_T;
|
||||
|
||||
private Point N_LB;
|
||||
|
||||
private Point N_CB;
|
||||
|
||||
private Point N_RB;
|
||||
|
||||
private Point M_L;
|
||||
|
||||
private Point M_C;
|
||||
|
||||
private Point M_R;
|
||||
|
||||
private Point L_T;
|
||||
|
||||
private Point L_B;
|
||||
|
||||
private Point CK_L;
|
||||
|
||||
private Point CK_R;
|
||||
|
||||
private Point CH;
|
||||
|
||||
private Point CH_L;
|
||||
|
||||
private Point CH_R;
|
||||
|
||||
public static final long PROP = 6400L;
|
||||
|
||||
private double scaleFactor = -1.0D;
|
||||
|
||||
public Point getEBL_L() {
|
||||
return this.EBL_L;
|
||||
}
|
||||
|
||||
public void setEBL_L(Point eBL_L) {
|
||||
this.EBL_L = eBL_L;
|
||||
}
|
||||
|
||||
public Point getEBL_M() {
|
||||
return this.EBL_M;
|
||||
}
|
||||
|
||||
public void setEBL_M(Point eBL_M) {
|
||||
this.EBL_M = eBL_M;
|
||||
}
|
||||
|
||||
public Point getEBL_R() {
|
||||
return this.EBL_R;
|
||||
}
|
||||
|
||||
public void setEBL_R(Point eBL_R) {
|
||||
this.EBL_R = eBL_R;
|
||||
}
|
||||
|
||||
public Point getEBR_L() {
|
||||
return this.EBR_L;
|
||||
}
|
||||
|
||||
public void setEBR_L(Point eBR_L) {
|
||||
this.EBR_L = eBR_L;
|
||||
}
|
||||
|
||||
public Point getEBR_R() {
|
||||
return this.EBR_R;
|
||||
}
|
||||
|
||||
public void setEBR_R(Point eBR_R) {
|
||||
this.EBR_R = eBR_R;
|
||||
}
|
||||
|
||||
public Point getEBR_M() {
|
||||
return this.EBR_M;
|
||||
}
|
||||
|
||||
public void setEBR_M(Point eBR_M) {
|
||||
this.EBR_M = eBR_M;
|
||||
}
|
||||
|
||||
public Point getEL_L() {
|
||||
return this.EL_L;
|
||||
}
|
||||
|
||||
public void setEL_L(Point eL_L) {
|
||||
this.EL_L = eL_L;
|
||||
}
|
||||
|
||||
public Point getEL_T() {
|
||||
return this.EL_T;
|
||||
}
|
||||
|
||||
public void setEL_T(Point eL_T) {
|
||||
this.EL_T = eL_T;
|
||||
}
|
||||
|
||||
public Point getEL_R() {
|
||||
return this.EL_R;
|
||||
}
|
||||
|
||||
public void setEL_R(Point eL_R) {
|
||||
this.EL_R = eL_R;
|
||||
}
|
||||
|
||||
public Point getEL_B() {
|
||||
return this.EL_B;
|
||||
}
|
||||
|
||||
public void setEL_B(Point eL_B) {
|
||||
this.EL_B = eL_B;
|
||||
}
|
||||
|
||||
public Point getEL_C() {
|
||||
return this.EL_C;
|
||||
}
|
||||
|
||||
public void setEL_C(Point eL_C) {
|
||||
this.EL_C = eL_C;
|
||||
}
|
||||
|
||||
public Point getER_L() {
|
||||
return this.ER_L;
|
||||
}
|
||||
|
||||
public void setER_L(Point eR_L) {
|
||||
this.ER_L = eR_L;
|
||||
}
|
||||
|
||||
public Point getER_T() {
|
||||
return this.ER_T;
|
||||
}
|
||||
|
||||
public void setER_T(Point eR_T) {
|
||||
this.ER_T = eR_T;
|
||||
}
|
||||
|
||||
public Point getER_R() {
|
||||
return this.ER_R;
|
||||
}
|
||||
|
||||
public void setER_R(Point eR_R) {
|
||||
this.ER_R = eR_R;
|
||||
}
|
||||
|
||||
public Point getER_B() {
|
||||
return this.ER_B;
|
||||
}
|
||||
|
||||
public void setER_B(Point eR_B) {
|
||||
this.ER_B = eR_B;
|
||||
}
|
||||
|
||||
public Point getER_C() {
|
||||
return this.ER_C;
|
||||
}
|
||||
|
||||
public void setER_C(Point eR_C) {
|
||||
this.ER_C = eR_C;
|
||||
}
|
||||
|
||||
public Point getE_C() {
|
||||
return this.E_C;
|
||||
}
|
||||
|
||||
public void setE_C(Point e_C) {
|
||||
this.E_C = e_C;
|
||||
}
|
||||
|
||||
public Point getEA_L() {
|
||||
return this.EA_L;
|
||||
}
|
||||
|
||||
public void setEA_L(Point eA_L) {
|
||||
this.EA_L = eA_L;
|
||||
}
|
||||
|
||||
public Point getEA_R() {
|
||||
return this.EA_R;
|
||||
}
|
||||
|
||||
public void setEA_R(Point eA_R) {
|
||||
this.EA_R = eA_R;
|
||||
}
|
||||
|
||||
public Point getFORH() {
|
||||
return this.FORH;
|
||||
}
|
||||
|
||||
public void setFORH(Point fORH) {
|
||||
this.FORH = fORH;
|
||||
}
|
||||
|
||||
public Point getN_T() {
|
||||
return this.N_T;
|
||||
}
|
||||
|
||||
public void setN_T(Point n_T) {
|
||||
this.N_T = n_T;
|
||||
}
|
||||
|
||||
public Point getN_LB() {
|
||||
return this.N_LB;
|
||||
}
|
||||
|
||||
public void setN_LB(Point n_LB) {
|
||||
this.N_LB = n_LB;
|
||||
}
|
||||
|
||||
public Point getN_CB() {
|
||||
return this.N_CB;
|
||||
}
|
||||
|
||||
public void setN_CB(Point n_CB) {
|
||||
this.N_CB = n_CB;
|
||||
}
|
||||
|
||||
public Point getN_RB() {
|
||||
return this.N_RB;
|
||||
}
|
||||
|
||||
public void setN_RB(Point n_RB) {
|
||||
this.N_RB = n_RB;
|
||||
}
|
||||
|
||||
public Point getM_L() {
|
||||
return this.M_L;
|
||||
}
|
||||
|
||||
public void setM_L(Point m_L) {
|
||||
this.M_L = m_L;
|
||||
}
|
||||
|
||||
public Point getM_C() {
|
||||
return this.M_C;
|
||||
}
|
||||
|
||||
public void setM_C(Point m_C) {
|
||||
this.M_C = m_C;
|
||||
}
|
||||
|
||||
public Point getM_R() {
|
||||
return this.M_R;
|
||||
}
|
||||
|
||||
public void setM_R(Point m_R) {
|
||||
this.M_R = m_R;
|
||||
}
|
||||
|
||||
public Point getL_T() {
|
||||
return this.L_T;
|
||||
}
|
||||
|
||||
public void setL_T(Point l_T) {
|
||||
this.L_T = l_T;
|
||||
}
|
||||
|
||||
public Point getL_B() {
|
||||
return this.L_B;
|
||||
}
|
||||
|
||||
public void setL_B(Point l_B) {
|
||||
this.L_B = l_B;
|
||||
}
|
||||
|
||||
public Point getCK_L() {
|
||||
return this.CK_L;
|
||||
}
|
||||
|
||||
public void setCK_L(Point cK_L) {
|
||||
this.CK_L = cK_L;
|
||||
}
|
||||
|
||||
public Point getCK_R() {
|
||||
return this.CK_R;
|
||||
}
|
||||
|
||||
public void setCK_R(Point cK_R) {
|
||||
this.CK_R = cK_R;
|
||||
}
|
||||
|
||||
public Point getCH() {
|
||||
return this.CH;
|
||||
}
|
||||
|
||||
public void setCH(Point cH) {
|
||||
this.CH = cH;
|
||||
}
|
||||
|
||||
public Point getCH_L() {
|
||||
return this.CH_L;
|
||||
}
|
||||
|
||||
public void setCH_L(Point cH_L) {
|
||||
this.CH_L = cH_L;
|
||||
}
|
||||
|
||||
public Point getCH_R() {
|
||||
return this.CH_R;
|
||||
}
|
||||
|
||||
public void setCH_R(Point cH_R) {
|
||||
this.CH_R = cH_R;
|
||||
}
|
||||
|
||||
public Point getB_TOP_LEFT() {
|
||||
return this.B_TOP_LEFT;
|
||||
}
|
||||
|
||||
public void setB_TOP_LEFT(Point b_TOP_LEFT) {
|
||||
this.B_TOP_LEFT = b_TOP_LEFT;
|
||||
}
|
||||
|
||||
public Point getB_TOP_RIGHT() {
|
||||
return this.B_TOP_RIGHT;
|
||||
}
|
||||
|
||||
public void setB_TOP_RIGHT(Point b_TOP_RIGTH) {
|
||||
this.B_TOP_RIGHT = b_TOP_RIGTH;
|
||||
}
|
||||
|
||||
public Point getB_BOTTOM_RIGHT() {
|
||||
return this.B_BOTTOM_RIGHT;
|
||||
}
|
||||
|
||||
private void setScaleFactor(double scaleFactor) {
|
||||
this.scaleFactor = scaleFactor;
|
||||
}
|
||||
|
||||
public double getScaleFactor() {
|
||||
if (this.scaleFactor < 0.0D && getEA_L() != null && getEA_R() != null) {
|
||||
double width = Point.getDistance(getEA_L(), getEA_R());
|
||||
DoubleOperator dop = new DoubleOperator(6400.0F);
|
||||
dop.setScale(6, RoundingMode.UNNECESSARY);
|
||||
dop.divide(width);
|
||||
setScaleFactor(dop.getResult());
|
||||
}
|
||||
return this.scaleFactor;
|
||||
}
|
||||
|
||||
public Point getB_BOTTOM_LEFT() {
|
||||
return this.B_BOTTOM_LEFT;
|
||||
}
|
||||
|
||||
public void setB_BOTTOM_LEFT(Point b_BOTTOM_LEFT) {
|
||||
this.B_BOTTOM_LEFT = b_BOTTOM_LEFT;
|
||||
}
|
||||
|
||||
public void setB_BOTTOM_RIGHT(Point b_BOTTOM_RIGHT) {
|
||||
this.B_BOTTOM_RIGHT = b_BOTTOM_RIGHT;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ResParm;
|
||||
|
||||
public interface FaceLabel {
|
||||
String getFullFaceImgPath();
|
||||
|
||||
String getLabelMd5();
|
||||
|
||||
String getPettorale();
|
||||
|
||||
long getLabel();
|
||||
|
||||
void findByMd5(String paramString);
|
||||
|
||||
long getNumberOfLabelsByLabel(long paramLong);
|
||||
|
||||
void setLabelCount(long paramLong);
|
||||
|
||||
long getLabelCount();
|
||||
|
||||
ResParm superSave();
|
||||
}
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class FaceRecog extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1686063087766L;
|
||||
|
||||
private long id_faceRecog;
|
||||
|
||||
private long id_fotoFace1;
|
||||
|
||||
private long id_fotoFace2;
|
||||
|
||||
private double eDistance;
|
||||
|
||||
private double cosineSim;
|
||||
|
||||
private double confidenceLBPH;
|
||||
|
||||
private double confidenceEigen;
|
||||
|
||||
private double confidenceFish;
|
||||
|
||||
private FotoFace fotoFace1;
|
||||
|
||||
private FotoFace fotoFace2;
|
||||
|
||||
public FaceRecog(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecog() {}
|
||||
|
||||
public void setId_faceRecog(long newId_faceRecog) {
|
||||
this.id_faceRecog = newId_faceRecog;
|
||||
}
|
||||
|
||||
public void setId_fotoFace1(long newId_fotoFace1) {
|
||||
this.id_fotoFace1 = newId_fotoFace1;
|
||||
setFotoFace1(null);
|
||||
}
|
||||
|
||||
public void setId_fotoFace2(long newId_fotoFace2) {
|
||||
this.id_fotoFace2 = newId_fotoFace2;
|
||||
setFotoFace2(null);
|
||||
}
|
||||
|
||||
public void setEDistance(double newEDistance) {
|
||||
this.eDistance = newEDistance;
|
||||
}
|
||||
|
||||
public void setCosineSim(double newCosineSim) {
|
||||
this.cosineSim = newCosineSim;
|
||||
}
|
||||
|
||||
public long getId_faceRecog() {
|
||||
return this.id_faceRecog;
|
||||
}
|
||||
|
||||
public long getId_fotoFace1() {
|
||||
return this.id_fotoFace1;
|
||||
}
|
||||
|
||||
public long getId_fotoFace2() {
|
||||
return this.id_fotoFace2;
|
||||
}
|
||||
|
||||
public double getEDistance() {
|
||||
return this.eDistance;
|
||||
}
|
||||
|
||||
public double getCosineSim() {
|
||||
return this.cosineSim;
|
||||
}
|
||||
|
||||
public void setFotoFace1(FotoFace newFotoFace1) {
|
||||
this.fotoFace1 = newFotoFace1;
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace1() {
|
||||
this.fotoFace1 = (FotoFace)getSecondaryObject(this.fotoFace1, FotoFace.class, getId_fotoFace1());
|
||||
return this.fotoFace1;
|
||||
}
|
||||
|
||||
public void setFotoFace2(FotoFace newFotoFace2) {
|
||||
this.fotoFace2 = newFotoFace2;
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace2() {
|
||||
this.fotoFace2 = (FotoFace)getSecondaryObject(this.fotoFace2, FotoFace.class, getId_fotoFace2());
|
||||
return this.fotoFace2;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FaceRecog> findByCR(FaceRecogCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOG AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void findByFotoFace1FotoFace2(long id_fotoFace1, long id_fotoFace2) {
|
||||
try {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOG AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("id_fotoFace1=" + id_fotoFace1);
|
||||
wc.addWc("id_fotoFace2=" + id_fotoFace2);
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
if (getId_faceRecog() == 0L) {
|
||||
wc = new WcString();
|
||||
wc.addWc("id_fotoFace2=" + id_fotoFace1);
|
||||
wc.addWc("id_fotoFace1=" + id_fotoFace2);
|
||||
stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceRecog> findByFoto1Foto2(long l_id_foto1, long l_id_foto2) {
|
||||
try {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOG AS A inner join FOTO_FACE B1 on A.id_fotoFace1 =B1.id_fotoFace inner join FOTO_FACE B2 on A.id_fotoFace2 =B2.id_fotoFace ";
|
||||
String s_Sql_Order1 = " order by B2.faceTopVx";
|
||||
String s_Sql_Order2 = " order by B1.faceTopVx";
|
||||
WcString wc1 = new WcString();
|
||||
wc1.addWc("B1.id_foto=" + l_id_foto1);
|
||||
wc1.addWc("B2.id_foto=" + l_id_foto2);
|
||||
WcString wc2 = new WcString();
|
||||
wc2.addWc("B1.id_foto=" + l_id_foto2);
|
||||
wc2.addWc("B2.id_foto=" + l_id_foto1);
|
||||
PreparedStatement stmt = getConn().prepareStatement("(" + s_Sql_Find + wc1.toString() + s_Sql_Order1 + ") ");
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public double getConfidenceLBPH() {
|
||||
return this.confidenceLBPH;
|
||||
}
|
||||
|
||||
public void setConfidenceLBPH(double confidenceLBPH) {
|
||||
this.confidenceLBPH = confidenceLBPH;
|
||||
}
|
||||
|
||||
public double getConfidenceEigen() {
|
||||
return this.confidenceEigen;
|
||||
}
|
||||
|
||||
public void setConfidenceEigen(double confidenceEigen) {
|
||||
this.confidenceEigen = confidenceEigen;
|
||||
}
|
||||
|
||||
public double getConfidenceFish() {
|
||||
return this.confidenceFish;
|
||||
}
|
||||
|
||||
public void setConfidenceFish(double confidenceFish) {
|
||||
this.confidenceFish = confidenceFish;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FaceRecogCR extends CRAdapter {
|
||||
private static final long serialVersionUID = -7003605836256739892L;
|
||||
|
||||
private long id_faceRecog;
|
||||
|
||||
private long id_fotoFace1;
|
||||
|
||||
private long id_fotoFace2;
|
||||
|
||||
private double eDistance;
|
||||
|
||||
private double cosineSim;
|
||||
|
||||
private FotoFace fotoFace1;
|
||||
|
||||
private FotoFace fotoFace2;
|
||||
|
||||
public FaceRecogCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecogCR() {}
|
||||
|
||||
public void setId_faceRecog(long newId_faceRecog) {
|
||||
this.id_faceRecog = newId_faceRecog;
|
||||
}
|
||||
|
||||
public void setId_fotoFace1(long newId_fotoFace1) {
|
||||
this.id_fotoFace1 = newId_fotoFace1;
|
||||
setFotoFace1(null);
|
||||
}
|
||||
|
||||
public void setId_fotoFace2(long newId_fotoFace2) {
|
||||
this.id_fotoFace2 = newId_fotoFace2;
|
||||
setFotoFace2(null);
|
||||
}
|
||||
|
||||
public void setEDistance(double newEDistance) {
|
||||
this.eDistance = newEDistance;
|
||||
}
|
||||
|
||||
public void setCosineSim(double newCosineSim) {
|
||||
this.cosineSim = newCosineSim;
|
||||
}
|
||||
|
||||
public long getId_faceRecog() {
|
||||
return this.id_faceRecog;
|
||||
}
|
||||
|
||||
public long getId_fotoFace1() {
|
||||
return this.id_fotoFace1;
|
||||
}
|
||||
|
||||
public long getId_fotoFace2() {
|
||||
return this.id_fotoFace2;
|
||||
}
|
||||
|
||||
public double getEDistance() {
|
||||
return this.eDistance;
|
||||
}
|
||||
|
||||
public double getCosineSim() {
|
||||
return this.cosineSim;
|
||||
}
|
||||
|
||||
public void setFotoFace1(FotoFace newFotoFace1) {
|
||||
this.fotoFace1 = newFotoFace1;
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace1() {
|
||||
this.fotoFace1 = (FotoFace)getSecondaryObject(this.fotoFace1, FotoFace.class,
|
||||
|
||||
getId_fotoFace1());
|
||||
return this.fotoFace1;
|
||||
}
|
||||
|
||||
public void setFotoFace2(FotoFace newFotoFace2) {
|
||||
this.fotoFace2 = newFotoFace2;
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace2() {
|
||||
this.fotoFace2 = (FotoFace)getSecondaryObject(this.fotoFace2, FotoFace.class,
|
||||
|
||||
getId_fotoFace2());
|
||||
return this.fotoFace2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.face.api.FaceRecognitionApiResult;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class FaceRecognizer extends it.acxent.dm.FaceRecognizer implements Serializable {
|
||||
private static final long serialVersionUID = 1701089333600L;
|
||||
|
||||
public FaceRecognizer(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecognizer() {}
|
||||
|
||||
public Vectumerator<FaceRecognizer> findByCR(FaceRecognizerCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public ResParm resetInvioTraining() {
|
||||
FotoFace fotoFace = new FotoFace(getApFull());
|
||||
ResParm rp = fotoFace.resetTsTraingFace();
|
||||
if (getId_faceRecognizer() == 0L)
|
||||
return new ResParm(false, "Errore! id nullo");
|
||||
FaceRecognitionApi fra = new FaceRecognitionApi(getApFull());
|
||||
FaceRecognitionApiResult fraRes = fra.__resetTraining(getId_faceRecognizer());
|
||||
FotoFace.threadBuildRecognizer = false;
|
||||
StatusMsg.deleteAllMsg(getApFull());
|
||||
rp.appendMsg(fraRes.getMsg());
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import java.sql.Date;
|
||||
|
||||
public class FaceRecognizerCR extends CRAdapter {
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private String flgTIpo;
|
||||
|
||||
private String codice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private String sessionId;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private long nTrainingImages;
|
||||
|
||||
private Date dataTraining;
|
||||
|
||||
public FaceRecognizerCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecognizerCR() {}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFlgTIpo(String newFlgTIpo) {
|
||||
this.flgTIpo = newFlgTIpo;
|
||||
}
|
||||
|
||||
public void setCodice(String newCodice) {
|
||||
this.codice = newCodice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setSessionId(String newSessionId) {
|
||||
this.sessionId = newSessionId;
|
||||
}
|
||||
|
||||
public void setFileName(String newFileName) {
|
||||
this.fileName = newFileName;
|
||||
}
|
||||
|
||||
public void setNTrainingImages(long newNTrainingImages) {
|
||||
this.nTrainingImages = newNTrainingImages;
|
||||
}
|
||||
|
||||
public void setDataTraining(Date newDataTraining) {
|
||||
this.dataTraining = newDataTraining;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public String getFlgTIpo() {
|
||||
return (this.flgTIpo == null) ? "" : this.flgTIpo.trim();
|
||||
}
|
||||
|
||||
public String getCodice() {
|
||||
return (this.codice == null) ? "" : this.codice.trim();
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return (this.sessionId == null) ? "" : this.sessionId.trim();
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return (this.fileName == null) ? "" : this.fileName.trim();
|
||||
}
|
||||
|
||||
public long getNTrainingImages() {
|
||||
return this.nTrainingImages;
|
||||
}
|
||||
|
||||
public Date getDataTraining() {
|
||||
return this.dataTraining;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,253 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.face.api.FaceRecognitionApiResult;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Base64;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class FaceRemota extends DBAdapter implements Serializable, FaceLabel {
|
||||
private static final long serialVersionUID = 1705956570841L;
|
||||
|
||||
private long id_faceRemota;
|
||||
|
||||
private long label;
|
||||
|
||||
private String labelMd5;
|
||||
|
||||
private long labelCount;
|
||||
|
||||
public FaceRemota(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRemota() {}
|
||||
|
||||
public void setId_faceRemota(long newId_faceRemota) {
|
||||
this.id_faceRemota = newId_faceRemota;
|
||||
}
|
||||
|
||||
public void setLabelMd5(String newMd5) {
|
||||
this.labelMd5 = newMd5;
|
||||
}
|
||||
|
||||
public long getId_faceRemota() {
|
||||
return this.id_faceRemota;
|
||||
}
|
||||
|
||||
public String getLabelMd5() {
|
||||
return (this.labelMd5 == null) ? "" : this.labelMd5.trim();
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FaceRemota> findByCR(FaceRemotaCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_REMOTA AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setLabel(long label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getFullFaceImgPath() {
|
||||
return getFullFileName();
|
||||
}
|
||||
|
||||
public void findByLabel(long l_label) {
|
||||
String s_Sql_Find = "select A.* from FACE_REMOTA AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.label=" + l_label);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
if (getId_faceRemota() > 0L)
|
||||
return;
|
||||
ResParm rp = new ResParm();
|
||||
FaceRecognitionApi fra = new FaceRecognitionApi(getApFull());
|
||||
FaceRecognitionApiResult frar = fra.__reqImage(l_label, "");
|
||||
if (!frar.isOk()) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore!. Label non trovata: " + frar.getMsg());
|
||||
} else {
|
||||
try {
|
||||
JSONObject jResponse = (JSONObject)frar.getResult();
|
||||
String l_md5 = jResponse.getString("labelMd5");
|
||||
setLabel(l_label);
|
||||
setLabelMd5(l_md5);
|
||||
rp = superSave();
|
||||
if (rp.getStatus()) {
|
||||
StringBuilder err = new StringBuilder();
|
||||
String imageContent = jResponse.getJSONObject("image")
|
||||
.getString("content");
|
||||
File path = new File(getPathFaceImg());
|
||||
if (!path.exists())
|
||||
path.mkdirs();
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(imageContent);
|
||||
File file = new File(getFullFileName());
|
||||
if (!file.exists()) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(decodedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
err.append("Impossibile salvare l'immagine md5 " + getLabelMd5() + ". " + e.getMessage());
|
||||
err.append("\n");
|
||||
} finally {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
if (err.length() > 0)
|
||||
handleDebug(err.toString());
|
||||
} else {
|
||||
handleDebug(rp.getErrMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getNumberOfLabelsByLabel(long l_label) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public void setLabelCount(long l_labelCount) {
|
||||
this.labelCount = l_labelCount;
|
||||
}
|
||||
|
||||
public long getLabelCount() {
|
||||
return this.labelCount;
|
||||
}
|
||||
|
||||
public ResParm superSave() {
|
||||
return save();
|
||||
}
|
||||
|
||||
public String getPettorale() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void findByMd5(String l_md5) {
|
||||
String s_Sql_Find = "select A.* from FACE_REMOTA AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.labelMd5='" + l_md5 + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
if (getId_faceRemota() > 0L)
|
||||
return;
|
||||
ResParm rp = new ResParm();
|
||||
FaceRecognitionApi fra = new FaceRecognitionApi(getApFull());
|
||||
FaceRecognitionApiResult frar = fra.__reqImage(0L, l_md5);
|
||||
if (!frar.isOk()) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore!. Label non trovata: " + frar.getMsg());
|
||||
} else {
|
||||
try {
|
||||
JSONObject jResponse = (JSONObject)frar.getResult();
|
||||
long l_label = jResponse.getLong("label");
|
||||
setLabel(l_label);
|
||||
setLabelMd5(l_md5);
|
||||
rp = superSave();
|
||||
if (rp.getStatus()) {
|
||||
StringBuilder err = new StringBuilder();
|
||||
String imageContent = jResponse.getJSONObject("image")
|
||||
.getString("content");
|
||||
File path = new File(getPathFaceImg());
|
||||
if (!path.exists())
|
||||
path.mkdirs();
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(imageContent);
|
||||
File file = new File(getFullFileName());
|
||||
if (!file.exists()) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(decodedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
err.append("Impossibile salvare l'immagine md5 " + getLabelMd5() + ". " + e.getMessage());
|
||||
err.append("\n");
|
||||
} finally {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
if (err.length() > 0)
|
||||
handleDebug(err.toString());
|
||||
} else {
|
||||
handleDebug(rp.getErrMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFullFileName() {
|
||||
return getPathFaceImg() + getPathFaceImg() + ".jpg";
|
||||
}
|
||||
|
||||
public String getPathFaceImg() {
|
||||
return getParm("PATHFACES_REMOTO").getTesto() + getParm("PATHFACES_REMOTO").getTesto();
|
||||
}
|
||||
|
||||
public String getPathIdStepDir() {
|
||||
if (getPathIdStep() <= 0L)
|
||||
return "";
|
||||
if (getId_faceRemota() == 0L)
|
||||
System.out.println("getPathIdStepDir pio");
|
||||
return "_" + getPathIdStep() * (getId_faceRemota() / getPathIdStep() + 1L) + "/";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FaceRemotaCR extends CRAdapter {
|
||||
private long id_faceRemota;
|
||||
|
||||
private String md5;
|
||||
|
||||
public FaceRemotaCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRemotaCR() {}
|
||||
|
||||
public void setId_faceRemota(long newId_faceRemota) {
|
||||
this.id_faceRemota = newId_faceRemota;
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public long getId_faceRemota() {
|
||||
return this.id_faceRemota;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,867 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class FaceScore extends _FaceAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1725875012792L;
|
||||
|
||||
private long id_faceScore;
|
||||
|
||||
private long id_foto;
|
||||
|
||||
private long id_fotoFace;
|
||||
|
||||
private long id_fotoFace2;
|
||||
|
||||
private long id_selfie;
|
||||
|
||||
private float score;
|
||||
|
||||
private float scoreSelfie;
|
||||
|
||||
private Foto foto;
|
||||
|
||||
private FotoFace fotoFace;
|
||||
|
||||
private FotoFace fotoFace2;
|
||||
|
||||
private Selfie selfie;
|
||||
|
||||
public static final int TIPO_FOTO_FACE_1 = 1;
|
||||
|
||||
public static final int TIPO_FOTO_SELFIE_2 = 2;
|
||||
|
||||
public static final int TIPO_FACE_FACE_3 = 3;
|
||||
|
||||
public FaceScore(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public String getTargetMd5ByMd5(String l_md5) {
|
||||
String s_sql = "select A.* from FACE_SCORE AS A INNER JOIN FOTO_FACE AS B ON A.id_fotoFace2=B.id_fotoFace";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("B.md5='" + l_md5 + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_sql + s_sql);
|
||||
findFirstRecord(stmt);
|
||||
if (getId_faceScore() > 0L)
|
||||
return getFotoFace().getMd5();
|
||||
return l_md5;
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return l_md5;
|
||||
}
|
||||
}
|
||||
|
||||
public FaceScore() {}
|
||||
|
||||
public void setId_faceScore(long newId_faceScore) {
|
||||
this.id_faceScore = newId_faceScore;
|
||||
}
|
||||
|
||||
public void setId_foto(long newId_foto) {
|
||||
this.id_foto = newId_foto;
|
||||
setFoto(null);
|
||||
}
|
||||
|
||||
public void setId_fotoFace(long newId_fotoFace) {
|
||||
this.id_fotoFace = newId_fotoFace;
|
||||
setFotoFace(null);
|
||||
}
|
||||
|
||||
public void setId_selfie(long newId_selfie) {
|
||||
this.id_selfie = newId_selfie;
|
||||
setSelfie(null);
|
||||
}
|
||||
|
||||
public void setScore(float newScore) {
|
||||
this.score = newScore;
|
||||
}
|
||||
|
||||
public long getId_faceScore() {
|
||||
return this.id_faceScore;
|
||||
}
|
||||
|
||||
public long getId_foto() {
|
||||
return this.id_foto;
|
||||
}
|
||||
|
||||
public long getId_fotoFace() {
|
||||
return this.id_fotoFace;
|
||||
}
|
||||
|
||||
public long getId_selfie() {
|
||||
return this.id_selfie;
|
||||
}
|
||||
|
||||
public float getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public String getScorePerc() {
|
||||
String result = String.format("%.2f", getScore() * 100.0F).replace('.', ',') + "%";
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setFoto(Foto newFoto) {
|
||||
this.foto = newFoto;
|
||||
}
|
||||
|
||||
public Foto getFoto() {
|
||||
this.foto = (Foto)getSecondaryObject(this.foto, Foto.class, getId_foto());
|
||||
return this.foto;
|
||||
}
|
||||
|
||||
public void setFotoFace(FotoFace newFotoFace) {
|
||||
this.fotoFace = newFotoFace;
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace() {
|
||||
this.fotoFace = (FotoFace)getSecondaryObject(this.fotoFace, FotoFace.class, getId_fotoFace());
|
||||
return this.fotoFace;
|
||||
}
|
||||
|
||||
public void setSelfie(Selfie newSelfie) {
|
||||
this.selfie = newSelfie;
|
||||
}
|
||||
|
||||
public Selfie getSelfie() {
|
||||
this.selfie = (Selfie)getSecondaryObject(this.selfie, Selfie.class, getId_selfie());
|
||||
return this.selfie;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FaceScore> findByCR(FaceScoreCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findByFoto(long l_id_foto) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
String s_Sql_Find2 = "select A.* from FACE_SCORE AS A inner join FOTO_FACE as B on A.id_fotoFace=B.id_fotoFace";
|
||||
String s_Sql_Find3 = "select A.* from FACE_SCORE AS A inner join FOTO_FACE as B on A.id_fotoFace2=B.id_fotoFace";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_foto=" + l_id_foto);
|
||||
WcString wc2 = new WcString();
|
||||
wc2.addWc("A.id_foto is null ");
|
||||
wc2.addWc("B.id_foto=" + l_id_foto);
|
||||
WcString wc3 = new WcString();
|
||||
wc3.addWc("A.id_foto is null ");
|
||||
wc3.addWc("B.id_foto=" + l_id_foto);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + " union " +
|
||||
wc.toString() + s_Sql_Find2 + " union " + wc2.toString() + s_Sql_Find3);
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findBySelfieEvento(long l_id_selfie, long l_id_evento) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_selfie=" + l_id_selfie);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void findBySelfieFoto(long l_id_selfie, long l_id_foto) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_foto=" + l_id_foto);
|
||||
wc.addWc("A.id_selfie=" + l_id_selfie);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findBySelfieFace(long l_id_selfie, long l_id_fotoFace) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace2=" + l_id_fotoFace);
|
||||
wc.addWc("A.id_selfie=" + l_id_selfie);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findByFaceFoto(long l_id_fotoFace, long l_id_foto) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_foto=" + l_id_foto);
|
||||
wc.addWc("A.id_fotoFace=" + l_id_fotoFace);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findByFaceFace(long l_id_fotoFace, long l_id_fotoFace2) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace=" + l_id_fotoFace);
|
||||
wc.addWc("A.id_fotoFace2=" + l_id_fotoFace2);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public FotoFace findFotoFaceTargetByFace(long l_id_fotoFace) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
FaceScore bean = new FaceScore(getApFull());
|
||||
wc.addWc("A.id_fotoFace2=" + l_id_fotoFace);
|
||||
wc.addWc("(A.id_selfie=0 or A.id_selfie is null)");
|
||||
wc.addWc("(A.id_foto=0 or A.id_foto is null)");
|
||||
DBAdapter.printDebug(true, s_Sql_Find + s_Sql_Find);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
bean.findFirstRecord(stmt);
|
||||
if (bean.getId_faceScore() > 0L) {
|
||||
DBAdapter.printDebug(true, "RESTITUISCO IL FOTO FACE CHE HO TROVATO SULLO SCORE DI TARGET" + bean.getId_fotoFace());
|
||||
return bean.getFotoFace();
|
||||
}
|
||||
DBAdapter.printDebug(true, "RESTITUISCO IL FOTO FACE STESSO " + l_id_fotoFace);
|
||||
FotoFace ff = new FotoFace(getApFull());
|
||||
ff.findByPrimaryKey(l_id_fotoFace);
|
||||
return ff;
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return new FotoFace(getApFull());
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findLegamiByFace(long l_id_fotoFace, int pageNumber, int pageRow) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("(A.id_fotoFace=" + l_id_fotoFace + " or A.id_fotoFace2=" + l_id_fotoFace + ")");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
return findRows(stmt, pageNumber, pageRow);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasLegamiQueryByFace(long l_id_fotoFace) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace2=" + l_id_fotoFace);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
Vectumerator<FaceScore> vec = findRows(stmt, 1, 1);
|
||||
return (vec.getTotNumberOfRecords() >= 1);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFaceLegami(long l_id_fotoFace) {
|
||||
return findLegamiByFace(l_id_fotoFace, 1, 1).hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean isIdFotoOfFace(long l_id_foto) {
|
||||
return (l_id_foto == getFotoFace().getId_foto());
|
||||
}
|
||||
|
||||
public boolean isIdFotoOfFace2(long l_id_foto) {
|
||||
return (l_id_foto == getFotoFace2().getId_foto());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ResParm elaboraScoringResult(JSONObject jo, Evento evento, boolean saveFaceScore) {
|
||||
ResParm rp = new ResParm(true);
|
||||
boolean debug = true;
|
||||
float scoreFoto = -1.0F;
|
||||
HashSet<FaceScore> hsFs = new HashSet<>();
|
||||
double scoreThresold = evento.getScoreThresold();
|
||||
double scoreThresoldSelfieSearch = evento.getScoreThresoldSelfieSearch();
|
||||
double scoreThresoldCurrent = scoreThresold;
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD1:\n" + jo.toString(4));
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
try {
|
||||
if (!jo.getBoolean("success")) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(jo.getString("msg"));
|
||||
} else {
|
||||
Selfie selfie = new Selfie(getApFull());
|
||||
FotoFace fotoFace = new FotoFace(getApFull());
|
||||
Foto foto = new Foto(getApFull());
|
||||
String md5Target = jo.getJSONObject("target").getString("md5");
|
||||
String typeTarget = jo.getJSONObject("target").getString("type");
|
||||
String md5Foto = "";
|
||||
String typeQuery = "";
|
||||
long l_id_fotoFace = 0L;
|
||||
long l_id_selfie = 0L;
|
||||
if (typeTarget.equals("selfie")) {
|
||||
selfie.findByMd5(md5Target);
|
||||
l_id_selfie = selfie.getId_selfie();
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD2: selfie:" + l_id_selfie);
|
||||
} else {
|
||||
fotoFace.findByMd5(md5Target);
|
||||
l_id_fotoFace = fotoFace.getId_fotoFace();
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD3: fotoFace:" + l_id_fotoFace);
|
||||
}
|
||||
if (l_id_fotoFace == 0L && l_id_selfie == 0L) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore! target " + typeTarget + " con md5 " + md5Target + " NON trovato!");
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD4: target con md5 " + md5Target + " NON trovato!");
|
||||
} else {
|
||||
JSONArray jsonResponseA = jo.getJSONArray("responses");
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD5: inizio ciclo:\n" + jsonResponseA.toString());
|
||||
for (int i = 0; i < jsonResponseA.length(); i++) {
|
||||
md5Foto = jsonResponseA.getJSONObject(i).getString("md5");
|
||||
scoreFoto = jsonResponseA.getJSONObject(i).getFloat("score");
|
||||
typeQuery = jsonResponseA.getJSONObject(i).getString("type");
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD6: md5Foto" + md5Foto + " scoreFoto:" + scoreFoto);
|
||||
if (typeQuery.equals("photo")) {
|
||||
foto.findByMd5(md5Foto);
|
||||
if (foto.getId_foto() == 0L) {
|
||||
errMsg.append("Foto md5 " + md5Foto + " NON TROVATA!");
|
||||
errMsg.append("\n");
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD7: Foto md5 " + md5Foto + " NON TROVATA!");
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD8: md5Foto" + md5Foto + " scoreFoto:" + scoreFoto + " TROVATA:" +
|
||||
foto.getFileName());
|
||||
FaceScore fs = new FaceScore(getApFull());
|
||||
if (typeTarget.equals("selfie")) {
|
||||
scoreThresoldCurrent = scoreThresoldSelfieSearch;
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD9: target:selfie query:foto");
|
||||
fs.findBySelfieFoto(l_id_selfie, foto.getId_foto());
|
||||
} else {
|
||||
scoreThresoldCurrent = scoreThresold;
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD10: target:face query:foto");
|
||||
fs.findByFaceFoto(l_id_fotoFace, foto.getId_foto());
|
||||
}
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD11:J_ATTRIBUTE_TYPE_VALUE_PHOTO score:" + scoreFoto + " scoreThresoldCurrent " + scoreThresoldCurrent);
|
||||
if ((double)scoreFoto >= scoreThresoldCurrent) {
|
||||
fs.setId_foto(foto.getId_foto());
|
||||
fs.setId_selfie(l_id_selfie);
|
||||
fs.setId_fotoFace(l_id_fotoFace);
|
||||
fs.setScore(scoreFoto);
|
||||
if (saveFaceScore) {
|
||||
rp = fs.save();
|
||||
if (rp.getStatus())
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD12: fs salvata: rp:" + rp.getMsg());
|
||||
} else {
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD12bis: fs NON salvata: rp:" + rp.getMsg());
|
||||
}
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD13: fs NON salvata: SCORE:" + scoreFoto + " < DI " + scoreThresold + " rp:" +
|
||||
rp.getMsg());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fotoFace.findByMd5(md5Foto);
|
||||
if (fotoFace.getId_fotoFace() == 0L) {
|
||||
errMsg.append("FotoFace md5 " + md5Foto + " NON TROVATA!");
|
||||
errMsg.append("\n");
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD14: FotoFace md5 " + md5Foto + " NON TROVATA!");
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD15: md5Foto" + md5Foto + " scoreFoto:" + scoreFoto + " TROVATA:" +
|
||||
foto.getFileName());
|
||||
FaceScore fs = new FaceScore(getApFull());
|
||||
if (typeTarget.equals("selfie")) {
|
||||
scoreThresoldCurrent = scoreThresoldSelfieSearch;
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD16: target:selfie query:face ");
|
||||
fs.findBySelfieFace(l_id_selfie, fotoFace.getId_fotoFace());
|
||||
} else {
|
||||
scoreThresoldCurrent = scoreThresold;
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD17: target:face query:face ");
|
||||
fs.findByFaceFace(l_id_fotoFace, fotoFace.getId_fotoFace());
|
||||
}
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD18:J_ATTRIBUTE_TYPE_VALUE_PHOTO score:" + scoreFoto + " scoreThresoldCurrent " + scoreThresoldCurrent);
|
||||
if ((double)scoreFoto >= scoreThresoldCurrent) {
|
||||
fs.setId_foto(foto.getId_foto());
|
||||
fs.setId_selfie(l_id_selfie);
|
||||
fs.setId_fotoFace(l_id_fotoFace);
|
||||
fs.setId_fotoFace2(fotoFace.getId_fotoFace());
|
||||
fs.setScore(scoreFoto);
|
||||
rp.setReturnObj(Float.valueOf(scoreFoto));
|
||||
if (saveFaceScore) {
|
||||
rp = fs.save();
|
||||
if (rp.getStatus())
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD19: fs salvata: rp:" + rp.getMsg());
|
||||
} else {
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD19bis: fs NON salvata: rp:" + rp.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(e);
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD20: ex:" + rp.getMsg());
|
||||
}
|
||||
rp.setReturnObj(hsFs);
|
||||
DBAdapter.printDebug(debug, "elaboraScoringResultOLD21: fine:" + rp.getMsg());
|
||||
return rp;
|
||||
}
|
||||
|
||||
public long getId_fotoFace2() {
|
||||
return this.id_fotoFace2;
|
||||
}
|
||||
|
||||
public void setId_fotoFace2(long id_fotoFace2) {
|
||||
this.id_fotoFace2 = id_fotoFace2;
|
||||
setFotoFace2(null);
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace2() {
|
||||
this.fotoFace2 = (FotoFace)getSecondaryObject(this.fotoFace2, FotoFace.class, getId_fotoFace2());
|
||||
return this.fotoFace2;
|
||||
}
|
||||
|
||||
public void setFotoFace2(FotoFace fotoFace2) {
|
||||
this.fotoFace2 = fotoFace2;
|
||||
}
|
||||
|
||||
public ResParm save() {
|
||||
if (getId_fotoFace() != 0L && getId_fotoFace2() != 0L && getId_fotoFace() == getId_fotoFace2()) {
|
||||
System.out.println("FaceScore.... Errore: fatoface 1 e 2 uguali!!!!");
|
||||
return new ResParm(false, "Errore: fatoface 1 e 2 uguali!!!!");
|
||||
}
|
||||
return super.save();
|
||||
}
|
||||
|
||||
public String getTargetMd5(long l_idFotoFace) {
|
||||
if (getId_selfie() > 0L)
|
||||
return getSelfie().getMd5();
|
||||
if (l_idFotoFace == 0L || getId_fotoFace() != l_idFotoFace)
|
||||
return getFotoFace().getMd5();
|
||||
return getFotoFace2().getMd5();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getTargetMd5() {
|
||||
return getTargetMd5(0L);
|
||||
}
|
||||
|
||||
public int getDescrizioneTipoInt() {
|
||||
if (getId_selfie() > 0L)
|
||||
return 2;
|
||||
if (getId_foto() > 0L && getId_fotoFace() > 0L)
|
||||
return 1;
|
||||
if (getId_fotoFace2() > 0L && getId_fotoFace() > 0L)
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getDescrizioneTipo() {
|
||||
switch (getDescrizioneTipoInt()) {
|
||||
case 2:
|
||||
return "Selfie su foto";
|
||||
case 1:
|
||||
return "Face su foto";
|
||||
case 3:
|
||||
return "Face su Face Foto";
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findTargetByPuntiFoto(HashSet<Long> hsPuntiFoto) {
|
||||
String s_Sql_Find = "select distinct A.id_fotoFace,C.fileName from FACE_SCORE AS A inner join FOTO_FACE as B on A.id_fotoFace=B.id_fotoFace INNER JOIN FOTO AS C ON C.id_foto=B.id_foto";
|
||||
String s_Sql_Order = " order by C.fileName";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace2>0");
|
||||
StringBuilder sb = new StringBuilder("(");
|
||||
for (Long pf : hsPuntiFoto) {
|
||||
if (sb.length() > 2)
|
||||
sb.append(" or ");
|
||||
sb.append("C.id_puntoFoto=" + pf);
|
||||
}
|
||||
sb.append(")");
|
||||
wc.addWc(sb.toString());
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
System.out.println("findTargetByPuntiFoto hashtable: " + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findTargetByPuntofoto(long l_id_puntoFoto) {
|
||||
String s_Sql_Find = "select distinct A.id_fotoFace,C.fileName from FACE_SCORE AS A inner join FOTO_FACE as B on A.id_fotoFace=B.id_fotoFace INNER JOIN FOTO AS C ON C.id_foto=B.id_foto";
|
||||
String s_Sql_Order = " order by C.fileName";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace2>0");
|
||||
wc.addWc("C.id_puntoFoto=" + l_id_puntoFoto);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findTargetByEvento(long l_id_evento, long l_flgFaceScoringDone) {
|
||||
boolean debug = true;
|
||||
String s_Sql_Find = "select distinct A.id_fotoFace,C.fileName, D.pathRelativoFoto from FACE_SCORE AS A inner join FOTO_FACE as B on A.id_fotoFace=B.id_fotoFace INNER JOIN FOTO AS C ON C.id_foto=B.id_foto inner join PUNTO_FOTO AS D ON C.id_puntoFoto=D.id_puntofoto";
|
||||
String s_Sql_Order = " order by D.pathRelativoFoto,C.fileName";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace2>0");
|
||||
wc.addWc("C.id_evento=" + l_id_evento);
|
||||
if (l_flgFaceScoringDone == 0L) {
|
||||
wc.addWc("(C.flgFaceScoringDone=0 or C.flgFaceScoringDone is null)");
|
||||
} else if (l_flgFaceScoringDone > 0L) {
|
||||
wc.addWc("C.flgFaceScoringDone=" + l_flgFaceScoringDone);
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
DBAdapter.printDebug(debug, "findTargetByEvento: " + s_Sql_Find + wc.toString() + s_Sql_Order);
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findTargetByPuntofotoNFace(long l_id_puntoFoto, String l_fileName, long nFacceDopo) {
|
||||
String s_Sql_Find = "select distinct A.id_fotoFace,C.fileName from FACE_SCORE AS A inner join FOTO_FACE as B on A.id_fotoFace=B.id_fotoFace INNER JOIN FOTO AS C ON C.id_foto=B.id_foto";
|
||||
String s_Sql_Order = " order by C.fileName limit " + nFacceDopo;
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace2>0");
|
||||
wc.addWc("C.id_puntoFoto=" + l_id_puntoFoto);
|
||||
wc.addWc("C.fileName>'" + l_fileName + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ResParm unisciTarget(long l_id_fotoFaceTargetMain, long l_id_fotoFaceTarget, float scoring) {
|
||||
FaceScore fs = new FaceScore(getApFull());
|
||||
fs.setId_fotoFace(l_id_fotoFaceTargetMain);
|
||||
fs.setId_fotoFace2(l_id_fotoFaceTarget);
|
||||
fs.setScore(scoring);
|
||||
ResParm rp = fs.save();
|
||||
if (rp.getStatus()) {
|
||||
String sqlUpdate = "update FACE_SCORE set id_fotoFace=" + l_id_fotoFaceTargetMain + " where id_fotoFace=" + l_id_fotoFaceTarget;
|
||||
rp = update(sqlUpdate);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public ResParm unisciTarget(long l_id_fotoFaceTargetMain, long l_id_fotoFaceTarget) {
|
||||
String sqlUpdate = "update FACE_SCORE set id_fotoFace=" + l_id_fotoFaceTargetMain + " where id_fotoFace=" + l_id_fotoFaceTarget;
|
||||
ResParm rp = update(sqlUpdate);
|
||||
return rp;
|
||||
}
|
||||
|
||||
public long getTotoFaceScoreByEvento(long l_id_evento) {
|
||||
String sql = "select count(*) as tot from FACE_SCORE AS A INNER JOIN FOTO_FACE AS B ON A.id_fotoFace=B.id_fotoFace INNER JOIN FOTO AS C ON C.id_foto=B.id_foto where C.id_evento=" + l_id_evento;
|
||||
return (long)getTots(sql);
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScore> findQueryByFace(long l_id_fotoFace, int pageNumber, int pageRow) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE AS A";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_fotoFace2>0");
|
||||
wc.addWc("A.id_fotoFace=" + l_id_fotoFace);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
return findRows(stmt, pageNumber, pageRow);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public ResParm elaboraScoringResultGson(JsonObject jo, Evento evento, boolean saveFaceScore) {
|
||||
ResParm rp = new ResParm(true);
|
||||
String tag = DBAdapter.getTimeNameForFileUpload();
|
||||
boolean debug = false;
|
||||
boolean debug2 = false;
|
||||
float scoreFoto = -1.0F;
|
||||
HashSet<FaceScore> hsFs = new HashSet<>();
|
||||
double scoreThresold = evento.getScoreThresold();
|
||||
double scoreThresoldSelfieSearch = evento.getScoreThresoldSelfieSearch();
|
||||
double scoreThresoldCurrent = scoreThresold;
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson0 start:");
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson1:\n" + tag);
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
try {
|
||||
if (!jo.get("success").getAsBoolean()) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(jo.get("msg").getAsString());
|
||||
} else {
|
||||
Selfie selfie = new Selfie(getApFull());
|
||||
FotoFace fotoFace = new FotoFace(getApFull());
|
||||
Foto foto = new Foto(getApFull());
|
||||
JsonObject targetObject = jo.getAsJsonObject("target");
|
||||
String md5Target = targetObject.get("md5").getAsString();
|
||||
String typeTarget = targetObject.get("type").getAsString();
|
||||
String md5Foto = "";
|
||||
String typeQuery = "";
|
||||
long l_id_fotoFaceTarget = 0L;
|
||||
long l_id_selfie = 0L;
|
||||
if (typeTarget.equals("selfie")) {
|
||||
selfie.findByMd5(md5Target);
|
||||
l_id_selfie = selfie.getId_selfie();
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson2: selfie:" + tag);
|
||||
} else {
|
||||
fotoFace.findByMd5(md5Target);
|
||||
l_id_fotoFaceTarget = fotoFace.getId_fotoFace();
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson3: fotoFace:" + tag);
|
||||
}
|
||||
if (l_id_fotoFaceTarget == 0L && l_id_selfie == 0L) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore! target " + typeTarget + " con md5 " + md5Target + " NON trovato!");
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson4: target con md5 " + tag + " NON trovato!");
|
||||
} else {
|
||||
JsonArray jsonResponseA = jo.getAsJsonArray("responses");
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson5: inizio ciclo:");
|
||||
for (int i = 0; i < jsonResponseA.size(); i++) {
|
||||
JsonObject jsonResponse = jsonResponseA.get(i).getAsJsonObject();
|
||||
md5Foto = jsonResponse.get("md5").getAsString();
|
||||
scoreFoto = jsonResponse.get("score").getAsFloat();
|
||||
typeQuery = jsonResponse.get("type").getAsString();
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson6: md5Foto " + tag + " scoreFoto:" + md5Foto);
|
||||
if (typeQuery.equals("photo")) {
|
||||
foto.findByMd5(md5Foto);
|
||||
if (foto.getId_foto() == 0L) {
|
||||
errMsg.append("Foto md5 " + md5Foto + " NON TROVATA!");
|
||||
errMsg.append("\n");
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson7: Foto md5 " + tag + " NON TROVATA!");
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson8: md5Foto" + tag + " scoreFoto:" + md5Foto + " TROVATA:" + scoreFoto);
|
||||
FaceScore fs = new FaceScore(getApFull());
|
||||
if (typeTarget.equals("selfie")) {
|
||||
scoreThresoldCurrent = scoreThresoldSelfieSearch;
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson9: target:selfie query:foto");
|
||||
fs.findBySelfieFoto(l_id_selfie, foto.getId_foto());
|
||||
} else {
|
||||
scoreThresoldCurrent = scoreThresold;
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson10: target:face query:foto");
|
||||
fs.findByFaceFoto(l_id_fotoFaceTarget, foto.getId_foto());
|
||||
}
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson11:J_ATTRIBUTE_TYPE_VALUE_PHOTO score:" + tag + " scoreThresoldCurrent " + scoreFoto);
|
||||
if ((double)scoreFoto >= scoreThresoldCurrent) {
|
||||
fs.setId_foto(foto.getId_foto());
|
||||
fs.setId_selfie(l_id_selfie);
|
||||
fs.setId_fotoFace(l_id_fotoFaceTarget);
|
||||
fs.setScore(scoreFoto);
|
||||
if (saveFaceScore) {
|
||||
DBAdapter.printDebug(debug2, tag + " ================== SALVO FACE SCORE SELFIE SU ID_FOTOFACE QUERY FOTO fs desc record\n" + tag + "\nrp:" +
|
||||
|
||||
fs.getDescRecord() + "\n hsFs size: " + rp.getMsg());
|
||||
rp = fs.save();
|
||||
if (rp.getStatus())
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson12: fs salvata: fs desc record\n" + tag + "\nrp:" +
|
||||
fs.getDescRecord() + "\n hsFs size: " + rp.getMsg());
|
||||
} else {
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson12bis: fs NON salvata:desc record\n" + tag + "\nrp:" +
|
||||
fs.getDescRecord() + "\n hsFs size: " + rp.getMsg());
|
||||
}
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson13: fs NON salvata: SCORE:" + tag + " < DI " + scoreFoto + " rp:" + scoreThresold);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fotoFace.findByMd5(md5Foto);
|
||||
if (fotoFace.getId_fotoFace() == 0L) {
|
||||
errMsg.append("FotoFace md5 " + md5Foto + " NON TROVATA!");
|
||||
errMsg.append("\n");
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson14: FotoFace md5 " + tag + " NON TROVATA!");
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson15: md5Foto " + tag + " scoreFoto:" + md5Foto + " TROVATA:" + scoreFoto);
|
||||
FaceScore fs = new FaceScore(getApFull());
|
||||
if (typeTarget.equals("selfie")) {
|
||||
scoreThresoldCurrent = scoreThresoldSelfieSearch;
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson16: target:selfie query:face ");
|
||||
fs.findBySelfieFace(l_id_selfie, fotoFace.getId_fotoFace());
|
||||
} else {
|
||||
scoreThresoldCurrent = scoreThresold;
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson17: target:face query:face targ.:" + tag + " q:" + l_id_fotoFaceTarget);
|
||||
fs.findByFaceFace(l_id_fotoFaceTarget, fotoFace.getId_fotoFace());
|
||||
fs.setId_fotoFace(l_id_fotoFaceTarget);
|
||||
}
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson18:J_ATTRIBUTE_TYPE_VALUE_PHOTO score:" + tag + " scoreThresoldCurrent " + scoreFoto);
|
||||
if ((double)scoreFoto >= scoreThresoldCurrent) {
|
||||
fs.setId_foto(foto.getId_foto());
|
||||
fs.setId_selfie(l_id_selfie);
|
||||
fs.setId_fotoFace2(fotoFace.getId_fotoFace());
|
||||
fs.setScore(scoreFoto);
|
||||
rp.setReturnObj(Float.valueOf(scoreFoto));
|
||||
if (saveFaceScore) {
|
||||
DBAdapter.printDebug(debug2, tag + " ================== SALVO FACE SCORE SELFIE SU ID_FOTOFACE fs desc record\n" + tag + "\nrp:" +
|
||||
|
||||
fs.getDescRecord() + "\n hsFs size: " + rp.getMsg());
|
||||
rp = fs.save();
|
||||
if (rp.getStatus())
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson19: fs salvata: fs desc record\n" + tag + "\nrp:" +
|
||||
fs.getDescRecord() + "\n hsFs size: " + rp.getMsg());
|
||||
} else {
|
||||
hsFs.add(fs);
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson19bis: fs NON salvata:fs salvata: fs desc record\n" + tag + "\nrp:" +
|
||||
|
||||
fs.getDescRecord() + "\n hsFs size: " + rp.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson0 STOP!!:");
|
||||
} catch (Exception e) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(e);
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson20: ex:" + tag);
|
||||
}
|
||||
rp.setReturnObj(hsFs);
|
||||
DBAdapter.printDebug(debug, tag + " elaboraScoringResultGson21: fine:" + tag + "\n hsFs size: " + rp.getMsg());
|
||||
return rp;
|
||||
}
|
||||
|
||||
public void findScoresBySelfieEventoFilenamefoto(long l_id_selfie, long l_id_evento, String l_filenameFoto) {
|
||||
boolean debug = false;
|
||||
String s_Sql_Find = "select A.* from face_score as A INNER JOIN foto_face as B on A.id_fotoFace2=B.id_fotoFace inner join foto as C on C.id_foto =B.id_foto";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_selfie=" + l_id_selfie);
|
||||
wc.addWc("C.id_evento=" + l_id_evento);
|
||||
wc.addWc("C.fileName='" + l_filenameFoto + "'");
|
||||
DBAdapter.printDebug(debug, s_Sql_Find + s_Sql_Find);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
if (getId_faceScore() == 0L) {
|
||||
s_Sql_Find = "select A.* from face_score as A INNER JOIN foto_face as B on A.id_fotoFace2=B.id_fotoFace inner join foto as C on C.id_foto =B.id_foto";
|
||||
wc = new WcString();
|
||||
wc.addWc("C.id_evento=" + l_id_evento);
|
||||
wc.addWc("C.fileName='" + l_filenameFoto + "'");
|
||||
String s_sql_Find2 = "select A.id_fotoFace2 from face_score as A INNER JOIN foto_face as B on A.id_fotoFace2=B.id_fotoFace inner join foto as C on C.id_foto =B.id_foto";
|
||||
WcString wc2 = new WcString();
|
||||
wc2.addWc("A.id_selfie=" + l_id_selfie);
|
||||
wc2.addWc("C.id_evento=" + l_id_evento);
|
||||
wc.addWc("A.id_fotoFace in (" + s_sql_Find2 + wc2.toString() + ")");
|
||||
DBAdapter.printDebug(debug, s_Sql_Find + s_Sql_Find);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
if (getId_faceScore() > 0L) {
|
||||
FaceScore bean = new FaceScore(getApFull());
|
||||
bean.findBySelfieFace(l_id_selfie, getId_fotoFace());
|
||||
setScoreSelfie(bean.getScore());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float getScoreSelfie() {
|
||||
return (this.scoreSelfie == 0.0F) ? getScore() : this.scoreSelfie;
|
||||
}
|
||||
|
||||
public void setScoreSelfie(float scoreSelfie) {
|
||||
this.scoreSelfie = scoreSelfie;
|
||||
}
|
||||
|
||||
public String getScoreSelfiePerc() {
|
||||
if (this.scoreSelfie == 0.0F)
|
||||
return getScorePerc();
|
||||
String result = String.format("%.2f", this.scoreSelfie * 100.0F).replace('.', ',') + "% *";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FaceScoreCR extends CRAdapter {
|
||||
private long id_faceScore;
|
||||
|
||||
private long id_foto;
|
||||
|
||||
private long id_fotoFace;
|
||||
|
||||
private long id_selfie;
|
||||
|
||||
private String score;
|
||||
|
||||
private Foto foto;
|
||||
|
||||
private FotoFace fotoFace;
|
||||
|
||||
private Selfie selfie;
|
||||
|
||||
public FaceScoreCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceScoreCR() {}
|
||||
|
||||
public void setId_faceScore(long newId_faceScore) {
|
||||
this.id_faceScore = newId_faceScore;
|
||||
}
|
||||
|
||||
public void setId_foto(long newId_foto) {
|
||||
this.id_foto = newId_foto;
|
||||
setFoto(null);
|
||||
}
|
||||
|
||||
public void setId_fotoFace(long newId_fotoFace) {
|
||||
this.id_fotoFace = newId_fotoFace;
|
||||
setFotoFace(null);
|
||||
}
|
||||
|
||||
public void setId_selfie(long newId_selfie) {
|
||||
this.id_selfie = newId_selfie;
|
||||
setSelfie(null);
|
||||
}
|
||||
|
||||
public void setScore(String newScore) {
|
||||
this.score = newScore;
|
||||
}
|
||||
|
||||
public long getId_faceScore() {
|
||||
return this.id_faceScore;
|
||||
}
|
||||
|
||||
public long getId_foto() {
|
||||
return this.id_foto;
|
||||
}
|
||||
|
||||
public long getId_fotoFace() {
|
||||
return this.id_fotoFace;
|
||||
}
|
||||
|
||||
public long getId_selfie() {
|
||||
return this.id_selfie;
|
||||
}
|
||||
|
||||
public String getScore() {
|
||||
return (this.score == null) ? "" : this.score.trim();
|
||||
}
|
||||
|
||||
public void setFoto(Foto newFoto) {
|
||||
this.foto = newFoto;
|
||||
}
|
||||
|
||||
public Foto getFoto() {
|
||||
this.foto = (Foto)getSecondaryObject(this.foto, Foto.class,
|
||||
|
||||
getId_foto());
|
||||
return this.foto;
|
||||
}
|
||||
|
||||
public void setFotoFace(FotoFace newFotoFace) {
|
||||
this.fotoFace = newFotoFace;
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace() {
|
||||
this.fotoFace = (FotoFace)getSecondaryObject(this.fotoFace, FotoFace.class,
|
||||
|
||||
getId_fotoFace());
|
||||
return this.fotoFace;
|
||||
}
|
||||
|
||||
public void setSelfie(Selfie newSelfie) {
|
||||
this.selfie = newSelfie;
|
||||
}
|
||||
|
||||
public Selfie getSelfie() {
|
||||
this.selfie = (Selfie)getSecondaryObject(this.selfie, Selfie.class,
|
||||
|
||||
getId_selfie());
|
||||
return this.selfie;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package it.acxent.face;
|
||||
|
||||
public interface FaceScoreTarget {
|
||||
long getId_fotoFace();
|
||||
|
||||
long getId_selfie();
|
||||
|
||||
String getFacePath();
|
||||
|
||||
String getMd5();
|
||||
}
|
||||
|
|
@ -0,0 +1,237 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class FaceScoreZoo extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1733318804428L;
|
||||
|
||||
private static boolean debug = true;
|
||||
|
||||
private long id_faceScoreZoo;
|
||||
|
||||
private String md51;
|
||||
|
||||
private String md52;
|
||||
|
||||
private float score;
|
||||
|
||||
public FaceScoreZoo(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceScoreZoo() {}
|
||||
|
||||
public void setId_faceScoreZoo(long newId_faceScoreZoo) {
|
||||
this.id_faceScoreZoo = newId_faceScoreZoo;
|
||||
}
|
||||
|
||||
public void setMd51(String newMd51) {
|
||||
this.md51 = newMd51;
|
||||
}
|
||||
|
||||
public void setMd52(String newMd52) {
|
||||
this.md52 = newMd52;
|
||||
}
|
||||
|
||||
public void setScore(float newScore) {
|
||||
this.score = newScore;
|
||||
}
|
||||
|
||||
public long getId_faceScoreZoo() {
|
||||
return this.id_faceScoreZoo;
|
||||
}
|
||||
|
||||
public String getMd51() {
|
||||
return (this.md51 == null) ? "" : this.md51.trim();
|
||||
}
|
||||
|
||||
public String getMd52() {
|
||||
return (this.md52 == null) ? "" : this.md52.trim();
|
||||
}
|
||||
|
||||
public float getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public void findByMd512(String l_md51, String l_md52) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE_ZOO AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
String md1 = (l_md51.compareTo(l_md52) < 0) ? l_md51 : l_md52;
|
||||
String md2 = (l_md51.compareTo(l_md52) < 0) ? l_md52 : l_md51;
|
||||
wc.addWc("md51 = '" + md1 + "'");
|
||||
wc.addWc("md52 = '" + md2 + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ResParm save() {
|
||||
if (getMd51().compareTo(getMd52()) > 0) {
|
||||
String temp = getMd51();
|
||||
setMd51(getMd52());
|
||||
setMd52(temp);
|
||||
}
|
||||
return super.save();
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScoreZoo> findByCR(FaceScoreZooCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE_ZOO AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceScoreZoo> findByMd5(String l_md5, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_SCORE_ZOO AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("(A.md51='" + l_md5 + "' or A.md52='" + l_md5 + "')");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public ResParm saveScoreResponse(JsonObject jsonObject) {
|
||||
ResParm rp = new ResParm();
|
||||
String tag = DBAdapter.getTimeNameForFileUpload();
|
||||
try {
|
||||
JsonArray jResponses = new JsonArray();
|
||||
JsonObject target = jsonObject.getAsJsonObject("target");
|
||||
String targetMd5 = target.get("md5").getAsString();
|
||||
FaceScoreZoo fsz = new FaceScoreZoo(getApFull());
|
||||
StringBuilder sbMsg = new StringBuilder();
|
||||
JsonArray responses = jsonObject.getAsJsonArray("responses");
|
||||
DBAdapter.printDebug(tag + " inizio ciclo SAVESCORE response size: " + tag);
|
||||
for (int i = 0; i < responses.size(); i++) {
|
||||
JsonObject response = responses.get(i).getAsJsonObject();
|
||||
String responseMd5 = response.get("md5").getAsString();
|
||||
boolean isDb = response.has("db") ?
|
||||
response.get("db").getAsBoolean() :
|
||||
false;
|
||||
float score = response.get("score").getAsFloat();
|
||||
if (isDb)
|
||||
DBAdapter.printDebug(tag + " findByMd512: isdb: " + tag + " " + isDb + " - " + targetMd5);
|
||||
fsz.findByMd512(targetMd5, responseMd5);
|
||||
if (fsz.getId_faceScoreZoo() == 0L || fsz.getScore() != score) {
|
||||
fsz.setMd51(targetMd5);
|
||||
fsz.setMd52(responseMd5);
|
||||
fsz.setScore(score);
|
||||
rp = fsz.save();
|
||||
if (!rp.getStatus()) {
|
||||
sbMsg.append(rp.getMsg());
|
||||
sbMsg.append("\n");
|
||||
} else {
|
||||
JsonObject jRow = new JsonObject();
|
||||
jRow.addProperty("md5", responseMd5);
|
||||
jRow.addProperty("score", Float.valueOf(fsz.getScore()));
|
||||
jResponses.add((JsonElement)jRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
DBAdapter.printDebug(tag + " ciclo response finito: " + tag);
|
||||
if (sbMsg.length() > 0) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(sbMsg.toString());
|
||||
}
|
||||
rp.setReturnObj(responses);
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug(tag + " EXC saveScoreResponse jo:\n" + tag);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ResParm saveScoreResponseJSON(JSONObject jsonObject) {
|
||||
ResParm rp = new ResParm();
|
||||
try {
|
||||
JSONArray jResponses = new JSONArray();
|
||||
JSONObject target = jsonObject.getJSONObject("target");
|
||||
String targetMd5 = target.getString("md5");
|
||||
FaceScoreZoo fsz = new FaceScoreZoo(getApFull());
|
||||
StringBuilder sbMsg = new StringBuilder();
|
||||
JSONArray responses = jsonObject.getJSONArray("responses");
|
||||
for (int i = 0; i < responses.length(); i++) {
|
||||
JSONObject response = responses.getJSONObject(i);
|
||||
String responseMd5 = response.getString("md5");
|
||||
float score = response.getFloat("score");
|
||||
fsz.findByMd512(targetMd5, responseMd5);
|
||||
if (fsz.getId_faceScoreZoo() == 0L || fsz.getScore() != score) {
|
||||
fsz.setMd51(targetMd5);
|
||||
fsz.setMd52(responseMd5);
|
||||
fsz.setScore(score);
|
||||
rp = fsz.save();
|
||||
if (!rp.getStatus()) {
|
||||
sbMsg.append(rp.getMsg());
|
||||
sbMsg.append("\n");
|
||||
} else {
|
||||
JSONObject jRow = new JSONObject();
|
||||
jRow.put("md5", responseMd5);
|
||||
jRow.put("score", fsz.getScore());
|
||||
jResponses.put(jRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sbMsg.length() > 0) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(sbMsg);
|
||||
}
|
||||
rp.setReturnObj(responses);
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug(debug, "EXC savescoreresponse jo:\n" + jsonObject.toString(4));
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public final ResParm addScoringResponse(JSONObject jo) {
|
||||
ResParm rp = new ResParm();
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FaceScoreZooCR extends CRAdapter {
|
||||
private long id_faceScoreZoo;
|
||||
|
||||
private String md51;
|
||||
|
||||
private String md52;
|
||||
|
||||
private float score;
|
||||
|
||||
public FaceScoreZooCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceScoreZooCR() {}
|
||||
|
||||
public void setId_faceScoreZoo(long newId_faceScoreZoo) {
|
||||
this.id_faceScoreZoo = newId_faceScoreZoo;
|
||||
}
|
||||
|
||||
public void setMd51(String newMd51) {
|
||||
this.md51 = newMd51;
|
||||
}
|
||||
|
||||
public void setMd52(String newMd52) {
|
||||
this.md52 = newMd52;
|
||||
}
|
||||
|
||||
public void setScore(float newScore) {
|
||||
this.score = newScore;
|
||||
}
|
||||
|
||||
public long getId_faceScoreZoo() {
|
||||
return this.id_faceScoreZoo;
|
||||
}
|
||||
|
||||
public String getMd51() {
|
||||
return (this.md51 == null) ? "" : this.md51.trim();
|
||||
}
|
||||
|
||||
public String getMd52() {
|
||||
return (this.md52 == null) ? "" : this.md52.trim();
|
||||
}
|
||||
|
||||
public float getScore() {
|
||||
return this.score;
|
||||
}
|
||||
}
|
||||
2052
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Foto.java
Normal file
2052
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Foto.java
Normal file
File diff suppressed because it is too large
Load diff
486
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/FotoCR.java
Normal file
486
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/FotoCR.java
Normal file
|
|
@ -0,0 +1,486 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class FotoCR extends CRAdapter implements Cloneable {
|
||||
private static final long serialVersionUID = 4318149988984574664L;
|
||||
|
||||
public static final String ATTR_SESS_SELFIE_FACE_FILENAME = "_SELFIE_FACE_FILENAME";
|
||||
|
||||
public static final String ATTR_SESS_SELFIE_FACE_ORIG_FILENAME = "_SELFIE_FACE_ORIG_FILENAME";
|
||||
|
||||
public static final String ATTR_SESS_SELFIE_FOTO = "_SELFIE_FOTO";
|
||||
|
||||
public static final String ATTR_SESS_SELFIE = "selfie";
|
||||
|
||||
public static final long FOTO_OR_FACE_FOTO = 0L;
|
||||
|
||||
public static final long FOTO_OR_FACE_FACE = 1L;
|
||||
|
||||
public static final long ORDER_BY_CONFIDENCE = 9L;
|
||||
|
||||
public static final long ORDER_BY_RAND = 99L;
|
||||
|
||||
public static final String PATH_SELFIE = "_selfie/";
|
||||
|
||||
private long id_foto;
|
||||
|
||||
private long id_fotoSelfie;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String pettorale;
|
||||
|
||||
private String fileNameMd5;
|
||||
|
||||
private String md5;
|
||||
|
||||
private FotoFace fotoFace;
|
||||
|
||||
private FotoI fotoSelfie;
|
||||
|
||||
private Evento evento;
|
||||
|
||||
private long id_evento;
|
||||
|
||||
private long flgIndicizzate = -1L;
|
||||
|
||||
private long id_puntoFoto;
|
||||
|
||||
private PuntoFoto puntoFotoFace;
|
||||
|
||||
private long id_fotoS;
|
||||
|
||||
private long flgVideo = -1L;
|
||||
|
||||
private double percIdx1 = 98.0D;
|
||||
|
||||
private double percIdx2 = 98.0D;
|
||||
|
||||
private double percIdx3 = 98.0D;
|
||||
|
||||
private double percIdx4 = 98.0D;
|
||||
|
||||
private long flgTh;
|
||||
|
||||
private long flgConPettorali = -1L;
|
||||
|
||||
private long flgTrainingOk = -1L;
|
||||
|
||||
private long flgLabelPrincipale = -1L;
|
||||
|
||||
private long flgHasFace = -1L;
|
||||
|
||||
private long label = -1L;
|
||||
|
||||
private long labelSearch = -1L;
|
||||
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private FaceRecognizer faceRecognizer;
|
||||
|
||||
private long flgFotoOrFace = 0L;
|
||||
|
||||
private double confidence = 0.0D;
|
||||
|
||||
private long flgWithFaces = -1L;
|
||||
|
||||
private long flgTrainingInviate = -1L;
|
||||
|
||||
private long flgLabel0 = -1L;
|
||||
|
||||
private long flgFaceScoringDone = -1L;
|
||||
|
||||
private String fileNameFrom;
|
||||
|
||||
private String md5FotoFace;
|
||||
|
||||
private Selfie selfie = null;
|
||||
|
||||
private long id_selfie;
|
||||
|
||||
private String elencoFoto;
|
||||
|
||||
public final String getFaceScoringDone() {
|
||||
return getFaceScoringDone(getFlgFaceScoringDone());
|
||||
}
|
||||
|
||||
public static final String getFaceScoringDone(long l_flgFaceScoringDone) {
|
||||
return Foto.getFaceScoringDone(l_flgFaceScoringDone);
|
||||
}
|
||||
|
||||
public FotoCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FotoCR() {}
|
||||
|
||||
public static final String getFotoOrFace(long l_flgFotoOrFace) {
|
||||
if (l_flgFotoOrFace == 0L)
|
||||
return "Foto";
|
||||
return "Face";
|
||||
}
|
||||
|
||||
public final String getFotoOrFace() {
|
||||
return getFotoOrFace(getFlgFotoOrFace());
|
||||
}
|
||||
|
||||
public void setId_foto(long newId_foto) {
|
||||
this.id_foto = newId_foto;
|
||||
}
|
||||
|
||||
public void setFileName(String newFileName) {
|
||||
this.fileName = newFileName;
|
||||
}
|
||||
|
||||
public void setPettorale(String newPettorali) {
|
||||
this.pettorale = 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 getPettorale() {
|
||||
return (this.pettorale == null) ? "" : this.pettorale.trim();
|
||||
}
|
||||
|
||||
public String getFileNameMd5() {
|
||||
return (this.fileNameMd5 == null) ? "" : this.fileNameMd5.trim();
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
public String getSessionSelfieImage(HttpServletRequest req) {
|
||||
String selfieFileName = (String)req.getSession().getAttribute("_SELFIE_FACE_FILENAME");
|
||||
return (selfieFileName == null) ? AB_EMPTY_STRING : selfieFileName;
|
||||
}
|
||||
|
||||
public FotoFace getFotoFace() {
|
||||
return this.fotoFace;
|
||||
}
|
||||
|
||||
public void setFotoFace(FotoFace fotoFace) {
|
||||
this.fotoFace = fotoFace;
|
||||
}
|
||||
|
||||
public String getSessionSelfieName(HttpServletRequest req) {
|
||||
String selfieFileName = (String)req.getSession().getAttribute("_SELFIE_FACE_ORIG_FILENAME");
|
||||
return (selfieFileName == null) ? AB_EMPTY_STRING : selfieFileName;
|
||||
}
|
||||
|
||||
public long getId_fotoSelfie() {
|
||||
return this.id_fotoSelfie;
|
||||
}
|
||||
|
||||
public void setId_fotoSelfie(long id_fotoSelfie) {
|
||||
this.id_fotoSelfie = id_fotoSelfie;
|
||||
setFotoSelfie(null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FotoI getFotoSelfie() {
|
||||
if (this.fotoSelfie == null && getId_fotoSelfie() > 0L && getApFull() != null) {
|
||||
this.fotoSelfie = new Foto(getApFull());
|
||||
this.fotoSelfie.findByPrimaryKey(getId_fotoSelfie());
|
||||
}
|
||||
return this.fotoSelfie;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setFotoSelfie(FotoI fotoSelfie) {
|
||||
this.fotoSelfie = fotoSelfie;
|
||||
}
|
||||
|
||||
public FotoI getSessionSelfie(HttpServletRequest req) {
|
||||
FotoI selfie = (FotoI)req.getSession().getAttribute("_SELFIE_FOTO");
|
||||
return (selfie == null) ? new Foto(getApFull()) : selfie;
|
||||
}
|
||||
|
||||
public Evento getEvento() {
|
||||
this.evento = (Evento)getSecondaryObject(this.evento, Evento.class, getId_evento());
|
||||
return this.evento;
|
||||
}
|
||||
|
||||
public long getId_evento() {
|
||||
return this.id_evento;
|
||||
}
|
||||
|
||||
public void setEvento(Evento evento) {
|
||||
this.evento = evento;
|
||||
}
|
||||
|
||||
public void setId_evento(long id_evento) {
|
||||
this.id_evento = id_evento;
|
||||
setEvento(null);
|
||||
}
|
||||
|
||||
public long getFlgIndicizzate() {
|
||||
return this.flgIndicizzate;
|
||||
}
|
||||
|
||||
public void setFlgIndicizzate(long flgIndicizzate) {
|
||||
this.flgIndicizzate = flgIndicizzate;
|
||||
}
|
||||
|
||||
public PuntoFoto getPuntoFotoFace() {
|
||||
this.puntoFotoFace = (PuntoFoto)getSecondaryObject(this.puntoFotoFace, PuntoFoto.class, getId_puntoFoto());
|
||||
return this.puntoFotoFace;
|
||||
}
|
||||
|
||||
public long getId_puntoFoto() {
|
||||
return this.id_puntoFoto;
|
||||
}
|
||||
|
||||
public void setId_puntoFoto(long id_puntoFoto) {
|
||||
this.id_puntoFoto = id_puntoFoto;
|
||||
setPuntoFotoFace(null);
|
||||
}
|
||||
|
||||
public void setPuntoFotoFace(PuntoFoto puntoFoto) {
|
||||
this.puntoFotoFace = puntoFoto;
|
||||
}
|
||||
|
||||
public long getId_fotoS() {
|
||||
return this.id_fotoS;
|
||||
}
|
||||
|
||||
public void setId_fotoS(long id_fotoS) {
|
||||
this.id_fotoS = id_fotoS;
|
||||
}
|
||||
|
||||
public long getFlgVideo() {
|
||||
return this.flgVideo;
|
||||
}
|
||||
|
||||
public void setFlgVideo(long flgVideo) {
|
||||
this.flgVideo = flgVideo;
|
||||
}
|
||||
|
||||
public double getPercIdx1() {
|
||||
return this.percIdx1;
|
||||
}
|
||||
|
||||
public void setPercIdx1(double percIdx1) {
|
||||
this.percIdx1 = percIdx1;
|
||||
}
|
||||
|
||||
public double getPercIdx2() {
|
||||
return this.percIdx2;
|
||||
}
|
||||
|
||||
public void setPercIdx2(double percIdx2) {
|
||||
this.percIdx2 = percIdx2;
|
||||
}
|
||||
|
||||
public double getPercIdx3() {
|
||||
return this.percIdx3;
|
||||
}
|
||||
|
||||
public void setPercIdx3(double percIdx3) {
|
||||
this.percIdx3 = percIdx3;
|
||||
}
|
||||
|
||||
public double getPercIdx4() {
|
||||
return this.percIdx4;
|
||||
}
|
||||
|
||||
public void setPercIdx4(double percIdx4) {
|
||||
this.percIdx4 = percIdx4;
|
||||
}
|
||||
|
||||
public long getFlgTh() {
|
||||
return this.flgTh;
|
||||
}
|
||||
|
||||
public void setFlgTh(long flgTh) {
|
||||
this.flgTh = flgTh;
|
||||
}
|
||||
|
||||
public long getFlgConPettorali() {
|
||||
return this.flgConPettorali;
|
||||
}
|
||||
|
||||
public void setFlgConPettorali(long flgConPettorali) {
|
||||
this.flgConPettorali = flgConPettorali;
|
||||
}
|
||||
|
||||
public long getFlgTrainingOk() {
|
||||
return this.flgTrainingOk;
|
||||
}
|
||||
|
||||
public void setFlgTrainingOk(long flgTrainingOk) {
|
||||
this.flgTrainingOk = flgTrainingOk;
|
||||
}
|
||||
|
||||
public long getFlgHasFace() {
|
||||
return this.flgHasFace;
|
||||
}
|
||||
|
||||
public void setFlgHasFace(long flgHasVisi) {
|
||||
this.flgHasFace = flgHasVisi;
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setLabel(long label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public long getLabelSearch() {
|
||||
return this.labelSearch;
|
||||
}
|
||||
|
||||
public void setLabelSearch(long labelSearch) {
|
||||
this.labelSearch = labelSearch;
|
||||
}
|
||||
|
||||
public boolean isRicercaFotoFace() {
|
||||
if (getFlgFotoOrFace() == 1L || this.label == 0L || this.labelSearch == 0L || getFlgTrainingOk() >= 0L)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public void setId_faceRecognizer(long id_faceRecognizer) {
|
||||
this.id_faceRecognizer = id_faceRecognizer;
|
||||
setFaceRecognizer(null);
|
||||
}
|
||||
|
||||
public FaceRecognizer getFaceRecognizer() {
|
||||
this.faceRecognizer = (FaceRecognizer)getSecondaryObject(this.faceRecognizer, FaceRecognizer.class, getId_faceRecognizer());
|
||||
return this.faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFaceRecognizer(FaceRecognizer faceRecognizer) {
|
||||
this.faceRecognizer = faceRecognizer;
|
||||
}
|
||||
|
||||
public long getFlgFotoOrFace() {
|
||||
return this.flgFotoOrFace;
|
||||
}
|
||||
|
||||
public void setFlgFotoOrFace(long flgFotoOrFace) {
|
||||
this.flgFotoOrFace = flgFotoOrFace;
|
||||
}
|
||||
|
||||
public double getConfidence() {
|
||||
return this.confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(double confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public long getFlgLabelPrincipale() {
|
||||
return this.flgLabelPrincipale;
|
||||
}
|
||||
|
||||
public void setFlgLabelPrincipale(long flgLabelPrincipale) {
|
||||
this.flgLabelPrincipale = flgLabelPrincipale;
|
||||
}
|
||||
|
||||
public FotoCR getClone() {
|
||||
try {
|
||||
return (FotoCR)clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public long getFlgWithFaces() {
|
||||
return this.flgWithFaces;
|
||||
}
|
||||
|
||||
public void setFlgWithFaces(long flgWithFaces) {
|
||||
this.flgWithFaces = flgWithFaces;
|
||||
}
|
||||
|
||||
public long getFlgTrainingInviate() {
|
||||
return this.flgTrainingInviate;
|
||||
}
|
||||
|
||||
public void setFlgTrainingInviate(long flgTrainingInviate) {
|
||||
this.flgTrainingInviate = flgTrainingInviate;
|
||||
}
|
||||
|
||||
public long getFlgLabel0() {
|
||||
return this.flgLabel0;
|
||||
}
|
||||
|
||||
public void setFlgLabel0(long flgLabel0) {
|
||||
this.flgLabel0 = flgLabel0;
|
||||
}
|
||||
|
||||
public long getFlgFaceScoringDone() {
|
||||
return this.flgFaceScoringDone;
|
||||
}
|
||||
|
||||
public void setFlgFaceScoringDone(long flgFaceScoringDone) {
|
||||
this.flgFaceScoringDone = flgFaceScoringDone;
|
||||
}
|
||||
|
||||
public String getFileNameFrom() {
|
||||
return (this.fileNameFrom == null) ? AB_EMPTY_STRING : this.fileNameFrom.trim();
|
||||
}
|
||||
|
||||
public void setFileNameFrom(String nomeFileDa) {
|
||||
this.fileNameFrom = nomeFileDa;
|
||||
}
|
||||
|
||||
public String getMd5FotoFace() {
|
||||
return (this.md5FotoFace == null) ? "" : this.md5FotoFace.trim();
|
||||
}
|
||||
|
||||
public void setMd5FotoFace(String md5FotoFace) {
|
||||
this.md5FotoFace = md5FotoFace;
|
||||
}
|
||||
|
||||
public Selfie getSelfie() {
|
||||
this.selfie = (Selfie)getSecondaryObject(this.selfie, Selfie.class, getId_selfie());
|
||||
return this.selfie;
|
||||
}
|
||||
|
||||
public void setSelfie(Selfie selfie) {
|
||||
this.selfie = selfie;
|
||||
}
|
||||
|
||||
public long getId_selfie() {
|
||||
return this.id_selfie;
|
||||
}
|
||||
|
||||
public void setId_selfie(long id_selfie) {
|
||||
this.id_selfie = id_selfie;
|
||||
setSelfie(null);
|
||||
}
|
||||
|
||||
public String getElencoFoto() {
|
||||
return (this.elencoFoto == null) ? AB_EMPTY_STRING : this.elencoFoto.trim();
|
||||
}
|
||||
|
||||
public void setElencoFoto(String elencoFoto) {
|
||||
this.elencoFoto = elencoFoto;
|
||||
}
|
||||
}
|
||||
2589
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/FotoFace.java
Normal file
2589
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/FotoFace.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,288 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class FotoFaceCR extends CRAdapter {
|
||||
private static final long serialVersionUID = -5434086501778653272L;
|
||||
|
||||
private long id_fotoFaceS;
|
||||
|
||||
private long id_foto;
|
||||
|
||||
private Foto foto;
|
||||
|
||||
private long label;
|
||||
|
||||
private long labelSearch;
|
||||
|
||||
private double confidence = 0.0D;
|
||||
|
||||
private Evento evento;
|
||||
|
||||
private long id_evento;
|
||||
|
||||
private String md5;
|
||||
|
||||
private long id_puntoFoto;
|
||||
|
||||
private PuntoFoto puntoFoto;
|
||||
|
||||
private long flgTrainingOk = -1L;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private long flgConPettorali = -1L;
|
||||
|
||||
private long flgIndicizzate = -1L;
|
||||
|
||||
private String pettorale;
|
||||
|
||||
private FaceRecognizer faceRecognizer;
|
||||
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private long flgSoloLabels = -1L;
|
||||
|
||||
private long flgLabelPrincipale = -1L;
|
||||
|
||||
private long flgHasFace = -1L;
|
||||
|
||||
private long labelCount;
|
||||
|
||||
private long flgLock = -1L;
|
||||
|
||||
private long flgTrainingInviate = -1L;
|
||||
|
||||
private long flgTarget = -1L;
|
||||
|
||||
public long getFlgTrainingInviate() {
|
||||
return this.flgTrainingInviate;
|
||||
}
|
||||
|
||||
public void setFlgTrainingInviate(long flgTrainingInviate) {
|
||||
this.flgTrainingInviate = flgTrainingInviate;
|
||||
}
|
||||
|
||||
public FotoFaceCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FotoFaceCR() {}
|
||||
|
||||
public void setId_fotoFaceS(long newId_fotoFace) {
|
||||
this.id_fotoFaceS = newId_fotoFace;
|
||||
}
|
||||
|
||||
public void setId_foto(long newId_foto) {
|
||||
this.id_foto = newId_foto;
|
||||
setFoto(null);
|
||||
}
|
||||
|
||||
public long getId_fotoFaceS() {
|
||||
return this.id_fotoFaceS;
|
||||
}
|
||||
|
||||
public long getId_foto() {
|
||||
return this.id_foto;
|
||||
}
|
||||
|
||||
public void setFoto(Foto newFoto) {
|
||||
this.foto = newFoto;
|
||||
}
|
||||
|
||||
public Foto getFoto() {
|
||||
this.foto = (Foto)getSecondaryObject(this.foto, Foto.class, getId_foto());
|
||||
return this.foto;
|
||||
}
|
||||
|
||||
public Evento getEvento() {
|
||||
this.evento = (Evento)getSecondaryObject(this.evento, Evento.class, getId_evento());
|
||||
return this.evento;
|
||||
}
|
||||
|
||||
public void setId_evento(long id_evento) {
|
||||
this.id_evento = id_evento;
|
||||
setEvento(null);
|
||||
}
|
||||
|
||||
public double getConfidence() {
|
||||
return this.confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(double confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public long getId_puntoFoto() {
|
||||
return this.id_puntoFoto;
|
||||
}
|
||||
|
||||
public void setId_puntoFoto(long id_puntoFoto) {
|
||||
this.id_puntoFoto = id_puntoFoto;
|
||||
setPuntoFoto(null);
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? AB_EMPTY_STRING : this.md5.trim();
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public long getId_evento() {
|
||||
return this.id_evento;
|
||||
}
|
||||
|
||||
public void setEvento(Evento evento) {
|
||||
this.evento = evento;
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setLabel(long label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public long getLabelSearch() {
|
||||
return this.labelSearch;
|
||||
}
|
||||
|
||||
public void setLabelSearch(long labelSearch) {
|
||||
this.labelSearch = labelSearch;
|
||||
}
|
||||
|
||||
public PuntoFoto getPuntoFoto() {
|
||||
this.puntoFoto = (PuntoFoto)getSecondaryObject(this.puntoFoto, PuntoFoto.class, getId_puntoFoto());
|
||||
return this.puntoFoto;
|
||||
}
|
||||
|
||||
public void setPuntoFoto(PuntoFoto puntoFoto) {
|
||||
this.puntoFoto = puntoFoto;
|
||||
}
|
||||
|
||||
public long getFlgTrainingOk() {
|
||||
return this.flgTrainingOk;
|
||||
}
|
||||
|
||||
public void setFlgTrainingOk(long flgTrainingOk) {
|
||||
this.flgTrainingOk = flgTrainingOk;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return (this.fileName == null) ? AB_EMPTY_STRING : this.fileName.trim();
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public long getFlgConPettorali() {
|
||||
return this.flgConPettorali;
|
||||
}
|
||||
|
||||
public void setFlgConPettorali(long flgConPettorali) {
|
||||
this.flgConPettorali = flgConPettorali;
|
||||
}
|
||||
|
||||
public long getFlgIndicizzate() {
|
||||
return this.flgIndicizzate;
|
||||
}
|
||||
|
||||
public void setFlgIndicizzate(long flgIndicizzate) {
|
||||
this.flgIndicizzate = flgIndicizzate;
|
||||
}
|
||||
|
||||
public FotoI getSessionSelfie(HttpServletRequest req) {
|
||||
FotoI selfie = (FotoI)req.getSession().getAttribute("_SELFIE_FOTO");
|
||||
return (selfie == null) ? new Foto(getApFull()) : selfie;
|
||||
}
|
||||
|
||||
public String getSessionSelfieImage(HttpServletRequest req) {
|
||||
String selfieFileName = (String)req.getSession().getAttribute("_SELFIE_FACE_FILENAME");
|
||||
return (selfieFileName == null) ? AB_EMPTY_STRING : selfieFileName;
|
||||
}
|
||||
|
||||
public String getSessionSelfieName(HttpServletRequest req) {
|
||||
String selfieFileName = (String)req.getSession().getAttribute("_SELFIE_FACE_ORIG_FILENAME");
|
||||
return (selfieFileName == null) ? AB_EMPTY_STRING : selfieFileName;
|
||||
}
|
||||
|
||||
public String getPettorale() {
|
||||
return (this.pettorale == null) ? AB_EMPTY_STRING : this.pettorale.trim();
|
||||
}
|
||||
|
||||
public void setPettorale(String pettorale) {
|
||||
this.pettorale = pettorale;
|
||||
}
|
||||
|
||||
public FaceRecognizer getFaceRecognizer() {
|
||||
this.faceRecognizer = (FaceRecognizer)getSecondaryObject(this.faceRecognizer, FaceRecognizer.class, getId_faceRecognizer());
|
||||
return this.faceRecognizer;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFaceRecognizer(FaceRecognizer faceRecognizer) {
|
||||
this.faceRecognizer = faceRecognizer;
|
||||
}
|
||||
|
||||
public void setId_faceRecognizer(long id_faceRecognizer) {
|
||||
this.id_faceRecognizer = id_faceRecognizer;
|
||||
setFaceRecognizer(null);
|
||||
}
|
||||
|
||||
public long getFlgSoloLabels() {
|
||||
return this.flgSoloLabels;
|
||||
}
|
||||
|
||||
public void setFlgSoloLabels(long flgSoloLabels) {
|
||||
this.flgSoloLabels = flgSoloLabels;
|
||||
}
|
||||
|
||||
public long getFlgHasFace() {
|
||||
return this.flgHasFace;
|
||||
}
|
||||
|
||||
public void setFlgHasFace(long flgHasFace) {
|
||||
this.flgHasFace = flgHasFace;
|
||||
}
|
||||
|
||||
public long getFlgLabelPrincipale() {
|
||||
return this.flgLabelPrincipale;
|
||||
}
|
||||
|
||||
public void setFlgLabelPrincipale(long flgLabelPrincipale) {
|
||||
this.flgLabelPrincipale = flgLabelPrincipale;
|
||||
}
|
||||
|
||||
public long getLabelCount() {
|
||||
return this.labelCount;
|
||||
}
|
||||
|
||||
public void setLabelCount(long labelCount) {
|
||||
this.labelCount = labelCount;
|
||||
}
|
||||
|
||||
public long getFlgLock() {
|
||||
return this.flgLock;
|
||||
}
|
||||
|
||||
public void setFlgLock(long flgLock) {
|
||||
this.flgLock = flgLock;
|
||||
}
|
||||
|
||||
public long getFlgTarget() {
|
||||
return this.flgTarget;
|
||||
}
|
||||
|
||||
public void setFlgTarget(long flgTarget) {
|
||||
this.flgTarget = flgTarget;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,886 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.face.api.vision.GoogleVisionApi;
|
||||
import it.acxent.face.api.vision.GoogleVisionResult;
|
||||
import it.acxent.util.DoubleOperator;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.apache.commons.math3.geometry.Vector;
|
||||
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class FotoFaceVision extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1683972032841L;
|
||||
|
||||
private Face face;
|
||||
|
||||
private long id_fotoFace;
|
||||
|
||||
private long id_foto;
|
||||
|
||||
private String jsonData;
|
||||
|
||||
private Foto foto;
|
||||
|
||||
private long faceTopVx;
|
||||
|
||||
private long faceTopVy;
|
||||
|
||||
private long faceBottomVx;
|
||||
|
||||
private long faceBottomVy;
|
||||
|
||||
private String featureVector1;
|
||||
|
||||
private String featureVector2;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String label;
|
||||
|
||||
private String labelDb;
|
||||
|
||||
public FotoFaceVision(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FotoFaceVision() {}
|
||||
|
||||
public void setId_fotoFace(long newId_fotoFace) {
|
||||
this.id_fotoFace = newId_fotoFace;
|
||||
}
|
||||
|
||||
public void setId_foto(long newId_foto) {
|
||||
this.id_foto = newId_foto;
|
||||
setFoto(null);
|
||||
}
|
||||
|
||||
public void setJsonData(String newJsonData) {
|
||||
this.jsonData = newJsonData;
|
||||
}
|
||||
|
||||
public final ResParm loadSelfieByGoogleVision(String fileName) {
|
||||
ResParm rp = new ResParm();
|
||||
try {
|
||||
String GVA_KEY = getParm("GOOGLE_API_KEY_VISION").getTesto();
|
||||
GoogleVisionApi gva = new GoogleVisionApi(GVA_KEY);
|
||||
GoogleVisionResult resF = gva.annotateFaces(fileName);
|
||||
if (resF.isOk()) {
|
||||
rp = loadSelfieByJson((JSONObject)resF.getResult());
|
||||
} else {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(resF.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
rp.setException(e);
|
||||
rp.setStatus(false);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public final ResParm loadSelfieByJson(JSONObject jo) {
|
||||
ResParm rp = new ResParm();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
JSONArray jaResponses = jo.getJSONArray("responses");
|
||||
boolean visiTrovati = false;
|
||||
for (int i = 0; i < jaResponses.length(); i++) {
|
||||
JSONObject joResponse = jaResponses.getJSONObject(i);
|
||||
if (joResponse.has("faceAnnotations")) {
|
||||
visiTrovati = true;
|
||||
JSONArray jaFaceAnnotations = joResponse.getJSONArray("faceAnnotations");
|
||||
if (jaFaceAnnotations.length() > 1) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Trovati duo o piu visi..");
|
||||
} else {
|
||||
JSONObject joFaceAnnotation = jaFaceAnnotations.getJSONObject(0);
|
||||
JSONObject joFace = new JSONObject();
|
||||
JSONObject joFdBoundingPoly = joFaceAnnotation.getJSONObject("fdBoundingPoly");
|
||||
joFace.put("fdBoundingPoly", joFdBoundingPoly);
|
||||
JSONArray jaLandmarks = joFaceAnnotation.getJSONArray("landmarks");
|
||||
joFace.put("landmarks", jaLandmarks);
|
||||
setJsonData(joFace.toString());
|
||||
rp = _loadFotoFaceFromFaceJson(false);
|
||||
if (!rp.getStatus())
|
||||
msg.append("Errore: impossibile caricare fotoface da json per il selfie: " + rp.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!visiTrovati) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Nessun viso trovato!!");
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public long getId_fotoFace() {
|
||||
return this.id_fotoFace;
|
||||
}
|
||||
|
||||
public long getId_foto() {
|
||||
return this.id_foto;
|
||||
}
|
||||
|
||||
public String getJsonData() {
|
||||
return (this.jsonData == null) ? "" : this.jsonData.trim();
|
||||
}
|
||||
|
||||
public void setFoto(Foto newFoto) {
|
||||
this.foto = newFoto;
|
||||
}
|
||||
|
||||
public Foto getFoto() {
|
||||
this.foto = (Foto)getSecondaryObject(this.foto, Foto.class, getId_foto());
|
||||
return this.foto;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FotoFaceVision> findByCR(FotoFaceCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FOTO_FACE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
private ResParm _loadFotoFaceFromFaceJson(boolean salva) {
|
||||
ResParm rp = new ResParm();
|
||||
if (getJsonData().isEmpty()) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Json data vuoto... non sono state trovate facce");
|
||||
} else {
|
||||
this.face = new Face();
|
||||
JSONObject joFace = new JSONObject(getJsonData());
|
||||
JSONObject joFdBoundingPoly = joFace.getJSONObject("fdBoundingPoly");
|
||||
JSONArray jaVertices = joFdBoundingPoly.getJSONArray("vertices");
|
||||
JSONObject joTopLeft = jaVertices.getJSONObject(0);
|
||||
JSONObject joTopRigth = jaVertices.getJSONObject(1);
|
||||
JSONObject joBottomRigth = jaVertices.getJSONObject(2);
|
||||
JSONObject joBottomLeft = jaVertices.getJSONObject(3);
|
||||
try {
|
||||
this.face.setB_TOP_LEFT(new Point(joTopLeft.getLong("x"),
|
||||
joTopLeft.getLong("y")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
this.face.setB_TOP_RIGHT(new Point(joTopRigth.getLong("x"),
|
||||
joTopRigth.getLong("y")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
this.face.setB_BOTTOM_RIGHT(new Point(joBottomRigth.getLong("x"),
|
||||
joBottomRigth.getLong("y")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
this.face.setB_BOTTOM_LEFT(new Point(joBottomLeft.getLong("x"),
|
||||
joBottomLeft.getLong("y")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONArray jaLandmarks = joFace.getJSONArray("landmarks");
|
||||
for (int k = 0; k < jaLandmarks.length(); k++) {
|
||||
JSONObject joLandmark = jaLandmarks.getJSONObject(k);
|
||||
_fillFaceLandmark(this.face, joLandmark);
|
||||
}
|
||||
if (salva) {
|
||||
rp = save();
|
||||
} else {
|
||||
rp.setStatus(true);
|
||||
rp.setMsg("Fotoface creato ma non salvato");
|
||||
}
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public ResParm deleteFotoFaceByFoto(long l_id_foto) {
|
||||
if (getApFull() == null || l_id_foto == 0L)
|
||||
return new ResParm(false, "Errore!! Dati connessione db assenti");
|
||||
return delete("delete from FOTO_FACE WHERE id_foto=" + l_id_foto);
|
||||
}
|
||||
|
||||
public void findFirstByFoto(long l_id_foto) {
|
||||
String s_Sql_Find = "select A.* from FOTO_FACE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_foto=" + l_id_foto);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final void _fillFaceLandmark(Face face, JSONObject joLandmark) {
|
||||
String type = joLandmark.getString("type");
|
||||
JSONObject joPosition = joLandmark.getJSONObject("position");
|
||||
Point currentPoint = new Point(joPosition.getLong("x"),
|
||||
joPosition.getLong("y"), joPosition.getLong("z"));
|
||||
if (type.equals("LEFT_EYE")) {
|
||||
face.setEL_C(currentPoint);
|
||||
} else if (type.equals("RIGHT_EYE")) {
|
||||
face.setER_C(currentPoint);
|
||||
} else if (type.equals("LEFT_OF_LEFT_EYEBROW")) {
|
||||
face.setEBL_L(currentPoint);
|
||||
} else if (type.equals("RIGHT_OF_LEFT_EYEBROW")) {
|
||||
face.setEBL_R(currentPoint);
|
||||
} else if (type.equals("LEFT_OF_RIGHT_EYEBROW")) {
|
||||
face.setEBR_L(currentPoint);
|
||||
} else if (type.equals("RIGHT_OF_RIGHT_EYEBROW")) {
|
||||
face.setEBR_R(currentPoint);
|
||||
} else if (type.equals("MIDPOINT_BETWEEN_EYES")) {
|
||||
face.setE_C(currentPoint);
|
||||
} else if (type.equals("NOSE_TIP")) {
|
||||
face.setN_T(currentPoint);
|
||||
} else if (type.equals("UPPER_LIP")) {
|
||||
face.setL_T(currentPoint);
|
||||
} else if (type.equals("LOWER_LIP")) {
|
||||
face.setL_B(currentPoint);
|
||||
} else if (type.equals("MOUTH_LEFT")) {
|
||||
face.setM_L(currentPoint);
|
||||
} else if (type.equals("MOUTH_RIGHT")) {
|
||||
face.setM_R(currentPoint);
|
||||
} else if (type.equals("MOUTH_CENTER")) {
|
||||
face.setM_C(currentPoint);
|
||||
} else if (type.equals("NOSE_BOTTOM_RIGHT")) {
|
||||
face.setN_RB(currentPoint);
|
||||
} else if (type.equals("NOSE_BOTTOM_LEFT")) {
|
||||
face.setN_LB(currentPoint);
|
||||
} else if (type.equals("NOSE_BOTTOM_CENTER")) {
|
||||
face.setN_CB(currentPoint);
|
||||
} else if (type.equals("LEFT_EYE_TOP_BOUNDARY")) {
|
||||
face.setEL_T(currentPoint);
|
||||
} else if (type.equals("LEFT_EYE_RIGHT_CORNER")) {
|
||||
face.setEL_R(currentPoint);
|
||||
} else if (type.equals("LEFT_EYE_BOTTOM_BOUNDARY")) {
|
||||
face.setEL_B(currentPoint);
|
||||
} else if (type.equals("LEFT_EYE_LEFT_CORNER")) {
|
||||
face.setEL_L(currentPoint);
|
||||
} else if (type.equals("RIGHT_EYE_TOP_BOUNDARY")) {
|
||||
face.setER_T(currentPoint);
|
||||
} else if (type.equals("RIGHT_EYE_RIGHT_CORNER")) {
|
||||
face.setER_R(currentPoint);
|
||||
} else if (type.equals("RIGHT_EYE_BOTTOM_BOUNDARY")) {
|
||||
face.setER_B(currentPoint);
|
||||
} else if (type.equals("RIGHT_EYE_LEFT_CORNER")) {
|
||||
face.setER_L(currentPoint);
|
||||
} else if (type.equals("LEFT_EYEBROW_UPPER_MIDPOINT")) {
|
||||
face.setEBL_M(currentPoint);
|
||||
} else if (type.equals("RIGHT_EYEBROW_UPPER_MIDPOINT")) {
|
||||
face.setEBR_M(currentPoint);
|
||||
} else if (type.equals("LEFT_EAR_TRAGION")) {
|
||||
face.setEA_L(currentPoint);
|
||||
} else if (type.equals("RIGHT_EAR_TRAGION")) {
|
||||
face.setEA_R(currentPoint);
|
||||
} else if (type.equals("FOREHEAD_GLABELLA")) {
|
||||
face.setFORH(currentPoint);
|
||||
} else if (type.equals("CHIN_GNATHION")) {
|
||||
face.setCH(currentPoint);
|
||||
} else if (type.equals("CHIN_LEFT_GONION")) {
|
||||
face.setCH_L(currentPoint);
|
||||
} else if (type.equals("CHIN_RIGHT_GONION")) {
|
||||
face.setCH_R(currentPoint);
|
||||
} else if (type.equals("LEFT_CHEEK_CENTER")) {
|
||||
face.setCK_L(currentPoint);
|
||||
} else if (type.equals("RIGHT_CHEEK_CENTER")) {
|
||||
face.setCK_R(currentPoint);
|
||||
} else {
|
||||
System.out.println("ERRORE!!! Face.fillFaceLandmark tipo non trovato: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public double getCalcFaceIdx1() {
|
||||
DoubleOperator dop = new DoubleOperator();
|
||||
dop.setScale(2, RoundingMode.UNNECESSARY);
|
||||
dop.add(Point.getDistanceNormF(getFace().getEA_L(), getFace().getM_C(), getFace().getScaleFactor()));
|
||||
dop.add(Point.getDistanceNormF(getFace().getEA_R(), getFace().getM_C(), getFace().getScaleFactor()));
|
||||
return dop.getResult();
|
||||
}
|
||||
|
||||
public double getCalcFaceIdx2() {
|
||||
DoubleOperator dop = new DoubleOperator();
|
||||
dop.setScale(2, RoundingMode.UNNECESSARY);
|
||||
dop.add(Point.getDistanceNormF(getFace().getEA_R(), getFace().getN_T(), getFace().getScaleFactor()));
|
||||
dop.add(Point.getDistanceNormF(getFace().getEA_L(), getFace().getN_T(), getFace().getScaleFactor()));
|
||||
dop.add(Point.getDistanceNormF(getFace().getM_C(), getFace().getN_T(), getFace().getScaleFactor()));
|
||||
return dop.getResult();
|
||||
}
|
||||
|
||||
public double getCalcFaceIdx3() {
|
||||
DoubleOperator dop = new DoubleOperator();
|
||||
dop.setScale(2, RoundingMode.UNNECESSARY);
|
||||
dop.add(Point.getDistanceNormF(getFace().getCK_L(), getFace().getCK_R(), getFace().getScaleFactor()));
|
||||
return dop.getResult();
|
||||
}
|
||||
|
||||
public double getCalcFaceIdx4() {
|
||||
DoubleOperator dop = new DoubleOperator();
|
||||
dop.setScale(2, RoundingMode.UNNECESSARY);
|
||||
dop.add(Point.getDistanceNormF(getFace().getEA_R(), getFace().getN_T(), getFace().getScaleFactor()));
|
||||
dop.add(Point.getDistanceNormF(getFace().getEA_L(), getFace().getN_T(), getFace().getScaleFactor()));
|
||||
dop.add(Point.getDistanceNormF(getFace().getM_C(), getFace().getN_T(), getFace().getScaleFactor()));
|
||||
return dop.getResult();
|
||||
}
|
||||
|
||||
public double[] getFaceIdRange(double faceId, double percRange) {
|
||||
DoubleOperator scarto = new DoubleOperator(100.0F);
|
||||
scarto.setScale(2, RoundingMode.UNNECESSARY);
|
||||
scarto.subtract(percRange);
|
||||
scarto.multiply(faceId);
|
||||
scarto.divide(100.0F);
|
||||
DoubleOperator min = new DoubleOperator(faceId);
|
||||
min.subtract(scarto);
|
||||
DoubleOperator max = new DoubleOperator(faceId);
|
||||
max.add(scarto);
|
||||
double[] result = { min.getResult(), max.getResult() };
|
||||
return result;
|
||||
}
|
||||
|
||||
public ResParm save() {
|
||||
String l_labelDb = getLabelDb();
|
||||
if (!getJsonData().isEmpty()) {
|
||||
_createFeatureVectorAll();
|
||||
} else {
|
||||
println("FotoFace: save: " + getFoto().getFileName() + " NO json data on foto face " + getId_fotoFace());
|
||||
}
|
||||
createFaceImage(false);
|
||||
ResParm rp = super.save();
|
||||
if (rp.getStatus())
|
||||
if (!getLabel().equals(l_labelDb))
|
||||
rp.append(getFoto().updatePettoraliByFotoFace(true));
|
||||
return rp;
|
||||
}
|
||||
|
||||
public Face getFace() {
|
||||
if (this.face == null && !getJsonData().isEmpty())
|
||||
_loadFotoFaceFromFaceJson(false);
|
||||
return this.face;
|
||||
}
|
||||
|
||||
public void setFace(Face face) {
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
public ResParm _createFeatureVectorAll() {
|
||||
ResParm rp = new ResParm();
|
||||
List<Double> featureVector = new ArrayList<>();
|
||||
Double faceHeight = Point.getDistance(getFace().getFORH(), getFace().getM_C());
|
||||
Double faceWidth = Point.getDistance(getFace().getEA_L(), getFace().getEA_R());
|
||||
Double eyeDistance = Point.getDistance(getFace().getEL_C(), getFace().getER_C());
|
||||
Double mouthLen = Point.getDistance(getFace().getM_L(), getFace().getM_R());
|
||||
Double nooseLen = Point.getDistance(getFace().getE_C(), getFace().getN_CB());
|
||||
List<Point> points = new ArrayList<>();
|
||||
points.add(getFace().getEL_C());
|
||||
points.add(getFace().getER_C());
|
||||
points.add(getFace().getEA_L());
|
||||
points.add(getFace().getEA_R());
|
||||
points.add(getFace().getEBL_M());
|
||||
points.add(getFace().getEBR_M());
|
||||
points.add(getFace().getCK_L());
|
||||
points.add(getFace().getCK_R());
|
||||
points.add(getFace().getM_C());
|
||||
points.add(getFace().getN_T());
|
||||
points.add(getFace().getE_C());
|
||||
points.add(getFace().getFORH());
|
||||
List<Double> distances = new ArrayList<>();
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
Point p1 = points.get(i);
|
||||
for (int j = i + 1; j < points.size(); j++) {
|
||||
Point p2 = points.get(j);
|
||||
double distance = Point.getDistance(p1, p2);
|
||||
distances.add(Double.valueOf(distance));
|
||||
}
|
||||
}
|
||||
double averageDistance = calculateAverageDistance(distances);
|
||||
featureVector.add(Double.valueOf(averageDistance));
|
||||
Double eyeMouthDistance = Point.getDistance(getFace().getE_C(), getFace().getM_C());
|
||||
featureVector.add(Double.valueOf(eyeMouthDistance / eyeDistance));
|
||||
Double eyeNoseDistance = Point.getDistance(getFace().getE_C(), getFace().getN_T());
|
||||
featureVector.add(Double.valueOf(eyeDistance / eyeNoseDistance));
|
||||
Double eyeChinDistance = Point.getDistance(getFace().getE_C(), getFace().getCH());
|
||||
Double eyeLipCHinDistance = Point.getDistance(getFace().getL_B(), getFace().getCH());
|
||||
featureVector.add(Double.valueOf(eyeDistance / eyeLipCHinDistance));
|
||||
Double eyeLipNooseDistance = Point.getDistance(getFace().getL_T(), getFace().getN_T());
|
||||
featureVector.add(Double.valueOf(eyeDistance / eyeLipNooseDistance));
|
||||
Double eyeEyebrowDistance = Point.getDistance(getFace().getEBL_M(), getFace().getEBR_M());
|
||||
featureVector.add(Double.valueOf(eyeDistance / eyeEyebrowDistance));
|
||||
Point midCheekPoint = new Point((getFace().getCK_L().getX() + getFace().getCK_R().getX()) / 2L, (
|
||||
getFace().getCK_L().getY() + getFace().getCK_R().getY()) / 2L, (
|
||||
getFace().getCK_L().getZ() + getFace().getCK_R().getZ()) / 2L);
|
||||
Double eyeCheekDistance = Point.getDistance(getFace().getE_C(), midCheekPoint);
|
||||
featureVector.add(Double.valueOf(eyeDistance / eyeCheekDistance));
|
||||
featureVector.add(eyeDistance);
|
||||
featureVector.add(eyeEyebrowDistance);
|
||||
Double cheekDistance = Point.getDistance(getFace().getCK_L(), getFace().getCK_R());
|
||||
featureVector.add(cheekDistance);
|
||||
Double mouthCornerDistance = Point.getDistance(getFace().getM_L(), getFace().getM_R());
|
||||
featureVector.add(mouthCornerDistance);
|
||||
Double chinDistance = Point.getDistance(getFace().getCH_L(), getFace().getCH_R());
|
||||
featureVector.add(chinDistance);
|
||||
featureVector.add(faceWidth);
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEL_C(), getFace().getE_C(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEL_C(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEBL_M(), getFace().getEL_C(), getFace().getN_T())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEBR_M(), getFace().getER_C(), getFace().getN_T())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEL_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEBL_L(), getFace().getEBL_M(), getFace().getEBL_R())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEBR_L(), getFace().getEBR_M(), getFace().getEBR_R())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEA_R(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEA_L(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(eyeDistance / faceWidth));
|
||||
Double noseLen = Point.getDistance(getFace().getE_C(), getFace().getN_CB());
|
||||
featureVector.add(Double.valueOf(noseLen / faceHeight));
|
||||
featureVector.add(Double.valueOf(mouthLen / faceWidth));
|
||||
featureVector.add(Double.valueOf(eyeEyebrowDistance / faceWidth));
|
||||
featureVector.add(Double.valueOf(cheekDistance / faceWidth));
|
||||
normalizeFeatureVector(featureVector);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Iterator<Double> iterator = featureVector.iterator(); iterator.hasNext(); ) {
|
||||
double element = iterator.next();
|
||||
sb.append(element);
|
||||
sb.append(",");
|
||||
}
|
||||
setFeatureVector1(sb.toString().substring(1, sb.toString().length() - 1));
|
||||
return rp;
|
||||
}
|
||||
|
||||
public ResParm _createFeatureVectorTop() {
|
||||
ResParm rp = new ResParm();
|
||||
if (getFace() == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(getFoto().getFileName() + ": No json data...");
|
||||
return rp;
|
||||
}
|
||||
List<Double> featureVector = new ArrayList<>();
|
||||
List<Point> points = new ArrayList<>();
|
||||
points.add(getFace().getEL_C());
|
||||
points.add(getFace().getER_C());
|
||||
points.add(getFace().getEA_L());
|
||||
points.add(getFace().getEA_R());
|
||||
points.add(getFace().getCK_L());
|
||||
points.add(getFace().getCK_R());
|
||||
points.add(getFace().getM_C());
|
||||
points.add(getFace().getN_T());
|
||||
List<Double> distances = new ArrayList<>();
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
Point p1 = points.get(i);
|
||||
for (int j = i + 1; j < points.size(); j++) {
|
||||
Point p2 = points.get(j);
|
||||
double distance = Point.getDistance(p1, p2);
|
||||
distances.add(Double.valueOf(distance));
|
||||
}
|
||||
}
|
||||
double averageDistance = calculateAverageDistance(distances);
|
||||
featureVector.add(Double.valueOf(averageDistance));
|
||||
Double eyeDistance = Point.getDistance(getFace().getEL_C(), getFace().getER_C());
|
||||
featureVector.add(eyeDistance);
|
||||
Double eyeMouthDistance = Point.getDistance(getFace().getE_C(), getFace().getM_C());
|
||||
featureVector.add(Double.valueOf(eyeMouthDistance / eyeDistance));
|
||||
Double eyeNoseDistance = Point.getDistance(getFace().getE_C(), getFace().getN_T());
|
||||
featureVector.add(Double.valueOf(eyeDistance / eyeNoseDistance));
|
||||
Double eyeChinDistance = Point.getDistance(getFace().getE_C(), getFace().getCH());
|
||||
Double eyeEyebrowDistance = Point.getDistance(getFace().getEBL_M(), getFace().getEBR_M());
|
||||
Point midCheekPoint = new Point((getFace().getCK_L().getX() + getFace().getCK_R().getX()) / 2L, (
|
||||
getFace().getCK_L().getY() + getFace().getCK_R().getY()) / 2L, (
|
||||
getFace().getCK_L().getZ() + getFace().getCK_R().getZ()) / 2L);
|
||||
Double eyeCheekDistance = Point.getDistance(getFace().getE_C(), midCheekPoint);
|
||||
Double cheekDistance = Point.getDistance(getFace().getCK_L(), getFace().getCK_R());
|
||||
featureVector.add(cheekDistance);
|
||||
Double mouthCornerDistance = Point.getDistance(getFace().getM_L(), getFace().getM_R());
|
||||
Double chinDistance = Point.getDistance(getFace().getCH_L(), getFace().getCH_R());
|
||||
featureVector.add(chinDistance);
|
||||
Double faceWidth = Point.getDistance(getFace().getEA_L(), getFace().getEA_R());
|
||||
featureVector.add(faceWidth);
|
||||
Double faceHeight = Point.getDistance(getFace().getFORH(), getFace().getM_C());
|
||||
featureVector.add(faceHeight);
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEL_C(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEL_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEA_R(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEA_L(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(eyeDistance / faceWidth));
|
||||
Double noseLen = Point.getDistance(getFace().getE_C(), getFace().getN_CB());
|
||||
featureVector.add(Double.valueOf(noseLen / faceHeight));
|
||||
Double mouthLen = Point.getDistance(getFace().getM_L(), getFace().getM_R());
|
||||
featureVector.add(Double.valueOf(cheekDistance / faceWidth));
|
||||
featureVector.add(Double.valueOf(faceHeight / faceWidth));
|
||||
normalizeFeatureVector(featureVector);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Iterator<Double> iterator = featureVector.iterator(); iterator.hasNext(); ) {
|
||||
double element = iterator.next();
|
||||
sb.append(element);
|
||||
sb.append(",");
|
||||
}
|
||||
setFeatureVector1(sb.toString().substring(1, sb.toString().length() - 1));
|
||||
return rp;
|
||||
}
|
||||
|
||||
public static double calculateAngleDeg(Point p1, Point p2, Point p3) {
|
||||
Vector3D v1 = new Vector3D((double)p1.getX(), (double)p1.getY(), (double)p1.getZ());
|
||||
Vector3D v2 = new Vector3D((double)p2.getX(), (double)p2.getY(), (double)p2.getZ());
|
||||
Vector3D v3 = new Vector3D((double)p3.getX(), (double)p3.getY(), (double)p3.getZ());
|
||||
Vector3D v12 = v2.subtract((Vector)v1);
|
||||
Vector3D v23 = v2.subtract((Vector)v3);
|
||||
double angRad = Vector3D.angle(v12, v23);
|
||||
return Math.toDegrees(angRad);
|
||||
}
|
||||
|
||||
public static double calculateAverageDistance(List<Double> distances) {
|
||||
double sum = 0.0D;
|
||||
for (Iterator<Double> iterator = distances.iterator(); iterator.hasNext(); ) {
|
||||
double distance = iterator.next();
|
||||
sum += distance;
|
||||
}
|
||||
return sum / (double)distances.size();
|
||||
}
|
||||
|
||||
public static void normalizeFeatureVector(List<Double> featureVector) {
|
||||
double norm = calculateEuclideanNorm(featureVector);
|
||||
for (int i = 0; i < featureVector.size(); i++)
|
||||
featureVector.set(i, Double.valueOf(featureVector.get(i) / norm));
|
||||
}
|
||||
|
||||
private static double calculateEuclideanNorm(List<Double> vector) {
|
||||
double sumOfSquares = 0.0D;
|
||||
for (Iterator<Double> iterator = vector.iterator(); iterator.hasNext(); ) {
|
||||
double value = iterator.next();
|
||||
sumOfSquares += value * value;
|
||||
}
|
||||
return Math.sqrt(sumOfSquares);
|
||||
}
|
||||
|
||||
public static double calculateDotProduct(List<Double> featureVector1, List<Double> featureVector2) {
|
||||
if (featureVector1.size() != featureVector2.size())
|
||||
return -1.0D;
|
||||
double dotProduct = 0.0D;
|
||||
for (int i = 0; i < featureVector1.size(); i++)
|
||||
dotProduct += featureVector1.get(i) * featureVector2.get(i);
|
||||
return dotProduct;
|
||||
}
|
||||
|
||||
public static double calculateEuclideanDistance(List<Double> featureVector1, List<Double> featureVector2) {
|
||||
if (featureVector1.size() != featureVector2.size()) {
|
||||
System.out.println("calculateEuclideanDistance: " + featureVector1.size() + " " + featureVector2.size());
|
||||
return 99999.0D;
|
||||
}
|
||||
double sumOfSquares = 0.0D;
|
||||
for (int i = 0; i < featureVector1.size(); i++) {
|
||||
double diff = featureVector1.get(i) - featureVector2.get(i);
|
||||
sumOfSquares += diff * diff;
|
||||
}
|
||||
return Math.sqrt(sumOfSquares);
|
||||
}
|
||||
|
||||
public long getFaceTopVx() {
|
||||
if (this.faceTopVx == 0L && getFace() != null)
|
||||
this.faceTopVx = getFace().getB_TOP_RIGHT().getX();
|
||||
return this.faceTopVx;
|
||||
}
|
||||
|
||||
public void setFaceTopVx(long faceTopVx) {
|
||||
this.faceTopVx = faceTopVx;
|
||||
}
|
||||
|
||||
public long getFaceTopVy() {
|
||||
if (this.faceTopVy == 0L && getFace() != null)
|
||||
this.faceTopVy = getFace().getB_TOP_RIGHT().getY();
|
||||
return this.faceTopVy;
|
||||
}
|
||||
|
||||
public void setFaceTopVy(long faceTopVy) {
|
||||
this.faceTopVy = faceTopVy;
|
||||
}
|
||||
|
||||
public long getFaceBottomVx() {
|
||||
if (this.faceBottomVx == 0L && getFace() != null)
|
||||
this.faceBottomVx = getFace().getB_BOTTOM_LEFT().getX();
|
||||
return this.faceBottomVx;
|
||||
}
|
||||
|
||||
public void setFaceBottomVx(long faceBottomVx) {
|
||||
this.faceBottomVx = faceBottomVx;
|
||||
}
|
||||
|
||||
public long getFaceBottomVy() {
|
||||
if (this.faceBottomVy == 0L && getFace() != null)
|
||||
this.faceBottomVy = getFace().getB_BOTTOM_LEFT().getY();
|
||||
return this.faceBottomVy;
|
||||
}
|
||||
|
||||
public void setFaceBottomVy(long faceBottomVy) {
|
||||
this.faceBottomVy = faceBottomVy;
|
||||
}
|
||||
|
||||
public String getFeatureVector1() {
|
||||
return (this.featureVector1 == null) ? "" : this.featureVector1.trim();
|
||||
}
|
||||
|
||||
public void setFeatureVector1(String featureVector1) {
|
||||
this.featureVector1 = featureVector1;
|
||||
}
|
||||
|
||||
public String getFeatureVector2() {
|
||||
return (this.featureVector2 == null) ? "" : this.featureVector2.trim();
|
||||
}
|
||||
|
||||
public void setFeatureVector2(String featureVector2) {
|
||||
this.featureVector2 = featureVector2;
|
||||
}
|
||||
|
||||
public Vectumerator<FotoFaceVision> findByFoto(long l_id_foto) {
|
||||
String s_Sql_Find = "select A.* from FOTO_FACE AS A";
|
||||
String s_Sql_Order = " order by faceTopVx";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_foto=" + l_id_foto);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FotoFaceVision> findByFotoConLabel(long l_id_foto) {
|
||||
String s_Sql_Find = "select A.* from FOTO_FACE AS A";
|
||||
String s_Sql_Order = " order by faceTopVx";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_foto=" + l_id_foto);
|
||||
wc.addWc("(A.label is not null or A.label <>'')");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Double> getFetureVetctor1list() {
|
||||
if (getFeatureVector1().isEmpty())
|
||||
return null;
|
||||
StringTokenizer st = new StringTokenizer(getFeatureVector1(), ",");
|
||||
List<Double> res = new ArrayList<>();
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
res.add(Double.valueOf(Double.parseDouble(token)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public ResParm _createFeatureVectorBottom() {
|
||||
ResParm rp = new ResParm();
|
||||
if (getFace() == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(getFoto().getFileName() + ": No json data...");
|
||||
return rp;
|
||||
}
|
||||
List<Double> featureVector = new ArrayList<>();
|
||||
List<Point> points = new ArrayList<>();
|
||||
points.add(getFace().getEL_C());
|
||||
points.add(getFace().getER_C());
|
||||
points.add(getFace().getEA_L());
|
||||
points.add(getFace().getEA_R());
|
||||
points.add(getFace().getCK_L());
|
||||
points.add(getFace().getCK_R());
|
||||
points.add(getFace().getM_C());
|
||||
points.add(getFace().getN_T());
|
||||
List<Double> distances = new ArrayList<>();
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
Point p1 = points.get(i);
|
||||
for (int j = i + 1; j < points.size(); j++) {
|
||||
Point p2 = points.get(j);
|
||||
double distance = Point.getDistance(p1, p2);
|
||||
distances.add(Double.valueOf(distance));
|
||||
}
|
||||
}
|
||||
double averageDistance = calculateAverageDistance(distances);
|
||||
featureVector.add(Double.valueOf(averageDistance));
|
||||
Double eyeDistance = Point.getDistance(getFace().getEL_C(), getFace().getER_C());
|
||||
featureVector.add(eyeDistance);
|
||||
Double eyeMouthDistance = Point.getDistance(getFace().getE_C(), getFace().getM_C());
|
||||
featureVector.add(Double.valueOf(eyeMouthDistance / eyeDistance));
|
||||
Double eyeNoseDistance = Point.getDistance(getFace().getE_C(), getFace().getN_T());
|
||||
featureVector.add(Double.valueOf(eyeDistance / eyeNoseDistance));
|
||||
Double eyeChinDistance = Point.getDistance(getFace().getE_C(), getFace().getCH());
|
||||
Double eyeEyebrowDistance = Point.getDistance(getFace().getEBL_M(), getFace().getEBR_M());
|
||||
Point midCheekPoint = new Point((getFace().getCK_L().getX() + getFace().getCK_R().getX()) / 2L, (
|
||||
getFace().getCK_L().getY() + getFace().getCK_R().getY()) / 2L, (
|
||||
getFace().getCK_L().getZ() + getFace().getCK_R().getZ()) / 2L);
|
||||
Double eyeCheekDistance = Point.getDistance(getFace().getE_C(), midCheekPoint);
|
||||
Double cheekDistance = Point.getDistance(getFace().getCK_L(), getFace().getCK_R());
|
||||
featureVector.add(cheekDistance);
|
||||
Double mouthCornerDistance = Point.getDistance(getFace().getM_L(), getFace().getM_R());
|
||||
Double chinDistance = Point.getDistance(getFace().getCH_L(), getFace().getCH_R());
|
||||
featureVector.add(chinDistance);
|
||||
Double faceWidth = Point.getDistance(getFace().getEA_L(), getFace().getEA_R());
|
||||
featureVector.add(faceWidth);
|
||||
Double faceHeight = Point.getDistance(getFace().getFORH(), getFace().getM_C());
|
||||
featureVector.add(faceHeight);
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEL_C(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getN_T(), getFace().getM_C())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEL_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEA_R(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getEA_L(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(calculateAngleDeg(getFace().getER_C(), getFace().getM_C(), getFace().getCH())));
|
||||
featureVector.add(Double.valueOf(eyeDistance / faceWidth));
|
||||
Double noseLen = Point.getDistance(getFace().getE_C(), getFace().getN_CB());
|
||||
featureVector.add(Double.valueOf(noseLen / faceHeight));
|
||||
Double mouthLen = Point.getDistance(getFace().getM_L(), getFace().getM_R());
|
||||
featureVector.add(Double.valueOf(cheekDistance / faceWidth));
|
||||
featureVector.add(Double.valueOf(faceHeight / faceWidth));
|
||||
normalizeFeatureVector(featureVector);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Iterator<Double> iterator = featureVector.iterator(); iterator.hasNext(); ) {
|
||||
double element = iterator.next();
|
||||
sb.append(element);
|
||||
sb.append(",");
|
||||
}
|
||||
setFeatureVector1(sb.toString().substring(1, sb.toString().length() - 1));
|
||||
return rp;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
if (this.fileName == null || this.fileName.isEmpty())
|
||||
this
|
||||
.fileName = getFoto().getFileNameReale() + " _" + getFoto().getFileNameReale() + "_tr-" + getId_fotoFace() + "-" + getFaceTopVx() + "_bl-" + getFaceTopVy() + "-" + getFaceBottomVx() + ".jpg";
|
||||
return (this.fileName == null) ? "" : this.fileName.trim();
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return (this.label == null) ? "" : this.label.trim();
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public ResParm createFaceImage(boolean overwrite) {
|
||||
ResParm rp = new ResParm();
|
||||
if (getId_fotoFace() > 0L && hasImageBounds())
|
||||
try {
|
||||
File faceImg = new File(getFullFaceImgPath());
|
||||
if (!faceImg.exists() || overwrite) {
|
||||
if (faceImg.exists())
|
||||
faceImg.delete();
|
||||
BufferedImage sourceImage = ImageIO.read(new File(getFoto().getFileNameFullPath()));
|
||||
int sourceWidth = sourceImage.getWidth();
|
||||
int sourceHeight = sourceImage.getHeight();
|
||||
int margin = 10;
|
||||
int faceTopRightX = (int)getFaceTopVx() + margin;
|
||||
int faceTopRightY = (int)getFaceTopVy() - margin;
|
||||
int faceBottomLeftX = (int)getFaceBottomVx() - margin;
|
||||
int faceBottomLeftY = (int)getFaceBottomVy() + margin;
|
||||
int faceTopLeftX = faceBottomLeftX;
|
||||
int faceTopLeftY = faceTopRightY;
|
||||
int faceBottomRightX = faceTopRightX;
|
||||
int faceBottomRightY = faceBottomLeftY;
|
||||
int faceWidth = faceBottomRightX - faceTopLeftX;
|
||||
int faceHeight = faceBottomRightY - faceTopLeftY;
|
||||
DoubleOperator percW = new DoubleOperator((double)sourceWidth, 4);
|
||||
percW.divide((float)faceWidth);
|
||||
percW.subtract(1);
|
||||
percW.multiply(100);
|
||||
DoubleOperator percH = new DoubleOperator((double)sourceHeight, 4);
|
||||
percH.divide((float)faceHeight);
|
||||
percH.subtract(1);
|
||||
percH.multiply(100);
|
||||
File targetDir = new File(getFoto().getPuntoFoto().getPathCompletoFotoFace());
|
||||
if (!targetDir.exists())
|
||||
targetDir.mkdirs();
|
||||
if (percW.getResult() < 26.0D || percH.getResult() < 26.0D) {
|
||||
DBAdapter.copyFile(getFoto().getFileNameFullPath(), getFullFaceImgPath());
|
||||
} else {
|
||||
BufferedImage faceImage = sourceImage.getSubimage(faceTopLeftX, faceTopLeftY, faceWidth, faceHeight);
|
||||
ImageIO.write(faceImage, "jpg", faceImg);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public String getFullFaceImgPath() {
|
||||
return getFoto().getPuntoFoto().getPathCompletoFotoFace() + "/" + getFoto().getPuntoFoto().getPathCompletoFotoFace();
|
||||
}
|
||||
|
||||
protected void fillFields(ResultSet rst) {
|
||||
super.fillFields(rst);
|
||||
setLabelDb(getLabel());
|
||||
createFaceImage(false);
|
||||
}
|
||||
|
||||
public boolean hasImageBounds() {
|
||||
if (getFaceTopVx() == 0L || getFaceBottomVx() == 0L || getFaceBottomVy() == 0L || getFaceTopVy() == 0L)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getLabelDb() {
|
||||
return (this.labelDb == null) ? "" : this.labelDb.trim();
|
||||
}
|
||||
|
||||
public void setLabelDb(String labelDb) {
|
||||
this.labelDb = labelDb;
|
||||
}
|
||||
|
||||
protected void initFields() {
|
||||
super.initFields();
|
||||
setLabelDb(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.common.Parm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.dm.FaceDetectionMethod;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public interface FotoI {
|
||||
ApplParmFull getApFull();
|
||||
|
||||
long getId_foto();
|
||||
|
||||
String getFileNameFaceRecognition();
|
||||
|
||||
boolean hasFotoFaces();
|
||||
|
||||
long getNumOfFaces();
|
||||
|
||||
ResParm _ricalcolaFotoFaces();
|
||||
|
||||
Parm getParm(String paramString);
|
||||
|
||||
long getFlgFotoSearch();
|
||||
|
||||
Timestamp getTsInserimento();
|
||||
|
||||
String getMd5();
|
||||
|
||||
void setMd5(String paramString);
|
||||
|
||||
void findByPrimaryKey(long paramLong);
|
||||
|
||||
ResParm save();
|
||||
|
||||
long getHeight();
|
||||
|
||||
long getWidth();
|
||||
|
||||
FaceDetectionMethod getFaceDetectionMethodReal();
|
||||
|
||||
long getDimMinFotoFaceReal();
|
||||
|
||||
long getMargineFotoBottom();
|
||||
|
||||
long getMargineFotoTop();
|
||||
|
||||
long getMargineFotoSx();
|
||||
|
||||
long getMargineFotoDx();
|
||||
|
||||
double getDetectFaceConfidentThresold();
|
||||
|
||||
void setId_faceDetectionMethod(long paramLong);
|
||||
|
||||
long getId_faceDetectionMethod();
|
||||
|
||||
long getFaceSize();
|
||||
}
|
||||
|
|
@ -0,0 +1,889 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.anag.Clifor;
|
||||
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.api.vision.GoogleVisionApi;
|
||||
import it.acxent.face.api.vision.GoogleVisionResult;
|
||||
import it.acxent.util.Vectumerator;
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class FotoVision extends DBAdapter implements Serializable, FotoI {
|
||||
private static final long serialVersionUID = 1683972369916L;
|
||||
|
||||
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;
|
||||
|
||||
public static final String DIR_MP4_JPG = DBAdapter.SEPARATOR;
|
||||
|
||||
public FotoVision(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FotoVision() {}
|
||||
|
||||
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 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) {
|
||||
ResParm rp = new ResParm();
|
||||
if (foto.getId_foto() == 0L || foto.getApFull() == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore! Foto non valida");
|
||||
}
|
||||
if (foto.hasFotoFaces());
|
||||
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);
|
||||
boolean usePath = foto.getApFull().getParm("FACE_DETECTION_USE_PATH").isTrue();
|
||||
FaceRecognitionApiResult resF = bean.__detectFaces(foto.getFileNameFaceRecognition(), foto.getMd5(), 99L, true,
|
||||
foto.getDetectFaceConfidentThresold(), usePath);
|
||||
if (resF.isOk())
|
||||
return loadFacesByFaceRecognitionJson(foto, (JSONObject)resF.getResult());
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(resF.getMsg());
|
||||
return rp;
|
||||
}
|
||||
|
||||
public static final ResParm loadFacesByGoogleVisionJson(FotoI foto, JSONObject jo) {
|
||||
ResParm rp = new ResParm();
|
||||
if (foto.getId_foto() == 0L || foto.getApFull() == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore! Foto non valida ");
|
||||
}
|
||||
StringBuilder msg = new StringBuilder();
|
||||
FotoFace ff = new FotoFace(foto.getApFull());
|
||||
ff.deleteFotoFaceByFoto(foto.getId_foto(), true);
|
||||
JSONArray jaResponses = jo.getJSONArray("responses");
|
||||
boolean visiTrovati = false;
|
||||
for (int i = 0; i < jaResponses.length(); i++) {
|
||||
JSONObject joResponse = jaResponses.getJSONObject(i);
|
||||
if (joResponse.has("faceAnnotations")) {
|
||||
visiTrovati = true;
|
||||
JSONArray jaFaceAnnotations = joResponse.getJSONArray("faceAnnotations");
|
||||
for (int j = 0; j < jaFaceAnnotations.length(); j++) {
|
||||
JSONObject joFaceAnnotation = jaFaceAnnotations.getJSONObject(j);
|
||||
ff = new FotoFace(foto.getApFull());
|
||||
ff.setId_foto(foto.getId_foto());
|
||||
JSONObject joFace = new JSONObject();
|
||||
JSONObject joFdBoundingPoly = joFaceAnnotation.getJSONObject("fdBoundingPoly");
|
||||
joFace.put("fdBoundingPoly", joFdBoundingPoly);
|
||||
JSONArray jaLandmarks = joFaceAnnotation.getJSONArray("landmarks");
|
||||
joFace.put("landmarks", jaLandmarks);
|
||||
ff.setJsonData(joFace.toString());
|
||||
rp = ff.save();
|
||||
if (!rp.getStatus())
|
||||
msg.append("Errore: impossibile caricare fotoface da json per foto id " + foto.getId_foto() + ": " + rp.getMsg() + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!visiTrovati) {
|
||||
ff = new FotoFace(foto.getApFull());
|
||||
ff.setId_foto(foto.getId_foto());
|
||||
rp = ff.save();
|
||||
}
|
||||
if (rp.getStatus())
|
||||
if (foto.getMd5().isEmpty()) {
|
||||
foto.setMd5(DBAdapter.getFileMd5(foto.getFileNameFaceRecognition()));
|
||||
rp.append(foto.save());
|
||||
}
|
||||
if (msg.length() > 0) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(msg.toString());
|
||||
}
|
||||
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);
|
||||
FotoVision fotoVision = new FotoVision(apTarget);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileNameFaceRecognition() {
|
||||
return getFileNameFullPath();
|
||||
}
|
||||
|
||||
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<FotoVision> 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()) {
|
||||
FotoVision row = (FotoVision)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, Clifor.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<FotoVision> vec = findRows(stmt, 1, 1);
|
||||
if (vec.hasMoreElements()) {
|
||||
FotoVision row = (FotoVision)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<FotoVision> vec = findRows(stmt, 1, 1);
|
||||
if (vec.hasMoreElements()) {
|
||||
FotoVision row = (FotoVision)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) {
|
||||
return delete("delete from FOTO where id_puntoFoto=" + l_id_puntoFoto);
|
||||
}
|
||||
|
||||
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(FotoVision 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 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<FotoVision> findByCR(FotoCR CR, int pageNumber, int pageRows) {
|
||||
if (CR.getFotoSelfie() != null)
|
||||
return findByCRFotoSelfie(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 ");
|
||||
WcString wc = new WcString();
|
||||
findByCRCreateWC(CR, s_Sql_Find, wc);
|
||||
try {
|
||||
PreparedStatement stmt;
|
||||
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;
|
||||
int start = (pageNumber - 1) * pageRows;
|
||||
int 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);
|
||||
}
|
||||
Vectumerator<FotoVision> 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.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.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("A.pettorali like'%," + CR.getPettorale() + ",%'");
|
||||
}
|
||||
|
||||
public Vectumerator<FotoVision> findByCRFotoSelfie(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;
|
||||
}
|
||||
}
|
||||
|
||||
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<FotoVision> 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<FotoVision> vec = findSelfies(0L);
|
||||
StringBuilder sb = new StringBuilder("N. Tot Selfie:" + vec.getTotNumberOfRecords() + "<br>");
|
||||
while (vec.hasMoreElements()) {
|
||||
FotoVision row = (FotoVision)vec.nextElement();
|
||||
FotoVision foto = new FotoVision(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<FotoVision> 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 updatePettoraliByLabel() {
|
||||
ResParm rp = new ResParm();
|
||||
if (getId_foto() > 0L) {
|
||||
FotoFace ff = new FotoFace(getApFull());
|
||||
Vectumerator<FotoFace> vec = ff.findByFotoConPettorale(getId_foto());
|
||||
StringBuilder sb = new StringBuilder(",");
|
||||
while (vec.hasMoreElements()) {
|
||||
FotoFace row = (FotoFace)vec.nextElement();
|
||||
sb.append(row.getPettorale());
|
||||
sb.append(",");
|
||||
}
|
||||
setPettorali(sb.toString());
|
||||
rp = save();
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
protected void fillFields(ResultSet rst) {
|
||||
super.fillFields(rst);
|
||||
}
|
||||
|
||||
public ResParm save() {
|
||||
ResParm rp = super.save();
|
||||
return rp;
|
||||
}
|
||||
|
||||
protected void initFields() {
|
||||
super.initFields();
|
||||
}
|
||||
|
||||
public static final ResParm loadFacesByFaceRecognitionJson(FotoI foto, JSONObject jo) {
|
||||
ResParm rp = new ResParm();
|
||||
if (foto.getId_foto() == 0L || foto.getApFull() == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore! Foto non valida..");
|
||||
}
|
||||
StringBuilder msg = new StringBuilder();
|
||||
FotoFace ff = new FotoFace(foto.getApFull());
|
||||
ff.deleteFotoFaceByFoto(foto.getId_foto(), true);
|
||||
JSONArray jaResponses = jo.getJSONArray("responses");
|
||||
boolean visiTrovati = false;
|
||||
for (int i = 0; i < jaResponses.length(); i++) {
|
||||
JSONObject joResponse = jaResponses.getJSONObject(i).getJSONObject("response");
|
||||
System.out.println(joResponse.toString(4));
|
||||
HashMap<Integer, Integer> hmNumbers = new HashMap<>();
|
||||
if (!joResponse.has("numbers"));
|
||||
JSONArray jaNumbers = joResponse.getJSONArray("numbers");
|
||||
for (int j = 0; j < jaNumbers.length(); j++) {
|
||||
JSONObject joNumber = jaNumbers.getJSONObject(j);
|
||||
hmNumbers.put(Integer.valueOf(joNumber.getInt("xCenter")), Integer.valueOf(joNumber.getInt("value")));
|
||||
}
|
||||
if (joResponse.has("faceAnnotations")) {
|
||||
visiTrovati = true;
|
||||
JSONArray jaFaceAnnotations = joResponse.getJSONArray("faceAnnotations");
|
||||
for (int k = 0; k < jaFaceAnnotations.length(); k++) {
|
||||
JSONObject joFaceAnnotation = jaFaceAnnotations.getJSONObject(k);
|
||||
ff = new FotoFace(foto.getApFull());
|
||||
ff.setId_foto(foto.getId_foto());
|
||||
JSONObject joFace = new JSONObject();
|
||||
JSONObject joFdBoundingPoly = joFaceAnnotation.getJSONObject("fdBoundingPoly");
|
||||
joFace.put("fdBoundingPoly", joFdBoundingPoly);
|
||||
for (Map.Entry<Integer, Integer> entry : hmNumbers.entrySet())
|
||||
System.out.println("Key : " + String.valueOf(entry.getKey()) + " Value : " + String.valueOf(entry.getValue()));
|
||||
rp = ff.save();
|
||||
if (!rp.getStatus())
|
||||
msg.append("Errore: impossibile caricare fotoface da json per foto id " + foto.getId_foto() + ": " + rp.getMsg() + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!visiTrovati) {
|
||||
ff = new FotoFace(foto.getApFull());
|
||||
ff.setId_foto(foto.getId_foto());
|
||||
rp = ff.save();
|
||||
}
|
||||
if (rp.getStatus())
|
||||
if (foto.getMd5().isEmpty()) {
|
||||
foto.setMd5(DBAdapter.getFileMd5(foto.getFileNameFaceRecognition()));
|
||||
rp.append(foto.save());
|
||||
}
|
||||
if (msg.length() > 0) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(msg.toString());
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public static final ResParm loadFacesByGoogleVision(FotoI foto) {
|
||||
ResParm rp = new ResParm();
|
||||
if (foto.getId_foto() == 0L || foto.getApFull() == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore! Foto non valida");
|
||||
}
|
||||
if (!foto.hasFotoFaces()) {
|
||||
System.out.println("loadFacesByGoogleVision: " + foto.getId_foto() + " " + foto.getFileNameFaceRecognition());
|
||||
String GVA_KEY = foto.getParm("GOOGLE_API_KEY_VISION").getTesto();
|
||||
GoogleVisionApi gva = new GoogleVisionApi(GVA_KEY);
|
||||
GoogleVisionResult resF = gva.annotateFaces(foto.getFileNameFaceRecognition());
|
||||
if (resF.isOk())
|
||||
return loadFacesByGoogleVisionJson(foto, (JSONObject)resF.getResult());
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(resF.getMsg());
|
||||
return rp;
|
||||
}
|
||||
System.out.println("loadFacesByGoogleVision solo ricalcolo: " + foto.getId_foto() + " " + foto.getFileNameFaceRecognition());
|
||||
foto._ricalcolaFotoFaces();
|
||||
rp.setStatus(true);
|
||||
rp.setMsg("Ricalcolo effettuato ");
|
||||
return rp;
|
||||
}
|
||||
|
||||
public long getNumOfFaces() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getHeight() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getWidth() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getMargineFotoBottom() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getMargineFotoTop() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getMargineFotoSx() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getMargineFotoDx() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getDimMinFotoFaceReal() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public FaceDetectionMethod getFaceDetectionMethodReal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getDetectFaceConfidentThresold() {
|
||||
return 0.9D;
|
||||
}
|
||||
|
||||
public void setId_faceDetectionMethod(long l_id_faceDetectionMethod) {}
|
||||
|
||||
public long getId_faceDetectionMethod() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getFaceSize() {
|
||||
return getEvento().getFaceRecognizer().getFaceSize();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.util.DoubleOperator;
|
||||
|
||||
public class Point {
|
||||
private long x;
|
||||
|
||||
private long y;
|
||||
|
||||
private long z;
|
||||
|
||||
public Point(long x, long y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = 0L;
|
||||
}
|
||||
|
||||
public Point(long x, long y, long z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Point() {}
|
||||
|
||||
public long getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public void setX(long x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public long getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(long y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public long getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public void setZ(long z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public static final double getDistance(Point start, Point end) {
|
||||
double d1 = Math.sqrt(Math.pow((double)(end.getX() - start.getX()), 2.0D) + Math.pow((double)(end.getY() - start.getY()), 2.0D) +
|
||||
Math.pow((double)(end.getZ() - start.getZ()), 2.0D));
|
||||
return d1;
|
||||
}
|
||||
|
||||
public static final double getDistanceNorm(Point start, Point end, double scaleFactor) {
|
||||
DoubleOperator dop = new DoubleOperator(scaleFactor);
|
||||
dop.multiply(getDistance(start, end));
|
||||
return dop.getResult();
|
||||
}
|
||||
|
||||
public static final float getDistanceNormF(Point start, Point end, double scaleFactor) {
|
||||
return (float)getDistanceNorm(start, end, scaleFactor);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Point a = new Point(0L, 0L, 0L);
|
||||
Point b = new Point(2L, 2L, 0L);
|
||||
System.out.println(getDistance(a, b));
|
||||
}
|
||||
}
|
||||
1074
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/PuntoFoto.java
Normal file
1074
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/PuntoFoto.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,105 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class PuntoFotoCR extends CRAdapter {
|
||||
private long id_puntoFoto;
|
||||
|
||||
private long id_evento;
|
||||
|
||||
private String pathRelativoFoto;
|
||||
|
||||
private long secRange;
|
||||
|
||||
private long secShift;
|
||||
|
||||
private Evento evento;
|
||||
|
||||
private long flgIndexOk = -1L;
|
||||
|
||||
private long flgPreviewFoto = -1L;
|
||||
|
||||
private String tipoPuntoFoto;
|
||||
|
||||
public PuntoFotoCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public PuntoFotoCR() {}
|
||||
|
||||
public void setId_puntoFoto(long newId_puntoFoto) {
|
||||
this.id_puntoFoto = newId_puntoFoto;
|
||||
}
|
||||
|
||||
public void setId_evento(long newId_evento) {
|
||||
this.id_evento = newId_evento;
|
||||
setEvento(null);
|
||||
}
|
||||
|
||||
public void setPathRelativoFoto(String newPathRelativoFoto) {
|
||||
this.pathRelativoFoto = newPathRelativoFoto;
|
||||
}
|
||||
|
||||
public void setSecRange(long newSecRange) {
|
||||
this.secRange = newSecRange;
|
||||
}
|
||||
|
||||
public void setSecShift(long newSecShift) {
|
||||
this.secShift = newSecShift;
|
||||
}
|
||||
|
||||
public long getId_puntoFoto() {
|
||||
return this.id_puntoFoto;
|
||||
}
|
||||
|
||||
public long getId_evento() {
|
||||
return this.id_evento;
|
||||
}
|
||||
|
||||
public String getPathRelativoFoto() {
|
||||
return (this.pathRelativoFoto == null) ? "" :
|
||||
this.pathRelativoFoto;
|
||||
}
|
||||
|
||||
public long getSecRange() {
|
||||
return this.secRange;
|
||||
}
|
||||
|
||||
public long getSecShift() {
|
||||
return this.secShift;
|
||||
}
|
||||
|
||||
public void setEvento(Evento newEvento) {
|
||||
this.evento = newEvento;
|
||||
}
|
||||
|
||||
public Evento getEvento() {
|
||||
this.evento = (Evento)getSecondaryObject(this.evento, Evento.class, getId_evento());
|
||||
return this.evento;
|
||||
}
|
||||
|
||||
public long getFlgIndexOk() {
|
||||
return this.flgIndexOk;
|
||||
}
|
||||
|
||||
public void setFlgIndexOk(long flgIndexOk) {
|
||||
this.flgIndexOk = flgIndexOk;
|
||||
}
|
||||
|
||||
public long getFlgPreviewFoto() {
|
||||
return this.flgPreviewFoto;
|
||||
}
|
||||
|
||||
public void setFlgPreviewFoto(long flgPreviewFoto) {
|
||||
this.flgPreviewFoto = flgPreviewFoto;
|
||||
}
|
||||
|
||||
public String getTipoPuntoFoto() {
|
||||
return (this.tipoPuntoFoto == null) ? AB_EMPTY_STRING : this.tipoPuntoFoto.trim();
|
||||
}
|
||||
|
||||
public void setTipoPuntoFoto(String tipoPuntoFoto) {
|
||||
this.tipoPuntoFoto = tipoPuntoFoto;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ScoringVelox extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1741708793293L;
|
||||
|
||||
private long id_scoringVelox;
|
||||
|
||||
private long numCoreCuda;
|
||||
|
||||
private long numThreadXCuda;
|
||||
|
||||
private long numQueryCallable;
|
||||
|
||||
private double maxVelox;
|
||||
|
||||
private Timestamp tsMax;
|
||||
|
||||
public ScoringVelox(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public ScoringVelox() {}
|
||||
|
||||
public void setId_scoringVelox(long newId_scoringVelox) {
|
||||
this.id_scoringVelox = newId_scoringVelox;
|
||||
}
|
||||
|
||||
public void setNumCoreCuda(long newNumCoreCuda) {
|
||||
this.numCoreCuda = newNumCoreCuda;
|
||||
}
|
||||
|
||||
public void setNumThreadXCuda(long newNumThreadXCuda) {
|
||||
this.numThreadXCuda = newNumThreadXCuda;
|
||||
}
|
||||
|
||||
public void setNumQueryCallable(long newNumQueryCallable) {
|
||||
this.numQueryCallable = newNumQueryCallable;
|
||||
}
|
||||
|
||||
public void setMaxVelox(double newMaxVelox) {
|
||||
this.maxVelox = newMaxVelox;
|
||||
}
|
||||
|
||||
public void setTsMax(Timestamp newTsMax) {
|
||||
this.tsMax = newTsMax;
|
||||
}
|
||||
|
||||
public long getId_scoringVelox() {
|
||||
return this.id_scoringVelox;
|
||||
}
|
||||
|
||||
public long getNumCoreCuda() {
|
||||
return this.numCoreCuda;
|
||||
}
|
||||
|
||||
public long getNumThreadXCuda() {
|
||||
return this.numThreadXCuda;
|
||||
}
|
||||
|
||||
public long getNumQueryCallable() {
|
||||
return this.numQueryCallable;
|
||||
}
|
||||
|
||||
public double getMaxVelox() {
|
||||
return this.maxVelox;
|
||||
}
|
||||
|
||||
public Timestamp getTsMax() {
|
||||
return this.tsMax;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public void findMaxVelox() {
|
||||
String s_Sql_Find = "SELECT * FROM SCORING_VELOX ORDER BY maxVelox DESC";
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find);
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<ScoringVelox> findByCR(ScoringVeloxCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from SCORING_VELOX AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void findByCoreThreadCallable(long l_numCoreCuda, long l_numThreadXCuda, int l_numQueryCallable) {
|
||||
String s_Sql_Find = "select A.* from SCORING_VELOX AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.numCoreCuda=" + l_numCoreCuda);
|
||||
wc.addWc("A.numThreadXCuda=" + l_numThreadXCuda);
|
||||
wc.addWc("A.numQueryCallable=" + l_numQueryCallable);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findMaxVeloxByCoreCuda(long l_numCoreCuda) {
|
||||
String s_Sql_Find = "SELECT * FROM SCORING_VELOX WHERE numCoreCuda =" + l_numCoreCuda + " ORDER BY maxVelox DESC";
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find);
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findMaxVeloxByCoreCudaThreadxcuda(long l_numCoreCuda, long l_numThreadXCuda) {
|
||||
String s_Sql_Find = "SELECT * FROM SCORING_VELOX WHERE numCoreCuda =" + l_numCoreCuda + " AND numThreadXCuda = " + l_numThreadXCuda + " ORDER BY maxVelox DESC";
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find);
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ScoringVeloxCR extends CRAdapter {
|
||||
private static final long serialVersionUID = 7825622112961344466L;
|
||||
|
||||
private long id_scoringVelox;
|
||||
|
||||
private long numCoreCuda;
|
||||
|
||||
private long numThreadXCuda;
|
||||
|
||||
private long numQueryCallable;
|
||||
|
||||
private double maxVelox;
|
||||
|
||||
private Timestamp tsMax;
|
||||
|
||||
public ScoringVeloxCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public ScoringVeloxCR() {}
|
||||
|
||||
public void setId_scoringVelox(long newId_scoringVelox) {
|
||||
this.id_scoringVelox = newId_scoringVelox;
|
||||
}
|
||||
|
||||
public void setNumCoreCuda(long newNumCoreCuda) {
|
||||
this.numCoreCuda = newNumCoreCuda;
|
||||
}
|
||||
|
||||
public void setNumThreadXCuda(long newNumThreadXCuda) {
|
||||
this.numThreadXCuda = newNumThreadXCuda;
|
||||
}
|
||||
|
||||
public void setNumQueryCallable(long newNumQueryCallable) {
|
||||
this.numQueryCallable = newNumQueryCallable;
|
||||
}
|
||||
|
||||
public void setMaxVelox(double newMaxVelox) {
|
||||
this.maxVelox = newMaxVelox;
|
||||
}
|
||||
|
||||
public void setTsMax(Timestamp newTsMax) {
|
||||
this.tsMax = newTsMax;
|
||||
}
|
||||
|
||||
public long getId_scoringVelox() {
|
||||
return this.id_scoringVelox;
|
||||
}
|
||||
|
||||
public long getNumCoreCuda() {
|
||||
return this.numCoreCuda;
|
||||
}
|
||||
|
||||
public long getNumThreadXCuda() {
|
||||
return this.numThreadXCuda;
|
||||
}
|
||||
|
||||
public long getNumQueryCallable() {
|
||||
return this.numQueryCallable;
|
||||
}
|
||||
|
||||
public double getMaxVelox() {
|
||||
return this.maxVelox;
|
||||
}
|
||||
|
||||
public Timestamp getTsMax() {
|
||||
return this.tsMax;
|
||||
}
|
||||
}
|
||||
1027
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Selfie.java
Normal file
1027
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Selfie.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,43 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class SelfieCR extends CRAdapter {
|
||||
private long id_selfie;
|
||||
|
||||
private String md5;
|
||||
|
||||
private Timestamp tsCreation;
|
||||
|
||||
public SelfieCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public SelfieCR() {}
|
||||
|
||||
public void setId_selfie(long newId_selfie) {
|
||||
this.id_selfie = newId_selfie;
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public void setTsCreation(Timestamp newTsCreation) {
|
||||
this.tsCreation = newTsCreation;
|
||||
}
|
||||
|
||||
public long getId_selfie() {
|
||||
return this.id_selfie;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
public Timestamp getTsCreation() {
|
||||
return this.tsCreation;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SelfieFoto extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1734518684722L;
|
||||
|
||||
private long id_selfieFoto;
|
||||
|
||||
private long id_selfie;
|
||||
|
||||
private long id_foto;
|
||||
|
||||
private long label;
|
||||
|
||||
private String confidence;
|
||||
|
||||
private Selfie selfie;
|
||||
|
||||
private Foto foto;
|
||||
|
||||
public SelfieFoto(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public SelfieFoto() {}
|
||||
|
||||
public void setId_selfieFoto(long newId_selfieFoto) {
|
||||
this.id_selfieFoto = newId_selfieFoto;
|
||||
}
|
||||
|
||||
public void setId_selfie(long newId_selfie) {
|
||||
this.id_selfie = newId_selfie;
|
||||
setSelfie(null);
|
||||
}
|
||||
|
||||
public void setId_foto(long newId_foto) {
|
||||
this.id_foto = newId_foto;
|
||||
setFoto(null);
|
||||
}
|
||||
|
||||
public void setLabel(long newLabel) {
|
||||
this.label = newLabel;
|
||||
}
|
||||
|
||||
public void setConfidence(String newConfidence) {
|
||||
this.confidence = newConfidence;
|
||||
}
|
||||
|
||||
public long getId_selfieFoto() {
|
||||
return this.id_selfieFoto;
|
||||
}
|
||||
|
||||
public long getId_selfie() {
|
||||
return this.id_selfie;
|
||||
}
|
||||
|
||||
public long getId_foto() {
|
||||
return this.id_foto;
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public String getConfidence() {
|
||||
return (this.confidence == null) ? "" : this.confidence.trim();
|
||||
}
|
||||
|
||||
public void setSelfie(Selfie newSelfie) {
|
||||
this.selfie = newSelfie;
|
||||
}
|
||||
|
||||
public Selfie getSelfie() {
|
||||
this.selfie = (Selfie)getSecondaryObject(this.selfie, Selfie.class, getId_selfie());
|
||||
return this.selfie;
|
||||
}
|
||||
|
||||
public void setFoto(Foto newFoto) {
|
||||
this.foto = newFoto;
|
||||
}
|
||||
|
||||
public Foto getFoto() {
|
||||
this.foto = (Foto)getSecondaryObject(this.foto, Foto.class, getId_foto());
|
||||
return this.foto;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<SelfieFoto> findByCR(SelfieFotoCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from SELFIE_FOTO AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<SelfieFoto> findBySelfie(long l_id_selfie) {
|
||||
String s_Sql_Find = "select A.* from SELFIE_FOTO AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_Selfie=" + l_id_selfie);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class SelfieFotoCR extends CRAdapter {
|
||||
private long id_selfieFoto;
|
||||
|
||||
private long id_selfie;
|
||||
|
||||
private long id_foto;
|
||||
|
||||
private long label;
|
||||
|
||||
private String confidence;
|
||||
|
||||
private Selfie selfie;
|
||||
|
||||
private Foto foto;
|
||||
|
||||
public SelfieFotoCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public SelfieFotoCR() {}
|
||||
|
||||
public void setId_selfieFoto(long newId_selfieFoto) {
|
||||
this.id_selfieFoto = newId_selfieFoto;
|
||||
}
|
||||
|
||||
public void setId_selfie(long newId_selfie) {
|
||||
this.id_selfie = newId_selfie;
|
||||
setSelfie(null);
|
||||
}
|
||||
|
||||
public void setId_foto(long newId_foto) {
|
||||
this.id_foto = newId_foto;
|
||||
setFoto(null);
|
||||
}
|
||||
|
||||
public void setLabel(long newLabel) {
|
||||
this.label = newLabel;
|
||||
}
|
||||
|
||||
public void setConfidence(String newConfidence) {
|
||||
this.confidence = newConfidence;
|
||||
}
|
||||
|
||||
public long getId_selfieFoto() {
|
||||
return this.id_selfieFoto;
|
||||
}
|
||||
|
||||
public long getId_selfie() {
|
||||
return this.id_selfie;
|
||||
}
|
||||
|
||||
public long getId_foto() {
|
||||
return this.id_foto;
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public String getConfidence() {
|
||||
return (this.confidence == null) ? "" : this.confidence.trim();
|
||||
}
|
||||
|
||||
public void setSelfie(Selfie newSelfie) {
|
||||
this.selfie = newSelfie;
|
||||
}
|
||||
|
||||
public Selfie getSelfie() {
|
||||
this.selfie = (Selfie)getSecondaryObject(this.selfie, Selfie.class,
|
||||
|
||||
getId_selfie());
|
||||
return this.selfie;
|
||||
}
|
||||
|
||||
public void setFoto(Foto newFoto) {
|
||||
this.foto = newFoto;
|
||||
}
|
||||
|
||||
public Foto getFoto() {
|
||||
this.foto = (Foto)getSecondaryObject(this.foto, Foto.class,
|
||||
|
||||
getId_foto());
|
||||
return this.foto;
|
||||
}
|
||||
}
|
||||
332
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Users.java
Normal file
332
decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/Users.java
Normal file
|
|
@ -0,0 +1,332 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.common.Parm;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.face.api.FaceRecognitionApi;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class Users extends it.acxent.anag.Users {
|
||||
public Users() {}
|
||||
|
||||
public Users(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public void initApplicationParms(ApplParmFull ap) {
|
||||
if (ap != null) {
|
||||
String l_tipoParm = "";
|
||||
Parm bean = new Parm(ap);
|
||||
l_tipoParm = "FACE";
|
||||
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
|
||||
bean.findByCodice("MAX_CONCURRENT_THREAD");
|
||||
bean.delete();
|
||||
bean.findByCodice("PATHFOTO_FACE");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PATHFOTO_FACE");
|
||||
bean.setDescrizione("PATHFOTO_FACE");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_RUS/");
|
||||
bean.setNota("PER FACE:Percorso dove risiedono tutte le foto sorgenti<br>PER FOTOEVENTI: PERCORSO DOVE RISIEDONO I SORGENTI DI FACE (NFS)<BR>ATTENZIONE!! Percorso ASSOLUTO.<BR>TUTTI I PERCORSI DEVONO FINIRE PER /<BR>Produzione: /home/sites/regalamiunsorriso/RUS/<br>Test: /Users/acolzi/Downloads/_RUS/");
|
||||
bean.save();
|
||||
bean.findByCodice("PATHFACES");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PATHFACES");
|
||||
bean.setDescrizione("PATHFACES");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_RUS/");
|
||||
bean.setNota("Percorso dove risiedono tutti i visi delle foto<br>ATTENZIONE!! Percorso ASSOLUTO.<BR>TUTTI I PERCORSI DEVONO FINIRE PER /<BR>Produzione: tbd/<br>Test: /Users/acolzi/Downloads/_RUS/");
|
||||
bean.save();
|
||||
bean.findByCodice("PATHFACES_REMOTO");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PATHFACES_REMOTO");
|
||||
bean.setDescrizione("PATHFACES_REMOTO");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_RUS/_REMOTOFACES/");
|
||||
bean.setNota("Percorso dove risiedono tutti i visi delle foto che mi prendo da fr remoto, per evitare tutte le volte di fare la chiamata al servizio<br>ATTENZIONE!! Percorso ASSOLUTO.<BR>TUTTI I PERCORSI DEVONO FINIRE PER /<BR>Produzione: tbd/<br>Test: /Users/acolzi/Downloads/_RUS/_REMOTOFACES/");
|
||||
bean.save();
|
||||
bean.findByCodice("SERVER_CHIAMETE_REMOTO_WWW");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("SERVER_CHIAMETE_REMOTO_WWW");
|
||||
bean.setDescrizione("SERVER_CHIAMETE_REMOTO_WWW");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("https://www.fotoeventi.com/RemoteCmd.abl");
|
||||
bean.setNota("Server remoto www. Serve per inviare i comandi da ovunque a chiunque. In pratica per le notifiche su ricerca per selfie....");
|
||||
bean.save();
|
||||
bean.findByCodice("PREVIEW_W");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PREVIEW_W");
|
||||
bean.setDescrizione("PREVIEW_W");
|
||||
bean.setFlgTipo(1L);
|
||||
bean.setNota("Larghezza preview su ricerca e indicizza. L'altezza ha la precedenza, ovvero se altezza>0, questo parametro viene ignorato.");
|
||||
bean.save();
|
||||
bean.findByCodice("PREVIEW_H");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PREVIEW_H");
|
||||
bean.setDescrizione("PREVIEW_H");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(400.0D);
|
||||
bean.setNota("Altezza preview su ricerca e indicizza. Ha la precedenza sulla larghezza.");
|
||||
bean.save();
|
||||
bean.findByCodice("MAX_NUMBER_OF_THREAD_PF_SCORING_LVL_1");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("MAX_NUMBER_OF_THREAD_PF_SCORING_LVL_1");
|
||||
bean.setDescrizione("MAX_NUMBER_OF_THREAD_PF_SCORING_LVL_1");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() < 0.0D)
|
||||
bean.setNumero(1.0D);
|
||||
bean.setNota("Numero thread (punti foto) contemporanei per il processo di scoring lvl1. Se==0 --> numero di punti foto");
|
||||
bean.save();
|
||||
bean.findByCodice("MAX_NUMBER_OF_THREAD_SCORING_LVL_1");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("MAX_NUMBER_OF_THREAD_SCORING_LVL_1");
|
||||
bean.setDescrizione("MAX_NUMBER_OF_THREAD_SCORING_LVL_1");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumeroInt() <= 0)
|
||||
bean.setNumero(300.0D);
|
||||
bean.setNota("Numero di thread per fase di scoring livello1. Non dipende dalla potenza della macchina ma da quanto i servizi di scoring riescono a assorbire. Per 2 macchine scoring con rtx proviamo con 20. Fare qualche test");
|
||||
bean.save();
|
||||
bean.findByCodice("NUM_QUERY_CALLABLE_LVL_1");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUM_QUERY_CALLABLE_LVL_1");
|
||||
bean.setDescrizione("NUM_QUERY_CALLABLE_LVL_1");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumeroInt() <= 0)
|
||||
bean.setNumero(98.0D);
|
||||
bean.setNota("Numero di query face da inviare a zoo per fase di scoring livello 1. In genere da 80 a 95 con 5 servizi. Utile se Num. Foto No Score ==0 (confronto tutte le face dell'evento...)");
|
||||
bean.save();
|
||||
bean.findByCodice("STEP_STATUS_MSG_SCORING");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("STEP_STATUS_MSG_SCORING");
|
||||
bean.setDescrizione("STEP_STATUS_MSG_SCORING");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumeroInt() <= 0)
|
||||
bean.setNumero(300.0D);
|
||||
bean.setNota("Numero di cicli senza status msg durante lo scoring. NUmero basso rallenta parecchio. In genere 300");
|
||||
bean.save();
|
||||
bean.findByCodice("MAX_NUMBER_OF_THREAD_SCORING_LVL_2");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("MAX_NUMBER_OF_THREAD_SCORING_LVL_2");
|
||||
bean.setDescrizione("MAX_NUMBER_OF_THREAD_SCORING_LVL_2");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumeroInt() <= 0)
|
||||
bean.setNumero(300.0D);
|
||||
bean.setNota("Numero di thread per fase di scoring livello 2 o 7(face to face). Non dipende dalla potenza della macchina ma da quanto i servizi di scoring riescono a assorbire. Per 2 macchine scoring con rtx proviamo con 20");
|
||||
bean.save();
|
||||
bean.findByCodice("NUM_QUERY_CALLABLE_LVL_2");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUM_QUERY_CALLABLE_LVL_2");
|
||||
bean.setDescrizione("NUM_QUERY_CALLABLE_LVL_2");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumeroInt() <= 0)
|
||||
bean.setNumero(98.0D);
|
||||
bean.setNota("Numero di query face da inviare a zoo per fase di scoring livello 2 (face to face). In genere da 80 a 95 con 5 servizi, dipende da NUM_QUERY_CALLABLE_LVL_2 e dal numero di servizi disponibili. Su scoring 7 è dinamico");
|
||||
bean.save();
|
||||
bean.findByCodice("MAX_NUMBER_OF_THREAD_INDEXING_SCALING");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("MAX_NUMBER_OF_THREAD_INDEXING_SCALING");
|
||||
bean.setDescrizione("MAX_NUMBER_OF_THREAD_INDEXING_SCALING");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumeroInt() <= 0)
|
||||
bean.setNumero(30.0D);
|
||||
bean.setNota("Numero Tthread per la fase di indexing e scaling. Di solito 30 con un servizio...");
|
||||
bean.save();
|
||||
l_tipoParm = "FACE SCORING";
|
||||
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
|
||||
bean.findByCodice("NUM_PROCESSORI_CUDA_EFFETTIVI");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUM_PROCESSORI_CUDA_EFFETTIVI");
|
||||
bean.setDescrizione("NUM_PROCESSORI_CUDA_EFFETTIVI");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(4.0D);
|
||||
bean.setNota("NUMERO PROCESSORI CUDA DI PARTENZA. VEDI P_NUM_THREAD_X_PROCESSORE_CUDA X NUMERO THREAD MASSIMO PER SCORING CENTRALIZZATO ");
|
||||
bean.save();
|
||||
bean.findByCodice("NUM_THREAD_X_PROCESSORE_CUDA");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUM_THREAD_X_PROCESSORE_CUDA");
|
||||
bean.setDescrizione("NUM_THREAD_X_PROCESSORE_CUDA");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() < 0.0D)
|
||||
bean.setNumero(0.0D);
|
||||
bean.setNota("NUMERO THREAD PER SCORING CENTRALIZZATO. IN PRATICA DETERMINO QUANTI THREAD MASSIMO PER PROCESSORI CUDA.<BR>QUESTO DETERMINA IL NUMERO DEI THREAD MASSIMO, OVVERO NUM_PROCESSORI_CUDA_EFFETTIVI * NUM_THREAD_X_PROCESSORE_CUDA<br>VIENE UTILIZZATO SE VOGLIO FORZARE IL VALORE NONOSTANTE LA TABELLA SCORING_VELOX. VIENE AZZERATO UNA VOLTA LETTO.");
|
||||
bean.save();
|
||||
bean.findByCodice("NUM_QYERY_CALLABLE");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUM_QYERY_CALLABLE");
|
||||
bean.setDescrizione("NUM_QYERY_CALLABLE");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() < 0.0D)
|
||||
bean.setNumero(0.0D);
|
||||
bean.setNota("NUMERO ELEMENTI NELLA QUERY CALLABLE (PACCHETTO DA INVIARE AI PROCESSORI CUDA).<BR>VIENE UTILIZZATO SE VOGLIO FORZARE IL VALORE NONOSTANTE LA TABELLA SCORING_VELOX. VIENE AZZERATO UNA VOLTA LETTO.");
|
||||
bean.save();
|
||||
bean.findByCodice("NUM_QUERY_CALLABLE_MIN");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUM_QUERY_CALLABLE_MIN");
|
||||
bean.setDescrizione("NUM_QUERY_CALLABLE_MIN");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(150.0D);
|
||||
bean.setNota("VALORE MINIMO PER SINGOLA CALLABLE. VALORI TROPPO BASSI O TROPPO ALTI SONO INEFFICIENTI.<BR>IL VALORE EFFETTIVO DEL NUMERO QUERY CALLABLE VIENE MODIFICATO DINAMICAMENTE MA MAI SOTTO QUESTO VALORE");
|
||||
bean.save();
|
||||
l_tipoParm = "FACE BUILDER";
|
||||
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
|
||||
bean.findByCodice("CONFIDENCE_FOTO_FACE_SEC_DISTANCE_MAX");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("CONFIDENCE_FOTO_FACE_SEC_DISTANCE_MAX");
|
||||
bean.setDescrizione("CONFIDENCE_FOTO_FACE_SEC_DISTANCE_MAX");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(1.0D);
|
||||
bean.setNota("VALORE SECONDI TRA FOTO PER CONFIDENCE NEAR (1)");
|
||||
bean.save();
|
||||
bean.findByCodice("CONFIDENCE_NO_LEVEL_1");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("CONFIDENCE_NO_LEVEL_1");
|
||||
bean.setDescrizione("CONFIDENCE_NO_LEVEL_1");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(40.0D);
|
||||
bean.setNota("CONFIDENCE SOTTO LA QUALE CONSIDERE LE FOTO SICURAMENTE NON APPARTENTENENTI ALLA STESSA CLASSE");
|
||||
bean.save();
|
||||
bean.findByCodice("CONFIDENCE_OK_LEVEL_1");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("CONFIDENCE_OK_LEVEL_1");
|
||||
bean.setDescrizione("CONFIDENCE_OK_LEVEL_1");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(65.0D);
|
||||
bean.setNota("VALORE CONFIDENCE 1 (65) < DI CONFIDENCE 2");
|
||||
bean.save();
|
||||
bean.findByCodice("CONFIDENCE_OK_LEVEL_2");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("CONFIDENCE_OK_LEVEL_2");
|
||||
bean.setDescrizione("CONFIDENCE_OK_LEVEL_2");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(75.0D);
|
||||
bean.setNota("VALORE CONFIDENCE 2 (75) > DI CONFIDENCE 1");
|
||||
bean.save();
|
||||
bean.findByCodice("CONFIDENCE_OK_NEAR");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("CONFIDENCE_OK_NEAR");
|
||||
bean.setDescrizione("CONFIDENCE_OK_NEAR");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(60.0D);
|
||||
bean.setNota("VALORE CONFIDENCE (60) CHE UTILIZZO SE LE FOTO SONO VICINE TRA LORO");
|
||||
bean.save();
|
||||
bean.findByCodice("CONFIDENCE_MAX_LABEL_X_EVENTO");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("CONFIDENCE_MAX_LABEL_X_EVENTO");
|
||||
bean.setDescrizione("CONFIDENCE_MAX_LABEL_X_EVENTO");
|
||||
bean.setFlgTipo(1L);
|
||||
if (bean.getNumero() <= 0.0D)
|
||||
bean.setNumero(50.0D);
|
||||
bean.setNota("NUMERO MASSIMO LABEL PER EVENTO (50)");
|
||||
bean.save();
|
||||
bean.findByCodice("FULL_PATH_SELFIE");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("FULL_PATH_SELFIE");
|
||||
bean.setDescrizione("FULL_PATH_SELFIE");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_FE/_selfie/");
|
||||
bean.setNota("Percorso completo dove vengono memorizzati i selfie<br>/Users/acolzi/Downloads/_FE/_selfie/");
|
||||
bean.save();
|
||||
bean.findByCodice("FACE_DETECTION_USE_PATH");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("FACE_DETECTION_USE_PATH");
|
||||
bean.setDescrizione("FACE_DETECTION_USE_PATH");
|
||||
bean.setFlgTipo(5L);
|
||||
bean.setNota("Se true su richeieste face detection YUNET ZOO mando il path.<br>I percorsi devono essere condivisi tra i container.<br>Dovrei attivarlo anche per gli altri");
|
||||
bean.save();
|
||||
bean.findByCodice("ZOO_YUNET_SCORING_DYS_TYPE");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("ZOO_YUNET_SCORING_DYS_TYPE");
|
||||
bean.setDescrizione("ZOO_YUNET_SCORING_DYS_TYPE");
|
||||
bean.setFlgTipo(1L);
|
||||
bean.setNota("Distance type. <br>0: cosine<br>1: norm_l1.<br>Defaults to 0");
|
||||
bean.save();
|
||||
StatusMsg.deleteMsgByTag(ap, "INIT");
|
||||
super.initApplicationParms(ap);
|
||||
FaceRecognitionApi.initApplicationParms(ap);
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<Users> findByCR(UsersCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from USERS AS A";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("dataFineVld is null");
|
||||
wc = managePolicyFind(CR, wc);
|
||||
if (!CR.isCode1())
|
||||
wc.addWc("A.id_users <>1");
|
||||
if (!CR.getFlgValido().isEmpty())
|
||||
wc.addWc("A.flgValido='" + CR.getFlgValido() + "'");
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
String temp = CR.getSearchTxt().trim().replace("*", "%");
|
||||
StringTokenizer st = new StringTokenizer(temp, " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
int countToken = 0;
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = prepareSqlString(st.nextToken());
|
||||
countToken++;
|
||||
if (countToken > 1)
|
||||
token = "%" + token;
|
||||
txt.append("(A.nome like'%" + token + "%' or A.cognome like'%" + token + "%' or A.eMail like'%" + token + "%' or A.codFisc like'%" + token + "%' or A.login like'%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
if (!CR.getEMail().isEmpty())
|
||||
wc.addWc("A.eMail like'%" + CR.getEMail() + "%'");
|
||||
if (CR.getFlgMl() == 0L) {
|
||||
wc.addWc("(A.flgMl is null or A.flgMl=0)");
|
||||
} else if (CR.getFlgMl() > 0L) {
|
||||
wc.addWc("A.flgMl =" + CR.getFlgMl());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (Exception e) {
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
|
||||
public class UsersCR extends it.acxent.common.UsersCR {
|
||||
public boolean isCode1() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public UsersCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public UsersCR() {}
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
package it.acxent.face;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.DBAdapterException;
|
||||
import it.acxent.db.ResParm;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
public class _FaceAdapter extends DBAdapter {
|
||||
private static final long serialVersionUID = -4488728644498299596L;
|
||||
|
||||
public static final String P_PATHFOTO_FACE = "PATHFOTO_FACE";
|
||||
|
||||
public static final String P_PATHFACES = "PATHFACES";
|
||||
|
||||
public static final String P_PATHFACES_REMOTO = "PATHFACES_REMOTO";
|
||||
|
||||
public static final String P_PATHFOTO_SRC = "PATHFOTO_SRC";
|
||||
|
||||
public static final String P_PREVIEW_W = "PREVIEW_W";
|
||||
|
||||
public static final String P_PREVIEW_H = "PREVIEW_H";
|
||||
|
||||
public static final String P_MODGARA = "MODGARA";
|
||||
|
||||
public static final String P_SERVER_CHIAMETE_REMOTO_WWW = "SERVER_CHIAMETE_REMOTO_WWW";
|
||||
|
||||
public static final String P_CONFIDENCE_OK_NEAR = "CONFIDENCE_OK_NEAR";
|
||||
|
||||
public static final String P_CONFIDENCE_OK_LEVEL_1 = "CONFIDENCE_OK_LEVEL_1";
|
||||
|
||||
public static final String P_CONFIDENCE_OK_LEVEL_2 = "CONFIDENCE_OK_LEVEL_2";
|
||||
|
||||
public static final String P_CONFIDENCE_NO_LEVEL_1 = "CONFIDENCE_NO_LEVEL_1";
|
||||
|
||||
public static final String P_CONFIDENCE_FOTO_FACE_SEC_DISTANCE_MAX = "CONFIDENCE_FOTO_FACE_SEC_DISTANCE_MAX";
|
||||
|
||||
public static final String P_CONFIDENCE_MAX_LABEL_X_EVENTO = "CONFIDENCE_MAX_LABEL_X_EVENTO";
|
||||
|
||||
public static final String P_NUM_PROCESSORI_CUDA_EFFETTIVI = "NUM_PROCESSORI_CUDA_EFFETTIVI";
|
||||
|
||||
public static final String P_NUM_QUERY_CALLABLE_MIN = "NUM_QUERY_CALLABLE_MIN";
|
||||
|
||||
public static final String P_NUM_THREAD_X_PROCESSORE_CUDA = "NUM_THREAD_X_PROCESSORE_CUDA";
|
||||
|
||||
public static final String P_NUM_QYERY_CALLABLE = "NUM_QYERY_CALLABLE";
|
||||
|
||||
public static final String P_MAX_NUMBER_OF_THREAD_INDEXING_SCALING = "MAX_NUMBER_OF_THREAD_INDEXING_SCALING";
|
||||
|
||||
public static final String P_STEP_STATUS_MSG_SCORING = "STEP_STATUS_MSG_SCORING";
|
||||
|
||||
public static final String P_MAX_NUMBER_OF_THREAD_SCORING_LVL_2 = "MAX_NUMBER_OF_THREAD_SCORING_LVL_2";
|
||||
|
||||
public static final String P_NUM_QUERY_CALLABLE_LVL_2 = "NUM_QUERY_CALLABLE_LVL_2";
|
||||
|
||||
public static final String P_MAX_NUMBER_OF_THREAD_PF_SCORING_LVL_1 = "MAX_NUMBER_OF_THREAD_PF_SCORING_LVL_1";
|
||||
|
||||
public static final String P_MAX_NUMBER_OF_THREAD_SCORING_LVL_1 = "MAX_NUMBER_OF_THREAD_SCORING_LVL_1";
|
||||
|
||||
public static final String P_NUM_QUERY_CALLABLE_LVL_1 = "NUM_QUERY_CALLABLE_LVL_1";
|
||||
|
||||
public static final String P_FACE_DETECTION_USE_PATH = "FACE_DETECTION_USE_PATH";
|
||||
|
||||
public static final String P_ZOO_YUNET_SCORING_DYS_TYPE = "ZOO_YUNET_SCORING_DYS_TYPE";
|
||||
|
||||
public static final String P_FULL_PATH_SELFIE = "FULL_PATH_SELFIE";
|
||||
|
||||
public static final String PATH_IMG_FACE = "_face/";
|
||||
|
||||
public _FaceAdapter() {}
|
||||
|
||||
public _FaceAdapter(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() throws DBAdapterException, SQLException {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public String getPathBaseFoto() {
|
||||
if (getApFull() == null)
|
||||
return "/";
|
||||
return getParm("PATHFOTO_FACE").getTesto();
|
||||
}
|
||||
|
||||
public String getPathBaseFace() {
|
||||
if (getApFull() == null)
|
||||
return "/";
|
||||
return getParm("PATHFACES").getTesto();
|
||||
}
|
||||
|
||||
public String getPathBaseFotoSorgenti() {
|
||||
if (getApFull() == null)
|
||||
return "/";
|
||||
return getParm("PATHFOTO_SRC").getTesto();
|
||||
}
|
||||
|
||||
public boolean isModGara() {
|
||||
long mg = getParm("MODGARA").getNumeroLong();
|
||||
if (mg > 0L)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isModGara(long l_id_gara) {
|
||||
long mg = getParm("MODGARA").getNumeroLong();
|
||||
if (mg == l_id_gara)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static synchronized ResParm startRemoteCmdWWW(ApplParmFull ap, Properties parms) {
|
||||
ResParm rp = new ResParm(true);
|
||||
try {
|
||||
URL urlMugello;
|
||||
String theUrlWww = ap.getParm("SERVER_CHIAMETE_REMOTO_WWW").getTesto();
|
||||
if (parms != null) {
|
||||
StringBuffer p = new StringBuffer("?");
|
||||
Enumeration<Object> e = parms.keys();
|
||||
while (e.hasMoreElements()) {
|
||||
String currentKey = (String)e.nextElement();
|
||||
p.append(currentKey);
|
||||
p.append("=");
|
||||
p.append(parms.getProperty(currentKey));
|
||||
if (e.hasMoreElements())
|
||||
p.append("&");
|
||||
}
|
||||
urlMugello = new URL(theUrlWww + theUrlWww);
|
||||
} else {
|
||||
urlMugello = new URL(theUrlWww);
|
||||
}
|
||||
HttpURLConnection connection = (HttpURLConnection)urlMugello.openConnection();
|
||||
BufferedReader read = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line = read.readLine();
|
||||
String html = "";
|
||||
while (line != null) {
|
||||
html = html + html;
|
||||
line = read.readLine();
|
||||
}
|
||||
rp.setMsg("Chiamata Remota a www eseguita con successo");
|
||||
} catch (MalformedURLException ex) {
|
||||
ex.printStackTrace();
|
||||
rp.setException(ex);
|
||||
rp.setStatus(false);
|
||||
} catch (IOException ioex) {
|
||||
ioex.printStackTrace();
|
||||
rp.setException(ioex);
|
||||
rp.setStatus(false);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,53 @@
|
|||
package it.acxent.face.api;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class FaceRecognitionApiResult {
|
||||
private String msg;
|
||||
|
||||
public FaceRecognitionApiResult(String msg, boolean status, Object result) {
|
||||
this.msg = msg;
|
||||
this.ok = status;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
private boolean ok = true;
|
||||
|
||||
private Object result;
|
||||
|
||||
public FaceRecognitionApiResult() {}
|
||||
|
||||
public String getMsg() {
|
||||
return (this.msg == null) ? "" : this.msg.trim();
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public boolean isOk() {
|
||||
return this.ok;
|
||||
}
|
||||
|
||||
public void setOk(boolean status) {
|
||||
this.ok = status;
|
||||
}
|
||||
|
||||
public Object getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public JsonObject getJsonObjectResult() {
|
||||
return (JsonObject)getResult();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public JSONObject getJSONObjectResult() {
|
||||
return (JSONObject)getResult();
|
||||
}
|
||||
|
||||
public void setResult(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package it.acxent.face.api;
|
||||
|
||||
public class TrainingImage {
|
||||
private String imageFileName;
|
||||
|
||||
private long label;
|
||||
|
||||
private String md5;
|
||||
|
||||
public TrainingImage(String imageFileName, long label) {
|
||||
this.imageFileName = imageFileName;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public TrainingImage(String imageFileName, long label, String md5) {
|
||||
this.imageFileName = imageFileName;
|
||||
this.label = label;
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public TrainingImage(String imageFileName, String md5) {
|
||||
this.imageFileName = imageFileName;
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public TrainingImage() {}
|
||||
|
||||
public String getImageFileName() {
|
||||
return this.imageFileName;
|
||||
}
|
||||
|
||||
public void setImageFileName(String imageFileName) {
|
||||
this.imageFileName = imageFileName;
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setLabel(long label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return this.md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,554 @@
|
|||
package it.acxent.face.api.opencv;
|
||||
|
||||
import it.acxent.db.ApplParm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.dm.FaceDetectionMethod;
|
||||
import it.acxent.face.api.vision.GoogleVisionApi;
|
||||
import it.acxent.face.api.vision.GoogleVisionResult;
|
||||
import it.acxent.face.fr.Face;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import org.apache.commons.math3.util.Pair;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.core.MatOfRect;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.dnn.Dnn;
|
||||
import org.opencv.dnn.Net;
|
||||
import org.opencv.face.FaceRecognizer;
|
||||
import org.opencv.face.LBPHFaceRecognizer;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.objdetect.CascadeClassifier;
|
||||
|
||||
public class FaceRecognition {
|
||||
private static boolean debug = false;
|
||||
|
||||
public static final boolean _IS_LOCAL = false;
|
||||
|
||||
private static final int WIDTH_DETECT = 416;
|
||||
|
||||
private static final int HEIGHT_DETECT = 416;
|
||||
|
||||
private static final int WIDTH_NUMBER = 140;
|
||||
|
||||
private static final int HEIGHT_NUMBER = 120;
|
||||
|
||||
private static final double SCALE = 0.00392D;
|
||||
|
||||
private static final double CONFIDENCE_THRESHOLD_NUMBER = 0.5D;
|
||||
|
||||
private static final double NMS_THRESHOLD = 0.4D;
|
||||
|
||||
private static final List<String> NUMBER_CLASSES = new ArrayList<>();
|
||||
|
||||
private static final double CONFIDENCE_CALC_MAX_DISTANCE = 200.0D;
|
||||
|
||||
private FaceRecognitionProperties faceRecognitionProperties;
|
||||
|
||||
private static FaceRecognition instance;
|
||||
|
||||
private static final String cascadePath = "/usr/local/share/opencv4/haarcascades/haarcascade_frontalface_default.xml";
|
||||
|
||||
public static final String pretrainedFrontFace = "/usr/local/share/opencv4/lbpcascades/lbpcascade_frontalface.xml";
|
||||
|
||||
public static final String pretrainedFrontFaceImproved = "/usr/local/share/opencv4/lbpcascades/lbpcascade_frontalface_improved.xml";
|
||||
|
||||
private FaceRecognizer recognizerLBPH;
|
||||
|
||||
private FaceRecognizer faceRecognizerEigen;
|
||||
|
||||
private FaceRecognizer faceRecognizerFish;
|
||||
|
||||
private Mat referenceImage;
|
||||
|
||||
static {
|
||||
NUMBER_CLASSES.add("0");
|
||||
NUMBER_CLASSES.add("1");
|
||||
NUMBER_CLASSES.add("2");
|
||||
NUMBER_CLASSES.add("3");
|
||||
NUMBER_CLASSES.add("4");
|
||||
NUMBER_CLASSES.add("5");
|
||||
NUMBER_CLASSES.add("6");
|
||||
NUMBER_CLASSES.add("7");
|
||||
NUMBER_CLASSES.add("8");
|
||||
NUMBER_CLASSES.add("9");
|
||||
}
|
||||
|
||||
private FaceRecognition(ApplParmFull l_apFull) {
|
||||
this.apFull = l_apFull;
|
||||
getFaceRecognitionProperties();
|
||||
}
|
||||
|
||||
private String fileModelloLBPH = null;
|
||||
|
||||
private ApplParmFull apFull;
|
||||
|
||||
public static void main(String[] args) {
|
||||
String hostname = "localhost:3308";
|
||||
String db = "fr";
|
||||
ApplParmFull ap = new ApplParmFull(new ApplParm(17, "//" + hostname + "/" + db, db, "root", "root", 1, 10, 300));
|
||||
FaceRecognition fr = new FaceRecognition(ap);
|
||||
String pathImgDir = "/Users/acolzi/Downloads/_ocv/img/";
|
||||
String pathToSelfie1 = pathImgDir + "selfie_652_r.JPG";
|
||||
String pathToSelfie2 = pathImgDir + "652_2_si.jpg";
|
||||
String testDetect = pathImgDir + "652_2_volti.jpg";
|
||||
String testDetect2 = pathImgDir + "AMG_4123_10_VOLTI.jpeg";
|
||||
JSONObject jo = fr.detectFaces(testDetect2, true);
|
||||
if (debug)
|
||||
System.out.println(jo.toString(4));
|
||||
}
|
||||
|
||||
public void faceRecognitionTest(String imgToCheck, String modelFileName) {
|
||||
if (imgToCheck == null)
|
||||
imgToCheck = "652_2_volti.jpg";
|
||||
String imagePath = getFaceRecognitionProperties().getPathImgBase() + getFaceRecognitionProperties().getPathImgBase();
|
||||
if (debug)
|
||||
System.out.println("imgToCheck: " + imagePath);
|
||||
Mat originalImage = Imgcodecs.imread(imagePath, 0);
|
||||
CascadeClassifier faceCascade = new CascadeClassifier("/usr/local/share/opencv4/haarcascades/haarcascade_frontalface_default.xml");
|
||||
MatOfRect faceRectangles = new MatOfRect();
|
||||
faceCascade.detectMultiScale(originalImage, faceRectangles);
|
||||
Rect[] comparisonFaceRectangles = faceRectangles.toArray();
|
||||
if (debug)
|
||||
System.out.println("Recognizer training");
|
||||
this.recognizerLBPH = (FaceRecognizer)LBPHFaceRecognizer.create();
|
||||
this.recognizerLBPH.read(modelFileName);
|
||||
comparisoRect(comparisonFaceRectangles, originalImage, imagePath, this.recognizerLBPH);
|
||||
if (debug)
|
||||
System.out.println("Recognizer pretrainedFrontFaceImproved");
|
||||
this.recognizerLBPH = (FaceRecognizer)LBPHFaceRecognizer.create();
|
||||
this.recognizerLBPH.read("/usr/local/share/opencv4/lbpcascades/lbpcascade_frontalface_improved.xml");
|
||||
comparisoRect(comparisonFaceRectangles, originalImage, imagePath, this.recognizerLBPH);
|
||||
}
|
||||
|
||||
public void comparisoRect(Rect[] comparisonFaceRectangles, Mat originalImage, String imagePath, FaceRecognizer l_recognizerLBPH) {
|
||||
for (Rect faceRect : comparisonFaceRectangles) {
|
||||
Mat faceImage = originalImage.submat(faceRect);
|
||||
Imgproc.resize(faceImage, faceImage, this.referenceImage.size());
|
||||
int[] predictedLabel = new int[1];
|
||||
double[] confidenceLBPH = new double[1];
|
||||
double[] confidenceEigen = new double[1];
|
||||
double[] confidenceFish = new double[1];
|
||||
l_recognizerLBPH.predict(faceImage, predictedLabel, confidenceLBPH);
|
||||
if (debug)
|
||||
System.out.println("LBPH Confidenza di confronto. Immagine:" + imagePath + " per faccia su x,y" + faceRect.x + "," + faceRect.y + " --> " + confidenceLBPH[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public void trainingCreateTest(List<TrainingImage> trainingImages, String modelFilename) {
|
||||
Mat labels = new Mat(trainingImages.size(), 1, CvType.CV_32SC1);
|
||||
MatOfInt labelsMat = new MatOfInt();
|
||||
List<Mat> trainingImagesMat = new ArrayList<>();
|
||||
int counter = 0;
|
||||
for (TrainingImage trainingImage : trainingImages) {
|
||||
File imageFile = new File(trainingImage.getImageFileName());
|
||||
if (this.referenceImage == null)
|
||||
this.referenceImage = Imgcodecs.imread(trainingImage.getImageFileName(), 0);
|
||||
Mat image = Imgcodecs.imread(imageFile.getAbsolutePath());
|
||||
Mat grayImage = new Mat();
|
||||
Imgproc.cvtColor(image, grayImage, 6);
|
||||
trainingImagesMat.add(grayImage);
|
||||
labels.put(trainingImage.getLabel(), 0, new double[] { (double)trainingImage.getLabel() });
|
||||
counter++;
|
||||
}
|
||||
labels.convertTo((Mat)labelsMat, CvType.CV_32SC1);
|
||||
this.recognizerLBPH = (FaceRecognizer)LBPHFaceRecognizer.create();
|
||||
this.recognizerLBPH.train(trainingImagesMat, labels);
|
||||
this.recognizerLBPH.save(modelFilename);
|
||||
}
|
||||
|
||||
public String getFileModelloLBPH() {
|
||||
return this.fileModelloLBPH;
|
||||
}
|
||||
|
||||
public void setFileModelloLBPH(String fileModelloLBPH) {
|
||||
this.fileModelloLBPH = fileModelloLBPH;
|
||||
}
|
||||
|
||||
public JSONObject detectFaces(String l_img, boolean isNumbers) {
|
||||
return detectFaces(l_img, 2L, isNumbers);
|
||||
}
|
||||
|
||||
public JSONObject detectFaces(String l_img) {
|
||||
return detectFaces(l_img, 2L, false);
|
||||
}
|
||||
|
||||
public JSONObject detectFaces(String l_img, long methodNumber) {
|
||||
return detectFaces(l_img, methodNumber, false);
|
||||
}
|
||||
|
||||
public JSONObject detectFaces(String l_img, long methodNumber, boolean isNumbers) {
|
||||
JSONObject res = new JSONObject();
|
||||
System.gc();
|
||||
try {
|
||||
FaceDetectionMethod fdm = new FaceDetectionMethod(getApFull());
|
||||
fdm.findByCodice(methodNumber);
|
||||
if (debug)
|
||||
System.out.println(fdm.getDescrizione());
|
||||
JSONObject response = new JSONObject();
|
||||
String l_md5 = l_img.substring(l_img.lastIndexOf('/') + 1, l_img.lastIndexOf("."));
|
||||
response.put("md5", l_md5);
|
||||
JSONArray faceAnnotationsA = new JSONArray();
|
||||
String tempImagePath = getApFull().getParm("path_img_tmp").getTesto() + getApFull().getParm("path_img_tmp").getTesto();
|
||||
Mat originalImage = Imgcodecs.imread(l_img, 0);
|
||||
if (debug)
|
||||
Imgcodecs.imwrite(tempImagePath + "_gray.jpg", originalImage);
|
||||
if (isNumbers) {
|
||||
JSONArray numbers = detectNumbers(l_img, getFaceRecognitionProperties());
|
||||
response.put("numbers", numbers);
|
||||
res.put("numOfNumbers", numbers.length());
|
||||
}
|
||||
if (methodNumber < 0L) {
|
||||
res.put("numOfFaces", 0);
|
||||
} else {
|
||||
int numberOfFaces = 0;
|
||||
if (fdm.getFlgDetectionType() == 0L) {
|
||||
CascadeClassifier faceCascade = new CascadeClassifier(fdm.getPathModello());
|
||||
MatOfRect faceRectangles = new MatOfRect();
|
||||
try {
|
||||
System.out.print("detectMultiscale: " + l_md5 + " ...");
|
||||
faceCascade.detectMultiScale(originalImage, faceRectangles);
|
||||
System.out.println("OK");
|
||||
Rect[] comparisonFaceRectangles = faceRectangles.toArray();
|
||||
for (Rect faceRect : comparisonFaceRectangles) {
|
||||
numberOfFaces++;
|
||||
JSONObject faceAnnotations = new JSONObject();
|
||||
JSONObject fdBoundingPoly = new JSONObject();
|
||||
JSONArray verticesA = new JSONArray();
|
||||
JSONObject j1 = new JSONObject();
|
||||
j1.put("x", faceRect.x);
|
||||
j1.put("y", faceRect.y);
|
||||
verticesA.put(j1);
|
||||
JSONObject j2 = new JSONObject();
|
||||
j2.put("x", faceRect.x + faceRect.width);
|
||||
j2.put("y", faceRect.y);
|
||||
verticesA.put(j2);
|
||||
JSONObject j3 = new JSONObject();
|
||||
j3.put("x", faceRect.x + faceRect.width);
|
||||
j3.put("y", faceRect.y + faceRect.height);
|
||||
verticesA.put(j3);
|
||||
JSONObject j4 = new JSONObject();
|
||||
j4.put("x", faceRect.x);
|
||||
j4.put("y", faceRect.y + faceRect.height);
|
||||
verticesA.put(j4);
|
||||
fdBoundingPoly.put("vertices", verticesA);
|
||||
faceAnnotations.put("fdBoundingPoly", fdBoundingPoly);
|
||||
faceAnnotationsA.put(faceAnnotations);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("detectFaces..");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fdm.getFlgDetectionType() == 1L) {
|
||||
System.out.println("image " + l_img + " md5: " + l_md5 + " ... trying google vision...");
|
||||
GoogleVisionApi gva = new GoogleVisionApi(fdm.getApiKey());
|
||||
GoogleVisionResult resF = gva.annotateFaces(l_img);
|
||||
if (resF.isOk()) {
|
||||
JSONObject jo = (JSONObject)resF.getResult();
|
||||
JSONArray jaResponses = jo.getJSONArray("responses");
|
||||
if (jaResponses.length() > 0) {
|
||||
JSONObject joResponse = jaResponses.getJSONObject(0);
|
||||
if (joResponse.has("faceAnnotations")) {
|
||||
faceAnnotationsA = joResponse.getJSONArray("faceAnnotations");
|
||||
numberOfFaces = faceAnnotationsA.length();
|
||||
System.out.println(l_md5 + " google vision OK. Number of faces: " + l_md5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
response.put("faceAnnotations", faceAnnotationsA);
|
||||
res.put("numOfFaces", numberOfFaces);
|
||||
}
|
||||
res.put("response", response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public FaceRecognitionProperties getFaceRecognitionProperties() {
|
||||
if (this.faceRecognitionProperties == null)
|
||||
this.faceRecognitionProperties = FaceRecognitionProperties.getInstance(this.apFull);
|
||||
return this.faceRecognitionProperties;
|
||||
}
|
||||
|
||||
private static List<Rect> detectBoundingBoxes(Net detectionNet, Mat image) {
|
||||
Mat blob = Dnn.blobFromImage(image, 0.00392D, new Size(416.0D, 416.0D), new Scalar(0.0D, 0.0D, 0.0D), true, false);
|
||||
detectionNet.setInput(blob);
|
||||
List<String> layerNames = getOutputLayers(detectionNet);
|
||||
List<Double> confidences = new ArrayList<>();
|
||||
List<Mat> outputs = new ArrayList<>();
|
||||
List<Rect> boundingBoxes = new ArrayList<>();
|
||||
try {
|
||||
detectionNet.forward(outputs, layerNames);
|
||||
for (Mat output : outputs) {
|
||||
for (int j = 0; j < output.rows(); j++) {
|
||||
Mat detectionsMat = output.row(j);
|
||||
double confidence = (Double)confidence(detectionsMat).getSecond();
|
||||
if (confidence > 0.5D) {
|
||||
confidences.add(Double.valueOf(confidence));
|
||||
boundingBoxes.add(getRectFromDetection(detectionsMat, image));
|
||||
}
|
||||
}
|
||||
}
|
||||
boundingBoxes = NMSBoxes(boundingBoxes, confidences, 0.5F, 0.4F);
|
||||
} catch (Exception e) {
|
||||
System.out.println("detectBoundingBoxes: ");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return boundingBoxes;
|
||||
}
|
||||
|
||||
private static void printMat(Mat mat) {
|
||||
System.out.println("\n" + String.valueOf(mat));
|
||||
for (int i = 0; i < mat.rows(); i++) {
|
||||
System.out.println();
|
||||
for (int j = 0; j < mat.cols(); j++) {
|
||||
double[] f = mat.get(i, j);
|
||||
System.out.print("[");
|
||||
for (int k = 0; k < f.length; k++)
|
||||
System.out.print("" + f[k] + ",");
|
||||
System.out.print("]\t");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Pair<Integer, Double> confidence(Mat mat) {
|
||||
int classid = 0;
|
||||
double confidence = 0.0D;
|
||||
if (mat.rows() == 1 && mat.cols() > 5)
|
||||
for (int k = 5; k < mat.cols(); k++) {
|
||||
double item = mat.get(0, k)[0];
|
||||
if (item > confidence) {
|
||||
confidence = item;
|
||||
classid = k - 5;
|
||||
}
|
||||
}
|
||||
Pair<Integer, Double> resP = new Pair(classid, confidence);
|
||||
return resP;
|
||||
}
|
||||
|
||||
private static Rect getRectFromDetection(Mat dec, Mat image) {
|
||||
Rect res = null;
|
||||
if (dec.rows() == 1 && dec.cols() > 4) {
|
||||
int width = (int)(dec.get(0, 2)[0] * (double)image.width());
|
||||
int height = (int)(dec.get(0, 3)[0] * (double)image.height());
|
||||
int x = (int)(dec.get(0, 0)[0] * (double)image.width()) - width / 2;
|
||||
int y = (int)(dec.get(0, 1)[0] * (double)image.height()) - height / 2;
|
||||
res = new Rect(x, y, width, height);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static JSONArray detectNumbers(String fileName, FaceRecognitionProperties prop) {
|
||||
Mat image = Imgcodecs.imread(fileName);
|
||||
int width = image.width();
|
||||
int height = image.height();
|
||||
JSONArray numbers = new JSONArray();
|
||||
Net detectionNet = Dnn.readNet(prop.getNumberBoxDetectionModel(), prop.getNumberBoxDetectionConfig());
|
||||
Net recognitionNet = Dnn.readNet(prop.getNumberRecognitionDetectionModel(), prop.getNumberRecognitionDetectionConfig());
|
||||
List<Rect> boundingBoxes = detectBoundingBoxes(detectionNet, image);
|
||||
String text = "";
|
||||
String tempImagePath = prop.getPathImgTmp() + prop.getPathImgTmp();
|
||||
for (Rect boundingBox : boundingBoxes) {
|
||||
Mat plateImage = cropImage(image, boundingBox);
|
||||
if (debug)
|
||||
Imgcodecs.imwrite(tempImagePath + "_" + tempImagePath + "_" + boundingBox.x + ".jpg", plateImage);
|
||||
JSONObject number = new JSONObject();
|
||||
number.put("xCenter", boundingBox.x + boundingBox.width / 2);
|
||||
number.put("yCenter", boundingBox.y + boundingBox.height / 2);
|
||||
String numberValue = recognizeNumber(recognitionNet, plateImage);
|
||||
number.put("value", numberValue);
|
||||
numbers.put(number);
|
||||
drawBoundingBox(image, numberValue, boundingBox);
|
||||
text = text + text + ",";
|
||||
}
|
||||
if (debug)
|
||||
Imgcodecs.imwrite(tempImagePath + "_bounding.jpg", image);
|
||||
if (debug)
|
||||
System.out.println("pettorali:" + text);
|
||||
return numbers;
|
||||
}
|
||||
|
||||
private static List<String> getOutputLayers(Net net) {
|
||||
List<String> layerNames = net.getLayerNames();
|
||||
List<String> outputLayers = new ArrayList<>();
|
||||
List<Integer> unconnectedLayers = new ArrayList<>();
|
||||
for (String layerName : layerNames) {
|
||||
List<String> outLayers = net.getUnconnectedOutLayersNames();
|
||||
if (outLayers.contains(layerName))
|
||||
unconnectedLayers.add(Integer.valueOf(layerNames.indexOf(layerName)));
|
||||
}
|
||||
for (Iterator<Integer> iterator = unconnectedLayers.iterator(); iterator.hasNext(); ) {
|
||||
int i = iterator.next();
|
||||
outputLayers.add(layerNames.get(i));
|
||||
}
|
||||
return outputLayers;
|
||||
}
|
||||
|
||||
private static void drawBoundingBox(Mat image, String licenseStr, Rect boundingBox) {
|
||||
int x = boundingBox.x;
|
||||
int y = boundingBox.y;
|
||||
int width = boundingBox.width;
|
||||
int height = boundingBox.height;
|
||||
Point tl = new Point((double)x, (double)y);
|
||||
Point br = new Point((double)(x + width), (double)(y + height));
|
||||
Imgproc.rectangle(image, tl, br, new Scalar(0.0D, 255.0D, 0.0D), 2);
|
||||
int fontFace = 0;
|
||||
double fontScale = 0.5D;
|
||||
int thickness = 1;
|
||||
int baseline = 0;
|
||||
Imgproc.putText(image, licenseStr, new Point((double)x, (double)(y - baseline)), fontFace, fontScale, new Scalar(0.0D, 0.0D, 255.0D), thickness);
|
||||
}
|
||||
|
||||
private static Mat cropImage(Mat image, Rect boundingBox) {
|
||||
int x = boundingBox.x;
|
||||
int y = boundingBox.y;
|
||||
int width = boundingBox.width;
|
||||
int height = boundingBox.height;
|
||||
Mat cropImage = new Mat(image, new Rect(x, y, width, height));
|
||||
return cropImage;
|
||||
}
|
||||
|
||||
private static String recognizeNumber(Net recognitionNet, Mat image) {
|
||||
Mat blob = Dnn.blobFromImage(image, 0.00392D, new Size(140.0D, 120.0D), new Scalar(0.0D, 0.0D, 0.0D), true, false);
|
||||
recognitionNet.setInput(blob);
|
||||
List<Double> confidences = new ArrayList<>();
|
||||
List<Integer> class_ids = new ArrayList<>();
|
||||
List<Double> center_X = new ArrayList<>();
|
||||
String text = "";
|
||||
List<String> layerNames = getOutputLayers(recognitionNet);
|
||||
List<Mat> outputs = new ArrayList<>();
|
||||
recognitionNet.forward(outputs, layerNames);
|
||||
List<Rect> boundingBoxes = new ArrayList<>();
|
||||
HashMap<Integer, String> hmLetters = new HashMap<>();
|
||||
for (Mat output : outputs) {
|
||||
for (int j = 0; j < output.rows(); j++) {
|
||||
Mat detectionsMat = output.row(j);
|
||||
Pair<Integer, Double> pClassConfidence = confidence(detectionsMat);
|
||||
double confidence = (Double)pClassConfidence.getSecond();
|
||||
int class_id = (Integer)pClassConfidence.getFirst();
|
||||
if (confidence > 0.5D) {
|
||||
Rect currentRect = getRectFromDetection(detectionsMat, image);
|
||||
boundingBoxes.add(currentRect);
|
||||
confidences.add(Double.valueOf(confidence));
|
||||
hmLetters.put(Integer.valueOf(currentRect.x), NUMBER_CLASSES.get(class_id));
|
||||
String classLabel = NUMBER_CLASSES.get(class_id);
|
||||
text = text + text;
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Rect> indices = NMSBoxes(boundingBoxes, confidences, 0.5F, 0.4F);
|
||||
TreeMap<Integer, String> tmLetters = new TreeMap<>();
|
||||
for (Rect currentbox : indices) {
|
||||
if (hmLetters.containsKey(Integer.valueOf(currentbox.x)))
|
||||
tmLetters.put(Integer.valueOf(currentbox.x), hmLetters.get(Integer.valueOf(currentbox.x)));
|
||||
}
|
||||
StringBuilder sbNumber = new StringBuilder();
|
||||
for (Iterator<Integer> iterator = tmLetters.keySet().iterator(); iterator.hasNext(); ) {
|
||||
int currentX = iterator.next();
|
||||
sbNumber.append(tmLetters.get(Integer.valueOf(currentX)));
|
||||
}
|
||||
return sbNumber.toString();
|
||||
}
|
||||
|
||||
private static List<Rect> NMSBoxes(List<Rect> boundingBoxes, List<Double> confidences, float confidenceThreshold, float nmsThreshold) {
|
||||
List<Rect> nmsBoxes = new ArrayList<>();
|
||||
boundingBoxes.sort((a, b) -> b.x - a.x);
|
||||
for (int i = 0; i < boundingBoxes.size(); i++) {
|
||||
Rect currentBox = boundingBoxes.get(i);
|
||||
for (int j = i + 1; j < boundingBoxes.size(); j++) {
|
||||
Rect remainingBox = boundingBoxes.get(j);
|
||||
float iou = IOU(currentBox, remainingBox);
|
||||
if (iou > nmsThreshold) {
|
||||
boundingBoxes.remove(j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
nmsBoxes.add(currentBox);
|
||||
}
|
||||
return nmsBoxes;
|
||||
}
|
||||
|
||||
private static float IOU(Rect a, Rect b) {
|
||||
int intersectionX = Math.max(a.x, b.x);
|
||||
int intersectionY = Math.max(a.y, b.y);
|
||||
int intersectionWidth = Math.min(a.x + a.width, b.x + b.width) - intersectionX;
|
||||
int intersectionHeight = Math.min(a.y + a.height, b.y + b.height) - intersectionY;
|
||||
float intersectionArea = 0.0F;
|
||||
if (intersectionWidth > 0 && intersectionHeight > 0)
|
||||
intersectionArea = (float)intersectionWidth * (float)intersectionHeight;
|
||||
float unionArea = (float)(a.width * a.height + b.width * b.height) - intersectionArea;
|
||||
return intersectionArea / unionArea;
|
||||
}
|
||||
|
||||
public ApplParmFull getApFull() {
|
||||
return this.apFull;
|
||||
}
|
||||
|
||||
public JSONArray faceRecognition(String imgToCheck, it.acxent.face.fr.FaceRecognizer frzer) {
|
||||
JSONArray jLabelsA = new JSONArray();
|
||||
boolean debug = true;
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " faceRecognition imgToCheck: " + imgToCheck);
|
||||
Mat originalImage = Imgcodecs.imread(imgToCheck, 0);
|
||||
int[] predictedLabel = new int[4];
|
||||
double[] confidenceLBPH = new double[4];
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " faceRecognition carico recognizer dalla cache: " +
|
||||
frzer.getFullFileName(0L));
|
||||
FaceRecognizer ocvFr = frzer.getOcvFaceRecognizerWithLoadedModel(0L);
|
||||
if (ocvFr == null) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " faceRecognition recognizer senza file modello!!!!!!");
|
||||
JSONObject jSONObject = new JSONObject();
|
||||
jSONObject.put("label", -1);
|
||||
jSONObject.put("confidence", 0);
|
||||
jSONObject.put("recognizerType", 0L);
|
||||
jSONObject.put("labelMd5", "");
|
||||
jLabelsA.put(jSONObject);
|
||||
return jLabelsA;
|
||||
}
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " faceRecognition predict.....: ");
|
||||
ocvFr.predict(originalImage, predictedLabel, confidenceLBPH);
|
||||
double confidence = confidenceLBPH[0];
|
||||
confidence = 100.0D * (1.0D - confidence / 200.0D);
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " faceRecognition LBPH Confidenza di confronto.\nImmagine:" + imgToCheck + "\npredictedLabel;" + predictedLabel[0] + "\ndistanza: " + confidenceLBPH[0] + "\nconfidenza: " + confidence + "\n--------");
|
||||
JSONObject joLabelsRow = new JSONObject();
|
||||
joLabelsRow.put("label", predictedLabel[0]);
|
||||
joLabelsRow.put("confidence", confidence);
|
||||
joLabelsRow.put("recognizerType", 0L);
|
||||
if (predictedLabel[0] > 0) {
|
||||
Face face = new Face(getApFull());
|
||||
face.findByPrimaryKey((long)predictedLabel[0]);
|
||||
joLabelsRow.put("labelMd5", face.getMd5());
|
||||
} else {
|
||||
joLabelsRow.put("labelMd5", "");
|
||||
}
|
||||
jLabelsA.put(joLabelsRow);
|
||||
return jLabelsA;
|
||||
}
|
||||
|
||||
public static FaceRecognition getInstance(ApplParmFull l_apFull) {
|
||||
if (instance == null) {
|
||||
instance = new FaceRecognition(l_apFull);
|
||||
Thread.setDefaultUncaughtExceptionHandler(new JniExceptionHandler());
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
package it.acxent.face.api.opencv;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
|
||||
public class FaceRecognitionProperties {
|
||||
public static final String mainConfigFile = "/etc/com-acxent-face/acxent-face.properties";
|
||||
|
||||
public static final String PROP_path_opencv_lib = "path_opencv_lib";
|
||||
|
||||
public static final String PROP_NUMBER_BOX_DECT_CONFIG = "NUMBER_BOX_DECT_CONFIG";
|
||||
|
||||
public static final String PROP_NUMBER_BOX_DECT_MODEL = "NUMBER_BOX_DECT_MODEL";
|
||||
|
||||
public static final String PROP_NUMBER_RECOG_CONFIG = "NUMBER_RECOG_CONFIG";
|
||||
|
||||
public static final String PROP_NUMBER_RECOG_MODEL = "NUMBER_RECOG_MODEL";
|
||||
|
||||
public static final String PROP_path_img_base = "path_img_base";
|
||||
|
||||
public static final String PROP_path_img_tmp = "path_img_tmp";
|
||||
|
||||
public static final String PROP_PATH_FACE_TRAINING_MODELS = "PATH_FACE_TRAINING_MODELS";
|
||||
|
||||
public static final String PROP_PATH_ZOO_FACE_RECOGNITION_SCRIPT = "PATH_ZOO_FACE_RECOGNITION_SCRIPT";
|
||||
|
||||
public static final String PROP_PATH_ZOO_FACE_DETECTION_SCRIPT = "PATH_ZOO_FACE_DETECTION_SCRIPT";
|
||||
|
||||
public static final String PROP_PATH_ZOO_BACKEND_TARGET = "PATH_ZOO_BACKEND_TARGET";
|
||||
|
||||
private static FaceRecognitionProperties instance;
|
||||
|
||||
private ApplParmFull apFull;
|
||||
|
||||
private String openCvLibPath;
|
||||
|
||||
private String numberBoxDetectionModel;
|
||||
|
||||
private String numberBoxDetectionConfig;
|
||||
|
||||
private String numberRecognitionDetectionModel;
|
||||
|
||||
private String numberRecognitionDetectionConfig;
|
||||
|
||||
private String pathImgBase;
|
||||
|
||||
private String pathImgTmp;
|
||||
|
||||
private String pathFaceTrainingModels;
|
||||
|
||||
public static FaceRecognitionProperties getInstance(ApplParmFull l_apFull) {
|
||||
if (instance == null) {
|
||||
instance = new FaceRecognitionProperties(l_apFull);
|
||||
System.load(instance.getOpenCvLibPath());
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public FaceRecognitionProperties(ApplParmFull l_apfFull) {
|
||||
this.apFull = l_apfFull;
|
||||
setOpenCvLibPath(this.apFull.getParm("path_opencv_lib").getTesto());
|
||||
setPathImgBase(this.apFull.getParm("path_img_base").getTesto());
|
||||
setPathImgTmp(this.apFull.getParm("path_img_tmp").getTesto());
|
||||
setPathFaceTrainingModels(this.apFull.getParm("PATH_FACE_TRAINING_MODELS").getTesto());
|
||||
setNumberBoxDetectionConfig(this.apFull.getParm("NUMBER_BOX_DECT_CONFIG").getTesto());
|
||||
setNumberBoxDetectionModel(this.apFull.getParm("NUMBER_BOX_DECT_MODEL").getTesto());
|
||||
setNumberRecognitionDetectionConfig(this.apFull.getParm("NUMBER_RECOG_CONFIG").getTesto());
|
||||
setNumberRecognitionDetectionModel(this.apFull.getParm("NUMBER_RECOG_MODEL").getTesto());
|
||||
}
|
||||
|
||||
public String getOpenCvLibPath() {
|
||||
return this.openCvLibPath;
|
||||
}
|
||||
|
||||
public void setOpenCvLibPath(String openCvLibPath) {
|
||||
this.openCvLibPath = openCvLibPath;
|
||||
}
|
||||
|
||||
public String getPathImgBase() {
|
||||
return this.pathImgBase;
|
||||
}
|
||||
|
||||
public void setPathImgBase(String patImgBase) {
|
||||
this.pathImgBase = patImgBase;
|
||||
}
|
||||
|
||||
public String getNumberBoxDetectionModel() {
|
||||
return this.numberBoxDetectionModel;
|
||||
}
|
||||
|
||||
public void setNumberBoxDetectionModel(String numberBoxDetectionModel) {
|
||||
this.numberBoxDetectionModel = numberBoxDetectionModel;
|
||||
}
|
||||
|
||||
public String getNumberBoxDetectionConfig() {
|
||||
return this.numberBoxDetectionConfig;
|
||||
}
|
||||
|
||||
public void setNumberBoxDetectionConfig(String numberBoxDetectionConfig) {
|
||||
this.numberBoxDetectionConfig = numberBoxDetectionConfig;
|
||||
}
|
||||
|
||||
public String getNumberRecognitionDetectionModel() {
|
||||
return this.numberRecognitionDetectionModel;
|
||||
}
|
||||
|
||||
public void setNumberRecognitionDetectionModel(String numberRecognitionDetectionModel) {
|
||||
this.numberRecognitionDetectionModel = numberRecognitionDetectionModel;
|
||||
}
|
||||
|
||||
public String getNumberRecognitionDetectionConfig() {
|
||||
return this.numberRecognitionDetectionConfig;
|
||||
}
|
||||
|
||||
public void setNumberRecognitionDetectionConfig(String numberRecognitionDetectionConfig) {
|
||||
this.numberRecognitionDetectionConfig = numberRecognitionDetectionConfig;
|
||||
}
|
||||
|
||||
public String getPathFaceTrainingModels() {
|
||||
return this.pathFaceTrainingModels;
|
||||
}
|
||||
|
||||
public void setPathFaceTrainingModels(String patFaceTrainingModels) {
|
||||
this.pathFaceTrainingModels = patFaceTrainingModels;
|
||||
}
|
||||
|
||||
public String getPathImgTmp() {
|
||||
return this.pathImgTmp;
|
||||
}
|
||||
|
||||
public void setPathImgTmp(String pathImgTmp) {
|
||||
this.pathImgTmp = pathImgTmp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package it.acxent.face.api.opencv;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
public class FileIniManager {
|
||||
private String fileName;
|
||||
|
||||
private PrintWriter out;
|
||||
|
||||
public FileIniManager(String s) {
|
||||
this.fileName = s;
|
||||
}
|
||||
|
||||
public boolean deleteProperty(String s) {
|
||||
return writeProperty(s, "");
|
||||
}
|
||||
|
||||
private PrintWriter getOut() {
|
||||
if (this.out == null)
|
||||
try {
|
||||
this.out = new PrintWriter(new BufferedWriter(new FileWriter(this.fileName)));
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace(System.out);
|
||||
return null;
|
||||
}
|
||||
return this.out;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
FileIniManager fileinimanager = new FileIniManager("c:/00/aa.ini");
|
||||
System.out.println("LETTURA1 " + fileinimanager.get("MaxDoc"));
|
||||
fileinimanager.writeProperty("MaxDoc", "ANDREA");
|
||||
System.out.println("LETTURA DOPO WRITE " + fileinimanager.get("MaxDoc"));
|
||||
fileinimanager.deleteProperty("MaxDoc");
|
||||
System.out.println("Dopo cancella: " + fileinimanager.get("MaxDoc"));
|
||||
fileinimanager.writeProperty("MaxDoc", "111 riwrite");
|
||||
System.out.println("Dopo riwrite: " + fileinimanager.get("MaxDoc"));
|
||||
}
|
||||
|
||||
private boolean outClose() {
|
||||
try {
|
||||
getOut().flush();
|
||||
getOut().close();
|
||||
this.out = null;
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace(System.out);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String get(String s) {
|
||||
BufferedReader bufferedreader = null;
|
||||
try {
|
||||
bufferedreader = new BufferedReader(new FileReader(this.fileName));
|
||||
String s1;
|
||||
while ((s1 = bufferedreader.readLine()) != null) {
|
||||
if (s1.startsWith(s + "="))
|
||||
return s1.substring(s.length() + 1);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace(System.out);
|
||||
} finally {
|
||||
if (bufferedreader != null)
|
||||
try {
|
||||
bufferedreader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean writeProperty(String s, String s1) {
|
||||
try {
|
||||
BufferedReader bufferedreader = new BufferedReader(new FileReader(this.fileName));
|
||||
Vector<String> vector = new Vector();
|
||||
boolean flag = false;
|
||||
String s2;
|
||||
while ((s2 = bufferedreader.readLine()) != null) {
|
||||
if (s2.startsWith(s + "=")) {
|
||||
if (!s1.isEmpty())
|
||||
vector.addElement(s + "=" + s);
|
||||
flag = true;
|
||||
continue;
|
||||
}
|
||||
vector.addElement(s2);
|
||||
}
|
||||
bufferedreader.close();
|
||||
if (!flag && !s1.isEmpty())
|
||||
vector.addElement(s + "=" + s);
|
||||
if (flag || !s1.isEmpty()) {
|
||||
for (Enumeration<String> enumeration = vector.elements(); enumeration.hasMoreElements();)
|
||||
getOut()
|
||||
.println(enumeration.nextElement());
|
||||
outClose();
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace(System.out);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package it.acxent.face.api.opencv;
|
||||
|
||||
public class JniExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||
public void uncaughtException(Thread thread, Throwable ex) {
|
||||
System.err.println("Errore JNI non intercettato nel thread " + String.valueOf(thread) + ": " + String.valueOf(ex));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package it.acxent.face.api.opencv;
|
||||
|
||||
public class TrainingImage {
|
||||
private String imageFileName;
|
||||
|
||||
private int label;
|
||||
|
||||
public TrainingImage(String imageFileName, int label) {
|
||||
this.imageFileName = imageFileName;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public TrainingImage() {}
|
||||
|
||||
public String getImageFileName() {
|
||||
return this.imageFileName;
|
||||
}
|
||||
|
||||
public void setImageFileName(String imageFileName) {
|
||||
this.imageFileName = imageFileName;
|
||||
}
|
||||
|
||||
public int getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setLabel(int label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.api.opencv;
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.api;
|
||||
|
|
@ -0,0 +1,243 @@
|
|||
package it.acxent.face.api.vision;
|
||||
|
||||
import it.acxent.cc.Attivita;
|
||||
import it.acxent.common.Parm;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import java.io.File;
|
||||
import java.util.Base64;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GoogleVisionApi {
|
||||
private Attivita attivita;
|
||||
|
||||
private boolean debug = false;
|
||||
|
||||
private ApplParmFull apFull = null;
|
||||
|
||||
private String googleApiKey;
|
||||
|
||||
private String imageFileName;
|
||||
|
||||
public static final String CUPS_SESSION_ID = "_CUPS_SESSION_ID";
|
||||
|
||||
public static final String API_PRODUCTION = "https://vision.googleapis.com/v1/";
|
||||
|
||||
public static final String P_GOOGLE_API_KEY_VISION = "GOOGLE_API_KEY_VISION";
|
||||
|
||||
private static final String URI_CMD_IMAGE_ANNOTATE = "images:annotate?key={key}";
|
||||
|
||||
public GoogleVisionApi(ApplParmFull apFull) {
|
||||
this.apFull = apFull;
|
||||
this.googleApiKey = apFull.getParm("GOOGLE_API_KEY_VISION").getTesto();
|
||||
}
|
||||
|
||||
public GoogleVisionApi(String l_googleApiKey) {
|
||||
this.googleApiKey = l_googleApiKey;
|
||||
}
|
||||
|
||||
public GoogleVisionApi() {}
|
||||
|
||||
public static void initApplicationParms(ApplParmFull ap) {
|
||||
if (ap != null) {
|
||||
DBAdapter.logDebug(true, "GOOGLE VISION initParms: start");
|
||||
String l_tipoParm = "GOOGLE VISION";
|
||||
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
|
||||
Parm bean = new Parm(ap);
|
||||
bean.findByCodice("GOOGLE_API_KEY_VISION");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("GOOGLE_API_KEY_VISION");
|
||||
bean.setDescrizione("GOOGLE_API_KEY_VISION");
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("AIzaSyBYEytX_RU1GDazEC4wCVz5SuxmM_XWUvU");
|
||||
bean.setNota("API KEY ACCESSO AL CLOUD VISION DI GOOGLE<br>AIzaSyBYEytX_RU1GDazEC4wCVz5SuxmM_XWUvU su comm<br>AIzaSyBYEytX_RU1GDazEC4wCVz5SuxmM_XWUvU qui");
|
||||
bean.save();
|
||||
DBAdapter.logDebug(true, "GOOGLE VISION initParms: stop");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String hostname = "localhost";
|
||||
String db = "tr";
|
||||
ApplParmFull ap = new ApplParmFull(new ApplParm(3, "//" + hostname + "/" + db, "root", "root", 1, 10, 300));
|
||||
GoogleVisionApi bean = new GoogleVisionApi("AIzaSyBYEytX_RU1GDazEC4wCVz5SuxmM_XWUvU");
|
||||
GoogleVisionResult resF = bean.annotateFaces("/Users/acolzi/Downloads/_testFace/bastogi1.jpg");
|
||||
System.out.println(resF.getMsg() + "\n" + resF.getMsg());
|
||||
}
|
||||
|
||||
protected String getBase64BasicCredential() {
|
||||
String encoding = "aa:bb";
|
||||
return "Basic " + Base64.getEncoder().encodeToString(encoding.getBytes());
|
||||
}
|
||||
|
||||
public ApplParmFull getApFull() {
|
||||
return this.apFull;
|
||||
}
|
||||
|
||||
public void setApFull(ApplParmFull apFull) {
|
||||
this.apFull = apFull;
|
||||
}
|
||||
|
||||
public Attivita getAttivita() {
|
||||
if (this.attivita == null)
|
||||
this.attivita = Attivita.getDefaultInstance(getApFull());
|
||||
return this.attivita;
|
||||
}
|
||||
|
||||
public String getApiEndpoint() {
|
||||
return "https://vision.googleapis.com/v1/";
|
||||
}
|
||||
|
||||
public GoogleVisionResult annotateImage(String l_imageFileName) {
|
||||
GoogleVisionResult resER = new GoogleVisionResult();
|
||||
try {
|
||||
if (this.debug)
|
||||
System.out.println("GoogleVisionApi --> annotateImage");
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpPost request = new HttpPost(getApiEndpoint() + getApiEndpoint());
|
||||
if (this.debug)
|
||||
System.out.println(getApiEndpoint() + getApiEndpoint());
|
||||
request.setHeader("Accept", "application/json");
|
||||
request.setHeader("Content-Type", "application/json");
|
||||
request.setHeader("Content-Language", "it-IT");
|
||||
JSONObject jBody = new JSONObject();
|
||||
jBody.put("parent", "");
|
||||
JSONArray jRequest = new JSONArray();
|
||||
JSONObject jRequestRow = new JSONObject();
|
||||
JSONObject jImage = new JSONObject();
|
||||
byte[] fileContent = FileUtils.readFileToByteArray(new File(l_imageFileName));
|
||||
String encodedString = Base64.getEncoder().encodeToString(fileContent);
|
||||
jImage.put("content", encodedString);
|
||||
jRequestRow.put("image", jImage);
|
||||
JSONArray jFeatures = new JSONArray();
|
||||
JSONObject jType = new JSONObject();
|
||||
jType.put("type", "DOCUMENT_TEXT_DETECTION");
|
||||
jFeatures.put(jType);
|
||||
jRequestRow.put("features", jFeatures);
|
||||
jRequest.put(jRequestRow);
|
||||
jBody.put("requests", jRequest);
|
||||
if (!this.debug);
|
||||
System.out.println(jBody.toString(4));
|
||||
StringEntity postingString = new StringEntity(jBody.toString());
|
||||
request.setEntity((HttpEntity)postingString);
|
||||
CloseableHttpResponse closeableHttpResponse = client.execute((HttpUriRequest)request);
|
||||
String content = EntityUtils.toString(closeableHttpResponse.getEntity());
|
||||
int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
|
||||
if (this.debug) {
|
||||
System.out.println("Status Code: " + statusCode);
|
||||
System.out.println("\ncontent = " + content);
|
||||
}
|
||||
if (statusCode >= 400) {
|
||||
resER.setOk(false);
|
||||
JSONObject jo = new JSONObject(content);
|
||||
resER.setMsg(jo.toString(2));
|
||||
resER.setResult(jo);
|
||||
} else {
|
||||
JSONObject jo = new JSONObject(content);
|
||||
if (this.debug)
|
||||
System.out.println(jo.toString(4));
|
||||
resER.setMsg("Text Found");
|
||||
resER.setOk(true);
|
||||
resER.setResult(jo.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
resER.setOk(false);
|
||||
resER.setMsg(e.getMessage());
|
||||
}
|
||||
return resER;
|
||||
}
|
||||
|
||||
public String getGoogleApiKey() {
|
||||
return (this.googleApiKey == null) ? "" : this.googleApiKey.trim();
|
||||
}
|
||||
|
||||
public void setGoogleApiKey(String googleApiKey) {
|
||||
this.googleApiKey = googleApiKey;
|
||||
}
|
||||
|
||||
public String getImageFileName() {
|
||||
return (this.imageFileName == null) ? "" : this.imageFileName.trim();
|
||||
}
|
||||
|
||||
public void setImageFileName(String imageFile) {
|
||||
this.imageFileName = imageFile;
|
||||
}
|
||||
|
||||
public GoogleVisionResult annotateFaces(String l_imageFileName) {
|
||||
GoogleVisionResult resER = new GoogleVisionResult();
|
||||
File l_imageFileNameFile = new File(l_imageFileName);
|
||||
if (!l_imageFileNameFile.exists()) {
|
||||
resER.setOk(false);
|
||||
resER.setMsg("File " + l_imageFileName + " not found!");
|
||||
return resER;
|
||||
}
|
||||
try {
|
||||
if (this.debug)
|
||||
System.out.println("GoogleVisionApi --> annotateImage");
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpPost request = new HttpPost(getApiEndpoint() + getApiEndpoint());
|
||||
if (this.debug)
|
||||
System.out.println(getApiEndpoint() + getApiEndpoint());
|
||||
request.setHeader("Accept", "application/json");
|
||||
request.setHeader("Content-Type", "application/json");
|
||||
request.setHeader("Content-Language", "it-IT");
|
||||
JSONObject jBody = new JSONObject();
|
||||
jBody.put("parent", "");
|
||||
JSONArray jRequest = new JSONArray();
|
||||
JSONObject jRequestRow = new JSONObject();
|
||||
JSONObject jImage = new JSONObject();
|
||||
byte[] fileContent = FileUtils.readFileToByteArray(l_imageFileNameFile);
|
||||
String encodedString = Base64.getEncoder().encodeToString(fileContent);
|
||||
jImage.put("content", encodedString);
|
||||
jRequestRow.put("image", jImage);
|
||||
JSONArray jFeatures = new JSONArray();
|
||||
JSONObject jType = new JSONObject();
|
||||
jType.put("type", "FACE_DETECTION");
|
||||
jFeatures.put(jType);
|
||||
jRequestRow.put("features", jFeatures);
|
||||
jRequest.put(jRequestRow);
|
||||
jBody.put("requests", jRequest);
|
||||
StringEntity postingString = new StringEntity(jBody.toString());
|
||||
request.setEntity((HttpEntity)postingString);
|
||||
CloseableHttpResponse closeableHttpResponse = client.execute((HttpUriRequest)request);
|
||||
String content = EntityUtils.toString(closeableHttpResponse.getEntity());
|
||||
int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
|
||||
if (this.debug) {
|
||||
System.out.println("Status Code: " + statusCode);
|
||||
System.out.println("\ncontent = " + content);
|
||||
}
|
||||
if (statusCode >= 400) {
|
||||
resER.setOk(false);
|
||||
JSONObject jo = new JSONObject(content);
|
||||
resER.setMsg(jo.toString(2));
|
||||
resER.setResult(jo);
|
||||
} else {
|
||||
JSONObject jo = new JSONObject(content);
|
||||
resER.setMsg("Faces found");
|
||||
resER.setOk(true);
|
||||
resER.setResult(jo);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
resER.setOk(false);
|
||||
resER.setMsg(e.getMessage());
|
||||
}
|
||||
return resER;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package it.acxent.face.api.vision;
|
||||
|
||||
public class GoogleVisionResult {
|
||||
private String msg;
|
||||
|
||||
public GoogleVisionResult(String msg, boolean status, Object result) {
|
||||
this.msg = msg;
|
||||
this.ok = status;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
private boolean ok = true;
|
||||
|
||||
private Object result;
|
||||
|
||||
public GoogleVisionResult() {}
|
||||
|
||||
public String getMsg() {
|
||||
return (this.msg == null) ? "" : this.msg.trim();
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public boolean isOk() {
|
||||
return this.ok;
|
||||
}
|
||||
|
||||
public void setOk(boolean status) {
|
||||
this.ok = status;
|
||||
}
|
||||
|
||||
public Object getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public void setResult(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.api.vision;
|
||||
|
|
@ -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;
|
||||
|
|
@ -0,0 +1,740 @@
|
|||
package it.acxent.face.dispatcher;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.AppStats;
|
||||
import it.acxent.face.Evento;
|
||||
import it.acxent.face.FaceScore;
|
||||
import it.acxent.face.Foto;
|
||||
import it.acxent.face.PuntoFoto;
|
||||
import it.acxent.face.callable.IndexFotoFaceCallable;
|
||||
import it.acxent.face.callable.Scoring2PuntoFotoCallable;
|
||||
import it.acxent.face.scoring.SmartFaceScoringQueue;
|
||||
import it.acxent.log.Log;
|
||||
import it.acxent.util.Timer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class EventoProcessingDispatcher {
|
||||
private static final Map<Long, EventoProcessingDispatcher> activeDispatchers = new ConcurrentHashMap<>();
|
||||
|
||||
private static boolean debug = true;
|
||||
|
||||
private final Evento evento;
|
||||
|
||||
private final ScheduledExecutorService scheduler;
|
||||
|
||||
private final AtomicBoolean isRunning = new AtomicBoolean(false);
|
||||
|
||||
private static final String TAG_THREAD_MSG_CREAPF = "0 CREA PUNTI FOTO + INDEX";
|
||||
|
||||
private static final String TAG_THREAD_DISPATCHER = "DISPATCHER";
|
||||
|
||||
private volatile boolean threadSTOP = false;
|
||||
|
||||
public EventoProcessingDispatcher(Evento evento) {
|
||||
this.evento = evento;
|
||||
long id = evento.getId_evento();
|
||||
EventoProcessingDispatcher existing = activeDispatchers.putIfAbsent(Long.valueOf(id), this);
|
||||
if (existing != null)
|
||||
throw new IllegalStateException("Dispatcher già attivo per l'evento ID " + id);
|
||||
this.scheduler = Executors.newScheduledThreadPool(5);
|
||||
}
|
||||
|
||||
public boolean isThreadSTOP() {
|
||||
return this.threadSTOP;
|
||||
}
|
||||
|
||||
public void startProcessingLoop() {
|
||||
boolean localhost = true;
|
||||
if (!this.isRunning.compareAndSet(false, true)) {
|
||||
DBAdapter.printDebug(debug, "Dispatcher già in esecuzione per evento " + this.evento.getId_evento());
|
||||
return;
|
||||
}
|
||||
this.threadSTOP = false;
|
||||
DBAdapter.printDebug(debug, "✅ Dispatcher avviato per evento ID " + this.evento.getId_evento());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "Dispatcher avviato per evento ID " + this.evento.getId_evento());
|
||||
this.scheduler.scheduleAtFixedRate(this::safeRunCreaPuntiFotoIndex0, 0L, 15L, TimeUnit.SECONDS);
|
||||
if (!localhost) {
|
||||
this.scheduler.scheduleAtFixedRate(this::safeRunDetect1, 10L, 15L, TimeUnit.SECONDS);
|
||||
this.scheduler.scheduleAtFixedRate(() ->
|
||||
ScoringManager.submitTask(new ScoringTask(this.evento.getId_evento(), ScoringType.SCORING2, this::runScoring2)), 15L, 15L, TimeUnit.SECONDS);
|
||||
this.scheduler.scheduleAtFixedRate(() ->
|
||||
ScoringManager.submitTask(new ScoringTask(this.evento.getId_evento(), ScoringType.SCORING3, this::runScoring3)), 20L, 15L, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
private void safeRunCreaPuntiFotoIndex0() {
|
||||
if (this.threadSTOP)
|
||||
return;
|
||||
if (!Evento.isThreadCreaPuntiFotoAttivo()) {
|
||||
DBAdapter.printDebug(debug, "🟡 [" + this.evento.getId_evento() + "] Avvio processo preparatorio (crea punti foto + indicizza)");
|
||||
ResParm res = this.evento.startCreaPuntiFoto(this.evento, true, 1L);
|
||||
if (!res.getStatus())
|
||||
DBAdapter.printDebug(debug, "⚠️ ThreadCreaPuntiFoto non avviato: " + res.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void safeRunCreatePointsIndexRedux0() {
|
||||
createNewPhotoPointsIndexRedux0();
|
||||
}
|
||||
|
||||
private void safeRunDetect1() {
|
||||
runFaceDetection1();
|
||||
}
|
||||
|
||||
private void safeRunScoring2() {
|
||||
runScoring2();
|
||||
}
|
||||
|
||||
private void runScoring3Test() {
|
||||
DBAdapter.printDebug(debug, "🔴 [" + this.evento.getId_evento() + "] 3 Avvio scoring global TEST...");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "3 TEST Avvio scoring global per evento ID " +
|
||||
this.evento.getId_evento());
|
||||
DBAdapter.sleepInSecond(20);
|
||||
DBAdapter.printDebug(debug, "🔴 [" + this.evento.getId_evento() + "] 3 test scoring FINE: ");
|
||||
}
|
||||
|
||||
private void safeRunScoring3() {
|
||||
runScoring3Test();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void createNewPhotoPointsIndexRedux0() {
|
||||
DBAdapter.printDebug(debug, "🟡 [" +
|
||||
this.evento.getId_evento() + "] 0 Scansione nuovi punti foto, indicizzazione immagini e riduzione...");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "0 Scansione nuovi punti foto, indicizzazione immagini e riduzione per evento ID " +
|
||||
this.evento.getId_evento());
|
||||
boolean indicizza = true;
|
||||
Timer timer = new Timer();
|
||||
timer.start();
|
||||
ResParm rp = new ResParm(true);
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "0 CREA PUNTI FOTO + INDEX", "Thread CREA PUNTI FOTO in esecuzione ....");
|
||||
String dirBase = this.evento.getPathBaseFoto() + this.evento.getPathBaseFoto();
|
||||
if (new File(dirBase).exists()) {
|
||||
File dir = new File(dirBase);
|
||||
try {
|
||||
processaDirectoryRicorsivamente(dir, dirBase, this.evento, indicizza, this.evento.getLastUpdId_user());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "0 CREA PUNTI FOTO + INDEX", "Creazione punto foto evento " + this.evento.getDescrizione() + " ok!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
timer.stop();
|
||||
DBAdapter.printDebug(debug, "🟡 [" +
|
||||
this.evento.getId_evento() + "] 0 Scansione nuovi punti foto, indicizzazione immagini e riduzione FINE. durata: " +
|
||||
timer.getDurataHourMin() + "\n" + rp.getMsg());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "0 CREA PUNTI FOTO + INDEX", "Thread CREA PUNTI FOTO FINE: " + rp.getMsg());
|
||||
try {
|
||||
DBAdapter.sleepInMilliSecond(4000);
|
||||
} catch (Exception e) {}
|
||||
StatusMsg.deleteMsgByTag(this.evento.getApFull(), "0 CREA PUNTI FOTO + INDEX");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "0 FINE Scansione nuovi punti foto, indicizzazione immagini e riduzione per evento ID " +
|
||||
this.evento.getId_evento());
|
||||
}
|
||||
|
||||
private void processaDirectoryRicorsivamente(File directory, String dirBase, Evento evento, boolean indicizza, long id_users) {
|
||||
if (directory == null || !directory.exists() || !directory.isDirectory())
|
||||
return;
|
||||
File[] files = directory.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
creazioneEIndicizzazionePuntoFoto(directory, dirBase, evento, indicizza, id_users);
|
||||
return;
|
||||
}
|
||||
boolean haSubDir = false;
|
||||
for (File file : files) {
|
||||
if (file.isDirectory() && !file.getName().startsWith("_")) {
|
||||
haSubDir = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!haSubDir) {
|
||||
creazioneEIndicizzazionePuntoFoto(directory, dirBase, evento, indicizza, id_users);
|
||||
} else {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory())
|
||||
processaDirectoryRicorsivamente(file, dirBase, evento, indicizza, id_users);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void creazioneEIndicizzazionePuntoFoto(File directory, String dirBase, Evento evento, boolean indicizza, long id_users) {
|
||||
String theDir = directory.getAbsolutePath();
|
||||
String path = theDir.substring(dirBase.length());
|
||||
StatusMsg.updateMsgByTag(evento.getApFull(), "0 CREA PUNTI FOTO + INDEX", "Creazione punto foto " + path);
|
||||
PuntoFoto pf = new PuntoFoto(evento.getApFull());
|
||||
pf.findByEventoPath(evento.getId_evento(), path);
|
||||
ResParm rp = new ResParm(true);
|
||||
if (pf.getDBState() == 0) {
|
||||
pf.setId_evento(evento.getId_evento());
|
||||
pf.setPathRelativoFoto(path);
|
||||
pf.setDescrizione(path.replace("/", ""));
|
||||
rp = pf.save();
|
||||
}
|
||||
if (rp.getStatus() &&
|
||||
indicizza) {
|
||||
long totFotoIndicizzate = pf.getTotFoto();
|
||||
long totJpgFile = pf.getTotJpgFiles();
|
||||
if (totFotoIndicizzate < totJpgFile) {
|
||||
StatusMsg.updateMsgByTag(evento.getApFull(), "0 CREA PUNTI FOTO + INDEX", "Indicizzazione punto foto " + path + "....");
|
||||
rp.append(pf.startIndexFoto(evento.getLastUpdId_user()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runFaceDetection1() {
|
||||
DBAdapter.printDebug(debug, "🔵 [" + this.evento.getId_evento() + "] 1 Avvio face detection...");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "1 Avvio face detection per evento ID " +
|
||||
this.evento.getId_evento());
|
||||
boolean debug2 = true;
|
||||
String TAG_THREAD_MSG = "1 DETECT FACE GARA " + this.evento.getDescrizioneEvento() + "(" + this.evento.getId_evento() + ")";
|
||||
Timer timer = new Timer();
|
||||
timer.start();
|
||||
ResParm rp = new ResParm(true);
|
||||
StringBuffer err = new StringBuffer();
|
||||
int i = 0;
|
||||
StringBuffer errMsg = new StringBuffer();
|
||||
int maxNumberOfThread = this.evento.getParm("MAX_NUMBER_OF_THREAD_INDEXING_SCALING").getNumeroInt();
|
||||
if (maxNumberOfThread <= 1)
|
||||
maxNumberOfThread = 10;
|
||||
if (this.evento.getId_evento() == 0L) {
|
||||
rp.setMsg("Indicizzazione foto: Bean evento non caricato");
|
||||
rp.setStatus(false);
|
||||
DBAdapter.printDebug("Indicizzazione foto: Bean evento non caricato");
|
||||
} else {
|
||||
try {
|
||||
boolean detectNumbers = (this.evento.getFlgDetectNumbers() == 1L);
|
||||
final ThreadLocal<Integer> callerTaskCount = ThreadLocal.withInitial(() -> 0);
|
||||
int NUMB_OF_CORES = Runtime.getRuntime().availableProcessors();
|
||||
int corePoolSize = 4;
|
||||
int maxPoolSize = NUMB_OF_CORES / 2;
|
||||
long keepAliveTime = 360L;
|
||||
int blockingQueueSize = maxPoolSize;
|
||||
ThreadPoolExecutor pool = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue(blockingQueueSize), new ThreadPoolExecutor.CallerRunsPolicy() {
|
||||
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
|
||||
callerTaskCount.set(Integer.valueOf(callerTaskCount.get() + 1));
|
||||
super.rejectedExecution(r, e);
|
||||
}
|
||||
}) {
|
||||
protected void afterExecute(Runnable r, Throwable t) {
|
||||
super.afterExecute(r, t);
|
||||
if (Thread.currentThread() == Thread.currentThread()) {
|
||||
int count = callerTaskCount.get();
|
||||
if (count > 0)
|
||||
callerTaskCount.set(Integer.valueOf(count - 1));
|
||||
}
|
||||
}
|
||||
};
|
||||
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
|
||||
Foto foto = new Foto(this.evento.getApFull());
|
||||
Foto rowFoto = new Foto();
|
||||
Vectumerator<Foto> vec = foto.findByEventoFaceScoringDone(this.evento.getId_evento(), 0L);
|
||||
long currentFotoSenzaVisi = 0L;
|
||||
long totFotoSenzaVisi = (long)vec.getTotNumberOfRecords();
|
||||
while (currentFotoSenzaVisi != totFotoSenzaVisi) {
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + " INIZIO TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current, prima del ciclo quindi dal 2 sicurmente più grande: " + totFotoSenzaVisi);
|
||||
currentFotoSenzaVisi = totFotoSenzaVisi;
|
||||
i = 0;
|
||||
try {
|
||||
while (vec.hasMoreElements() && !this.threadSTOP) {
|
||||
rowFoto = (Foto)vec.nextElement();
|
||||
i++;
|
||||
if (rowFoto.getNumOfFaces() == 0L) {
|
||||
rowFoto.setId_faceDetectionMethod(0L);
|
||||
Thread.sleep(20L);
|
||||
IndexFotoFaceCallable ifc = new IndexFotoFaceCallable(rowFoto, detectNumbers, false);
|
||||
vecF.add(pool.submit(ifc));
|
||||
if (i % 20 == 0)
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - SUBMIT ...index face foto - " +
|
||||
|
||||
rowFoto.getFileName() + " - " + foto.getPuntoFoto().getDescrizioneCompleta() + " - " + i + 1 + " su " +
|
||||
vec.getTotNumberOfRecords() + " method: " +
|
||||
rowFoto.getFaceDetectionMethodReal().getDescrizione() + " eta: " +
|
||||
timer.getEta((long)vec.getTotNumberOfRecords(), (long)(i + 1)));
|
||||
continue;
|
||||
}
|
||||
if (i % 20 == 0)
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - SKIP ...index face foto - " +
|
||||
|
||||
rowFoto.getFileName() + " - " + foto.getPuntoFoto().getDescrizioneCompleta() + " - " + i + 1 + " su " +
|
||||
vec.getTotNumberOfRecords() + " method: " +
|
||||
rowFoto.getFaceDetectionMethodReal().getDescrizione() + " eta: " +
|
||||
timer.getEta((long)vec.getTotNumberOfRecords(), (long)(i + 1)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug("ECCEZIONE! " + e.getMessage());
|
||||
errMsg.append("\nDetect face fallita sul file " + rowFoto.getFileName() + "<br>" + e.getMessage());
|
||||
}
|
||||
rp.setMsg("Detect face completata.<br>Numero foto indicizzate:" + i + "<br> - Errori rilevati: " + errMsg.toString());
|
||||
rp.setStatus(true);
|
||||
for (int j = 0; j < vecF.getTotNumberOfRecords(); j++) {
|
||||
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
|
||||
rp = currentFuture.get();
|
||||
if (!rp.getStatus()) {
|
||||
errMsg.append(rp.getErrMsg() + "\n");
|
||||
} else {
|
||||
rp.append(rowFoto.updateCurrentFlgFaceScoringDone(1L));
|
||||
}
|
||||
DBAdapter.printDebug(debug2, currentFuture.get().getMsg() + " ended");
|
||||
if (i % 20 == 0)
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThread + " - face detected on foto " + j + " su " +
|
||||
vecF.getTotNumberOfRecords() + " eta: " + timer.getEta((long)vecF.getTotNumberOfRecords(), (long)(j + 1)));
|
||||
}
|
||||
vec = foto.findByEventoFaceScoringDone(this.evento.getId_evento(), 0L);
|
||||
totFotoSenzaVisi = (long)vec.getTotNumberOfRecords();
|
||||
StatusMsg.deleteMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG);
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + "FINE CICLO.. CONTROLLO FOTO SENZA VISI: TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current,: " + totFotoSenzaVisi);
|
||||
}
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + "USCITO CICLO SENZA VISI.. : TOTFOTOSENZA VISI= " + TAG_THREAD_MSG + " current,: " + totFotoSenzaVisi);
|
||||
pool.shutdown();
|
||||
} catch (Exception e) {
|
||||
err.append("ERRORE!! " + e.getMessage());
|
||||
err.append("\n");
|
||||
DBAdapter.printDebug(true, TAG_THREAD_MSG + "ERRORE!!!!! exc " + TAG_THREAD_MSG);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
timer.stop();
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + " " +
|
||||
timer.getDurataHourMin() + "\nerr: " + rp.getMsg());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "DETECT face foto concluso: DURATA: " + timer.getDurata() + "\nRisultato: " + rp.getMsg());
|
||||
Log.addAltro(this.evento.getApFull(), "127.0.0.1", 1L, " runFaceDetection1: FINE!!! :\n" +
|
||||
timer.getDurata() + "\nRisultato: " + rp.getMsg() + "\nerr: " + errMsg.toString());
|
||||
try {
|
||||
DBAdapter.sleepInMilliSecond(1000);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
StatusMsg.deleteMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG);
|
||||
DBAdapter.printDebug(debug, "🔵 [" + this.evento.getId_evento() + "] 1 FINE face detection");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "1 FINE face detection per evento ID " + this.evento.getId_evento());
|
||||
}
|
||||
|
||||
private void runScoring2() {
|
||||
DBAdapter.printDebug(debug, "🟠 [" + this.evento.getId_evento() + "] 2 Avvio scoring near...");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "2 Avvio scoring near per evento ID " + this.evento.getId_evento());
|
||||
boolean debug2 = true;
|
||||
String TAG_THREAD_MSG = "2 SCORING Ev.: " + this.evento.getId_evento();
|
||||
Timer timer = new Timer();
|
||||
timer.start();
|
||||
ResParm rp = new ResParm(true);
|
||||
long fotoCount = 0L;
|
||||
long faceCount = 0L;
|
||||
long faceTrovataCount = 0L;
|
||||
StringBuffer errMsg = new StringBuffer();
|
||||
String targetDir = this.evento.getParm("PATHFOTO_FACE").getTesto() + this.evento.getParm("PATHFOTO_FACE").getTesto();
|
||||
File targetDirFile = new File(targetDir);
|
||||
if (!targetDirFile.exists())
|
||||
targetDirFile.mkdirs();
|
||||
FaceScore fs = new FaceScore(this.evento.getApFull());
|
||||
Vectumerator<PuntoFoto> vecPf = this.evento.getPuntiFoto(0, 0);
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + " inizio ... vecpf.size: " + TAG_THREAD_MSG);
|
||||
int maxNumberOfThreadPf = this.evento.getParm("MAX_NUMBER_OF_THREAD_PF_SCORING_LVL_1").getNumeroInt();
|
||||
if (maxNumberOfThreadPf < 1)
|
||||
maxNumberOfThreadPf = vecPf.getTotNumberOfRecords();
|
||||
ExecutorService pool = Executors.newFixedThreadPool(maxNumberOfThreadPf);
|
||||
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
|
||||
Foto foto = new Foto(this.evento.getApFull());
|
||||
while (vecPf.hasMoreElements() && !this.threadSTOP) {
|
||||
PuntoFoto puntofoto = (PuntoFoto)vecPf.nextElement();
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + " current pf: " + TAG_THREAD_MSG + " " +
|
||||
puntofoto.getId_puntoFoto() + " .....");
|
||||
long numFotoPfDaElaborare = foto.getNumFotoFaceByPuntoFotoFaceScoringDone(puntofoto.getId_puntoFoto(), 1L);
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + " current pf: " + TAG_THREAD_MSG + " " + puntofoto.getId_puntoFoto() + "===> fotoface da elaborare: " + puntofoto.getDescrizione());
|
||||
if (numFotoPfDaElaborare <= 0L)
|
||||
continue;
|
||||
DBAdapter.printDebug(debug2, TAG_THREAD_MSG + " PF:" + TAG_THREAD_MSG + " evento id: " + puntofoto.getDescrizione() + " fotoface da elaborare: " + this.evento.getId_evento());
|
||||
fotoCount = 0L;
|
||||
Scoring2PuntoFotoCallable ifc = new Scoring2PuntoFotoCallable(this, puntofoto, TAG_THREAD_MSG + " pf: " + TAG_THREAD_MSG);
|
||||
DBAdapter.printDebug(debug2, "Submit pf " + puntofoto.getId_puntoFoto());
|
||||
vecF.add(pool.submit(ifc));
|
||||
puntofoto.setFlgStatoScoring(11L);
|
||||
puntofoto.save();
|
||||
}
|
||||
try {
|
||||
for (int j = 0; j < vecF.getTotNumberOfRecords(); j++) {
|
||||
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
|
||||
rp = currentFuture.get();
|
||||
DBAdapter.printDebug(debug2, "Future " + j + "/" + vecF.getTotNumberOfRecords() + ": rp: " + rp.getMsg());
|
||||
if (!rp.getStatus())
|
||||
errMsg.append(rp.getErrMsg() + "\n");
|
||||
DBAdapter.printDebug(currentFuture.get().getMsg() + " ended");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "max thread: " + maxNumberOfThreadPf + " reading future..... " + j + 1 + "/" +
|
||||
vecF.getTotNumberOfRecords() + 1);
|
||||
PuntoFoto pfFinito = (PuntoFoto)currentFuture.get().getReturnObj();
|
||||
if (!this.threadSTOP) {
|
||||
pfFinito.setFlgStatoScoring(1L);
|
||||
} else {
|
||||
pfFinito.setFlgStatoScoring(0L);
|
||||
}
|
||||
pfFinito.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Eccezione vecfuture: " + e.getMessage());
|
||||
}
|
||||
if (rp.getStatus()) {
|
||||
faceTrovataCount = fs.getTotoFaceScoreByEvento(this.evento.getId_evento());
|
||||
if (this.threadSTOP) {
|
||||
rp.setMsg("Evento Scoring STOP MANUALE!.<br>Numero foto:" + fotoCount + " facce: " + faceCount + " facce trovate: " + faceTrovataCount + "<br> - Errori rilevati: " +
|
||||
errMsg.toString());
|
||||
} else {
|
||||
rp.setMsg("Evento Scoring completato.<br>Numero foto: " + fotoCount + " facce: " + faceCount + " facce trovate: " + faceTrovataCount + "<br> - Errori rilevati: " +
|
||||
errMsg.toString());
|
||||
}
|
||||
rp.setStatus(true);
|
||||
}
|
||||
pool.shutdown();
|
||||
timer.stop();
|
||||
DBAdapter.printDebug(true, TAG_THREAD_MSG + " DURATA: " + TAG_THREAD_MSG + " " + timer.getDurata());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "Concluso fase 1: DURATA: " + timer.getDurata() + "\nRisultato: " + rp.getMsg());
|
||||
try {
|
||||
DBAdapter.sleepInMilliSecond(4000);
|
||||
} catch (Exception e) {}
|
||||
StatusMsg.deleteMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG);
|
||||
Log.addAltro(this.evento.getApFull(), "127.0.0.1", 1L, " fase1ScoringPuntifoto: FINE!!! :\n" +
|
||||
timer.getDurata() + "\nRisultato: " + rp.getMsg());
|
||||
DBAdapter.printDebug(debug, "🟠 [" + this.evento.getId_evento() + "] 2 FINE scoring: " + rp.getMsg());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "2 FINE scoring near per evento ID " +
|
||||
this.evento.getId_evento() + " " + rp.getMsg());
|
||||
}
|
||||
|
||||
private void runScoring3() {
|
||||
ResParm rp = new ResParm(true);
|
||||
try {
|
||||
DBAdapter.printDebug(debug, "🔴 [" + this.evento.getId_evento() + "] 3 Avvio scoring global...");
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "3 Avvio scoring global per evento ID " +
|
||||
this.evento.getId_evento());
|
||||
boolean debug2 = false;
|
||||
boolean debug3 = true;
|
||||
DBAdapter.printDebug(debug2, "# 1 # START");
|
||||
String TAG_THREAD_MSG = "3 SCORING Ev.: " + this.evento.getId_evento();
|
||||
SmartFaceScoringQueue smartFaceScoringQueue = SmartFaceScoringQueue.getInstance(this.evento.getApFull());
|
||||
Foto foto = new Foto(this.evento.getApFull());
|
||||
long fotoQuery = foto.getNumFotoFaceByEventoFaceScoringDone(this.evento.getId_evento(), 2L);
|
||||
DBAdapter.printDebug(debug2, "fotoQuery: " + fotoQuery);
|
||||
if (fotoQuery <= 0L) {
|
||||
rp.setStatus(true);
|
||||
rp.setMsg("Non ci sono face query. Niente da fare!");
|
||||
DBAdapter.printDebug(debug2, "FACCIO NIENTE");
|
||||
} else {
|
||||
DBAdapter.printDebug(debug2, "VADO AVANTI");
|
||||
StringBuffer errMsg = new StringBuffer();
|
||||
int priority = 1;
|
||||
int STEP_STATUS_MSG = 100;
|
||||
Timer timer = new Timer();
|
||||
Timer timerTarget = new Timer();
|
||||
long currentTargetTime = 0L;
|
||||
double currentTargetVelox = 0.0D, actualTargetVelox = 0.0D;
|
||||
String targetDir = this.evento.getParm("PATHFOTO_FACE").getTesto() + this.evento.getParm("PATHFOTO_FACE").getTesto();
|
||||
File targetDirFile = new File(targetDir);
|
||||
if (!targetDirFile.exists())
|
||||
targetDirFile.mkdirs();
|
||||
double confDetectLevel = this.evento.getDetectFaceConfidentThresold();
|
||||
long dysType = this.evento.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
|
||||
int targetUniti = 0;
|
||||
int targetProcessati = 0;
|
||||
FaceScore fs = new FaceScore(this.evento.getApFull());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "1. QUERY TARGET X EVENTO......");
|
||||
DBAdapter.printDebug(debug2, "1. QUERY TARGET X EVENTO......");
|
||||
Vectumerator<FaceScore> vecFsTarget = fs.findTargetByEvento(this.evento.getId_evento(), 2L);
|
||||
DBAdapter.printDebug(debug2, "1.1 vecFsTarget.getTotNumberOfRecords(): " +
|
||||
vecFsTarget.getTotNumberOfRecords() + " threadSTOP: " + this.threadSTOP);
|
||||
timer.start();
|
||||
int i = 0;
|
||||
JsonArray jsonQueryArray = new JsonArray();
|
||||
JsonArray jsonTargetDoneArray = new JsonArray();
|
||||
JsonObject jsonData = new JsonObject();
|
||||
jsonData.addProperty("dis_type", Long.valueOf(dysType));
|
||||
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
|
||||
FaceScore currentFs = null;
|
||||
JsonObject jsonTarget = null;
|
||||
String eta = "....";
|
||||
String puntoFotoDesc = "";
|
||||
long l_id_fotoTarget = 0L;
|
||||
while (vecFsTarget.hasMoreElements() && !this.threadSTOP &&
|
||||
!Thread.currentThread().isInterrupted()) {
|
||||
currentFs = (FaceScore)vecFsTarget.nextElement();
|
||||
puntoFotoDesc = currentFs.getFotoFace2().getFoto().getPuntoFoto().getDescrizione();
|
||||
DBAdapter.printDebug(false, "2. creazione query globale: current punto foto:" + puntoFotoDesc + " (" + i + "/" +
|
||||
vecFsTarget.getTotNumberOfRecords() + ") currentFs.getId_fotoFace(): " + currentFs.getId_fotoFace() + " scoring_done_val: " +
|
||||
currentFs.getFotoFace().getFoto().getFlgFaceScoringDone());
|
||||
if (i % STEP_STATUS_MSG == 0)
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "2. creazione query globale: current punto foto:" + puntoFotoDesc + " (" + i + "/" +
|
||||
vecFsTarget.getTotNumberOfRecords() + ")");
|
||||
JsonObject jsonQueryRow = new JsonObject();
|
||||
jsonQueryRow.addProperty("id", Long.valueOf(currentFs.getId_fotoFace()));
|
||||
jsonQueryRow.addProperty("id_foto", Long.valueOf(currentFs.getFotoFace().getId_foto()));
|
||||
jsonQueryRow.addProperty("path", currentFs.getFotoFace().getFacePath());
|
||||
jsonQueryRow.addProperty("md5", currentFs.getFotoFace().getMd5());
|
||||
jsonQueryRow.addProperty("type", "face");
|
||||
i++;
|
||||
if (currentFs.getFotoFace().getFoto().getFlgFaceScoringDone() == 3L) {
|
||||
jsonTargetDoneArray.add((JsonElement)jsonQueryRow);
|
||||
DBAdapter.printDebug(debug2, "ciclo creo query e targetDone. aggiunto targetDone");
|
||||
}
|
||||
if (currentFs.getFotoFace().getFoto().getFlgFaceScoringDone() == 2L) {
|
||||
jsonQueryArray.add((JsonElement)jsonQueryRow);
|
||||
DBAdapter.printDebug(debug2, "ciclo creo query e targetDone. aggiunto jsonQueryArray");
|
||||
}
|
||||
}
|
||||
DBAdapter.printDebug(debug2, "fine while");
|
||||
JsonArray jsonTargetArray = new JsonArray();
|
||||
for (JsonElement elem : (Iterable<JsonElement>)jsonTargetDoneArray)
|
||||
jsonTargetArray.add(elem);
|
||||
for (JsonElement elem : (Iterable<JsonElement>)jsonQueryArray)
|
||||
jsonTargetArray.add(elem);
|
||||
DBAdapter.printDebug(debug2, "jsonTargetDoneArray: " + jsonTargetDoneArray.size());
|
||||
DBAdapter.printDebug(debug2, "jsonQueryArray: " + jsonQueryArray.size());
|
||||
DBAdapter.printDebug(debug2, "jsonTargetArray: " + jsonTargetArray.size());
|
||||
long totConfrontiFatti = 0L;
|
||||
long totConfrontiTarget = 0L;
|
||||
long totMd5Toremove = 0L;
|
||||
double mediaMd5ToRemove = 0.0D;
|
||||
i = 0;
|
||||
long l_id_curretFoto = 0L;
|
||||
while (jsonTargetArray.size() > 0 && !this.threadSTOP) {
|
||||
timerTarget.start();
|
||||
i++;
|
||||
totConfrontiTarget = (long)jsonTargetArray.size();
|
||||
totConfrontiFatti += (long)jsonTargetArray.size();
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "3 MAIN. actualTargetVelox: " +
|
||||
this.evento.getNf().format(actualTargetVelox) + " targ./sec currentTargetTime: " + currentTargetTime + " sec. currentTargetVelox: " +
|
||||
|
||||
this.evento.getNf().format(currentTargetVelox) + " conf/sec punto foto:" + puntoFotoDesc + " (" + i + "/" +
|
||||
jsonTargetArray.size() + ") target uniti: " + targetUniti + " mediaMd5ToRemove: " + mediaMd5ToRemove + " ..... ETA: " + eta + "\n" +
|
||||
smartFaceScoringQueue.getStatus());
|
||||
AppStats.setScoring7CurrentTargetVelox(currentTargetVelox);
|
||||
AppStats.setScoring7ETA(eta);
|
||||
targetProcessati++;
|
||||
jsonTarget = jsonTargetArray.get(0).getAsJsonObject();
|
||||
jsonData.add("target", (JsonElement)jsonTarget);
|
||||
l_id_fotoTarget = jsonTarget.get("id_foto").getAsLong();
|
||||
long l_id_fotoFacequery1 = jsonQueryArray.get(0).getAsJsonObject().get("id").getAsLong();
|
||||
if (l_id_fotoFacequery1 == jsonTarget.get("id").getAsLong()) {
|
||||
jsonQueryArray.remove(0);
|
||||
DBAdapter.printDebug(debug2, "# 2 # tolto il target da jsonQueryArray perchè stesso id_fotoFace di target (corretto se non ci sono global2 done) l_id_fotoFacequery1: " + l_id_fotoFacequery1);
|
||||
}
|
||||
DBAdapter.printDebug(debug2, "# 2.1 # scoring target: " +
|
||||
currentFs.getId_fotoFace() + " jsonTargetArray.size(): " + jsonTargetArray.size());
|
||||
JsonArray jsonQueryCopy = jsonQueryArray.deepCopy();
|
||||
JsonObject jsonTargetCopy = jsonTarget.deepCopy();
|
||||
DBAdapter.printDebug(debug2, "# 3 # inizio scoring - " + smartFaceScoringQueue.getStatus());
|
||||
Vectumerator<Future<ResParm>> vecF = smartFaceScoringQueue.faceScoring(this.evento, jsonQueryCopy, jsonTargetCopy, confDetectLevel, priority);
|
||||
DBAdapter.printDebug(debug2, "# 4 # future arrivato");
|
||||
DBAdapter.printDebug(debug2, "# 5 # vecF.getTotNumberOfRecords(): " + vecF.getTotNumberOfRecords());
|
||||
DBAdapter.printDebug(debug2, "# 6 # FUTURE start vecF.getTotNumberOfRecords():" + vecF.getTotNumberOfRecords());
|
||||
Set<String> md5ToRemove = new HashSet<>();
|
||||
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
|
||||
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
|
||||
if (currentFuture == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore: Future null per indice " + fidx);
|
||||
DBAdapter.printDebug(debug2, "# 7 # null Errore: Future null per indice " + fidx);
|
||||
} else {
|
||||
try {
|
||||
rp = currentFuture.get(45L, TimeUnit.SECONDS);
|
||||
} catch (TimeoutException e) {
|
||||
DBAdapter.printDebug(debug2, "# 8 # Errore Timeout su future index " + fidx + ", ignorando.");
|
||||
} catch (InterruptedException e) {
|
||||
DBAdapter.printDebug(debug2, "# 9 # Errore Interruzione rilevata, terminazione del ciclo.");
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (ExecutionException e) {
|
||||
DBAdapter.printDebug(debug2, "# 10 # Errore durante l'esecuzione del task " + fidx + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug(debug2, "# 11 # Errore generico su future index " + fidx + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!rp.getStatus()) {
|
||||
DBAdapter.printDebug((debug || debug2), "# 12 # errore future: " + rp.getMsg());
|
||||
errMsg.append(rp.getErrMsg() + "\n");
|
||||
DBAdapter.printDebug(debug2, "# 13 # errore future: " + rp.getMsg());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "4 FUTURE. currentTargetTime: " + currentTargetTime + " sec. punto foto:" + puntoFotoDesc + " (" + i + "/" +
|
||||
|
||||
jsonTargetArray.size() + ") target uniti: " + targetUniti + " mediaMd5ToRemove: " + mediaMd5ToRemove + " future: " + fidx + "/" +
|
||||
vecF.getTotNumberOfRecords() + " - " + eta + "\n" +
|
||||
smartFaceScoringQueue.getStatus());
|
||||
AppStats.setScoring7CurrentTargetVelox(currentTargetVelox);
|
||||
AppStats.setScoring7ETA(eta);
|
||||
} else {
|
||||
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
|
||||
if (hsFs != null) {
|
||||
if (debug || debug2)
|
||||
DBAdapter.printDebug(debug2, "# 14 # FS UNITI.... LI TOLGO DA HASHMAP se LSH SIZE>0 ===> CURRENT LSH SIZE: " +
|
||||
hsFs.size());
|
||||
int hsIdx = 0;
|
||||
for (FaceScore fsTargetSul2 : hsFs) {
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG, "5 CLEAN MD5. actualTargetVelox: " +
|
||||
this.evento.getNf().format(actualTargetVelox) + " targ./sec currentTargetTime: " + currentTargetTime + " sec. currentTargetVelox: " +
|
||||
|
||||
this.evento.getNf().format(currentTargetVelox) + " conf/sec punto foto:" + puntoFotoDesc + " (" + i + "/" +
|
||||
jsonTargetArray.size() + ") target uniti: " + targetUniti + "/" + targetProcessati + " mediaMd5ToRemove: " + mediaMd5ToRemove + " future: " + fidx + "/" +
|
||||
|
||||
vecF.getTotNumberOfRecords() + " unisci target " + hsIdx + "/" + hsFs.size() + " - " + eta + "\n" +
|
||||
smartFaceScoringQueue.getStatus());
|
||||
rp = fs.unisciTarget(jsonTarget.get("id").getAsLong(),
|
||||
fsTargetSul2.getId_fotoFace2());
|
||||
targetUniti++;
|
||||
md5ToRemove.add(fsTargetSul2.getFotoFace2().getMd5());
|
||||
hsIdx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DBAdapter.printDebug(debug2, "# 15 # . ciclo future finito faccio shutdown ");
|
||||
if (md5ToRemove.size() > 0) {
|
||||
JsonArray newJsonQuery = new JsonArray();
|
||||
DBAdapter.printDebug(debug2, "# 16 # MD5 DA RIMUOVERE:" +
|
||||
md5ToRemove.size() + " ...... : creo newJsonQuery e lo copio su jsonQuery ");
|
||||
for (int j = jsonQueryArray.size() - 1; j >= 0; j--) {
|
||||
JsonObject item = jsonQueryArray.get(j).getAsJsonObject();
|
||||
String currentMd5 = item.get("md5").getAsString();
|
||||
if (!md5ToRemove.contains(currentMd5)) {
|
||||
newJsonQuery.add((JsonElement)item);
|
||||
DBAdapter.printDebug(false, "# 19 # newJsonQuery.add jsonQuery size:" + jsonQueryArray.size() + " newJsonQuery size : " +
|
||||
newJsonQuery.size());
|
||||
} else {
|
||||
DBAdapter.printDebug(debug2, "# 20 # rimosso : " + currentMd5);
|
||||
}
|
||||
}
|
||||
jsonQueryArray = newJsonQuery.deepCopy();
|
||||
} else {
|
||||
DBAdapter.printDebug(debug2, "# 21 # NIENTE DA RIMUOVERE estraggo target e tolgo primo elemento a query ");
|
||||
}
|
||||
if (l_id_curretFoto == 0L) {
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
} else if (l_id_curretFoto != l_id_fotoTarget) {
|
||||
foto.findByPrimaryKey(l_id_curretFoto);
|
||||
if (foto.getFlgFaceScoringDone() != 3L) {
|
||||
foto.updateCurrentFlgFaceScoringDone(3L);
|
||||
DBAdapter.printDebug(true, "# XXXX # updateCurrentFlgFaceScoringDone FACE_SCORING_DONE_GLOBAL_3 FOTO " +
|
||||
foto.getFileName() + " id: " + foto.getId_foto());
|
||||
} else {
|
||||
DBAdapter.printDebug(true, "# YYYY # updateCurrentFlgFaceScoringDone NON AGGIORNATO PERCHE' IL SUO STATO E' : " +
|
||||
|
||||
foto.getFaceScoringDone() + " FOTO " + foto.getFileName() + " id: " + foto.getId_foto());
|
||||
}
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
}
|
||||
jsonTargetArray = new JsonArray();
|
||||
if (jsonTargetDoneArray.size() > 0)
|
||||
for (int j = i; j < jsonTargetDoneArray.size(); j++)
|
||||
jsonTargetArray.add(jsonTargetDoneArray.get(j));
|
||||
for (JsonElement elem : (Iterable<JsonElement>)jsonQueryArray)
|
||||
jsonTargetArray.add(elem);
|
||||
totMd5Toremove += (long)md5ToRemove.size();
|
||||
mediaMd5ToRemove = (double)(totMd5Toremove / (long)i);
|
||||
DBAdapter.printDebug(debug2, "# 22 # fine ciclo rimozione md5! totMd5Toremove: " + totMd5Toremove + " cicli i: " + i + " mediaMd5ToRemove: " + mediaMd5ToRemove);
|
||||
DBAdapter.printDebug(debug2, "# 23 # nuova query ripulita dei target trovati. jsonQueryArray.size: " +
|
||||
jsonQueryArray.size());
|
||||
DBAdapter.printDebug(debug2, "# 23.1 # nuova TARGET ripulita dei target trovati. jsonTargetArray.size: " +
|
||||
jsonTargetArray.size());
|
||||
DBAdapter.printDebug(debug2, "# 24 # FUTURE STOP. faccio shutdown ");
|
||||
smartFaceScoringQueue.poolShutdown();
|
||||
DBAdapter.printDebug(debug2, "# 25 #. shutdown concluso ");
|
||||
DBAdapter.printDebug(debug2, "# 26 # tot confronti fatti:" + totConfrontiFatti);
|
||||
timerTarget.stop();
|
||||
if (currentTargetTime == 0L) {
|
||||
currentTargetTime = timerTarget.getDurataSecLong();
|
||||
currentTargetVelox = (double)totConfrontiTarget / (double)timerTarget.getDurataMilliSec() * 1000.0D;
|
||||
}
|
||||
long numeroQueryRimanenti = (long)jsonQueryArray.size();
|
||||
long stimaConfrontiDaFare = Evento.stimaConfrontiMergeAggressivo(numeroQueryRimanenti, (double)numeroQueryRimanenti);
|
||||
eta = timer.getEta(stimaConfrontiDaFare, totConfrontiFatti);
|
||||
DBAdapter.printDebug(debug3, "# ETA # numeroQueryRimanenti: " + numeroQueryRimanenti + " numeroQueryRimanenti: " + numeroQueryRimanenti + " stimaConfrontiDaFare: " + stimaConfrontiDaFare + "currentTargetVelox: " + currentTargetVelox + " actualTargetVelox: " + actualTargetVelox + " currentTargetTime: " + currentTargetTime);
|
||||
actualTargetVelox = (double)totConfrontiFatti / (double)timer.getDurataMilliSec() * 1000.0D;
|
||||
DBAdapter.printDebug(debug2, "# 27 # FUTURE STOP currentTargetVelox: " + currentTargetVelox + " actualTargetVelox: " + actualTargetVelox + " currentTargetTime: " + currentTargetTime);
|
||||
}
|
||||
if (l_id_curretFoto != 0L) {
|
||||
foto.findByPrimaryKey(l_id_curretFoto);
|
||||
if (foto.getFlgFaceScoringDone() != 3L) {
|
||||
foto.updateCurrentFlgFaceScoringDone(3L);
|
||||
DBAdapter.printDebug(true, "# XXXX L # updateCurrentFlgFaceScoringDone FACE_SCORING_DONE_GLOBAL_3 FOTO " +
|
||||
foto.getFileName() + " id: " + foto.getId_foto());
|
||||
} else {
|
||||
DBAdapter.printDebug(true, "# YYYY L # updateCurrentFlgFaceScoringDone NON AGGIORNATO PERCHE' IL SUO STATO E' : " +
|
||||
foto.getFaceScoringDone() + " FOTO " + foto.getFileName() + " id: " + foto.getId_foto());
|
||||
}
|
||||
l_id_curretFoto = l_id_fotoTarget;
|
||||
}
|
||||
timer.stop();
|
||||
DBAdapter.printDebug(debug2, "# 28 # FINE!!!: " + timer.getDurata());
|
||||
StatusMsg.deleteMsgByTag(this.evento.getApFull(), TAG_THREAD_MSG);
|
||||
Log.addAltro(this.evento.getApFull(), "127.0.0.1", 1L, " fase7ScoringTargetSuTargetPerEvento: FINE!!! Target uniti/processati:" + targetUniti + "/" + targetProcessati + " mediaMd5ToRemove: " + mediaMd5ToRemove + " currentTargetVelox: " +
|
||||
|
||||
|
||||
this.evento.getNf().format(currentTargetVelox) + " conf/sec currentTargetTime: " + currentTargetTime + " sec.\n" +
|
||||
timer.getDurata() + "\nRisultato: " + rp.getMsg());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug("# 99 # ECCEZIONE SCORING 3!!!!! " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
rp.setStatus(false);
|
||||
rp.setException(e);
|
||||
}
|
||||
DBAdapter.printDebug(debug, "🔴 [" + this.evento.getId_evento() + "] 3 scoring FINE: " + rp.getMsg());
|
||||
StatusMsg.updateMsgByTag(this.evento.getApFull(), "DISPATCHER", "3 FINE scoring global per evento ID " +
|
||||
this.evento.getId_evento() + " " + rp.getMsg());
|
||||
}
|
||||
|
||||
public static void shutdown(Evento evento) {
|
||||
EventoProcessingDispatcher dispatcher = activeDispatchers.remove(Long.valueOf(evento.getId_evento()));
|
||||
if (dispatcher != null)
|
||||
dispatcher.shutdown();
|
||||
}
|
||||
|
||||
private void shutdown() {
|
||||
if (this.isRunning.compareAndSet(true, false)) {
|
||||
this.threadSTOP = true;
|
||||
this.scheduler.shutdown();
|
||||
activeDispatchers.remove(Long.valueOf(this.evento.getId_evento()));
|
||||
DBAdapter.printDebug(debug, "🛑 Dispatcher arrestato per evento ID " + this.evento.getId_evento());
|
||||
StatusMsg.deleteMsgByTag(this.evento.getApFull(), "DISPATCHER");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRunningForEvento(long idEvento) {
|
||||
return activeDispatchers.containsKey(Long.valueOf(idEvento));
|
||||
}
|
||||
|
||||
public static void shutdownAll() {
|
||||
for (EventoProcessingDispatcher d : activeDispatchers.values())
|
||||
d.shutdown();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Evento ev = new Evento();
|
||||
EventoProcessingDispatcher d = new EventoProcessingDispatcher(ev);
|
||||
d.startProcessingLoop();
|
||||
Executors.newSingleThreadScheduledExecutor().schedule(() ->
|
||||
ev.setFlgProcessing(0L), 30L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public Evento getEvento() {
|
||||
return this.evento;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package it.acxent.face.dispatcher;
|
||||
|
||||
import it.acxent.db.DBAdapter;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ScoringManager {
|
||||
private static final BlockingQueue<ScoringTask> scoring2Queue = new LinkedBlockingQueue<>();
|
||||
|
||||
private static final BlockingQueue<ScoringTask> scoring3Queue = new LinkedBlockingQueue<>();
|
||||
|
||||
private static final Set<Long> eventiInCodaScoring2 = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private static final Set<Long> eventiInCodaScoring3 = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private static final AtomicReference<Thread> scoring3Thread = new AtomicReference<>();
|
||||
|
||||
private static final AtomicBoolean executorStarted = new AtomicBoolean(false);
|
||||
|
||||
public static void start() {
|
||||
new Thread(ScoringManager::runExecutor, "ScoringTaskExecutor").start();
|
||||
}
|
||||
|
||||
public static void submitTask(ScoringTask task) {
|
||||
if (executorStarted.compareAndSet(false, true))
|
||||
start();
|
||||
if (task.type == ScoringType.SCORING2) {
|
||||
if (eventiInCodaScoring2.add(Long.valueOf(task.idEvento)))
|
||||
scoring2Queue.offer(task);
|
||||
} else if (eventiInCodaScoring3.add(Long.valueOf(task.idEvento))) {
|
||||
scoring3Queue.offer(task);
|
||||
}
|
||||
}
|
||||
|
||||
private static void runExecutor() {
|
||||
int ciclo = 0;
|
||||
try {
|
||||
while (true) {
|
||||
if (++ciclo % 10 == 0)
|
||||
printStatoCorrente();
|
||||
ScoringTask task = scoring2Queue.poll(1L, TimeUnit.SECONDS);
|
||||
if (task != null) {
|
||||
eventiInCodaScoring2.remove(Long.valueOf(task.idEvento));
|
||||
logEsecuzione("scoring2", task.idEvento);
|
||||
task.action.run();
|
||||
continue;
|
||||
}
|
||||
ScoringTask scoring3task = scoring3Queue.poll(1L, TimeUnit.SECONDS);
|
||||
if (scoring3task != null) {
|
||||
eventiInCodaScoring3.remove(Long.valueOf(scoring3task.idEvento));
|
||||
logEsecuzione("scoring3", scoring3task.idEvento);
|
||||
Thread current = new Thread(() -> {
|
||||
try {
|
||||
scoring3task.action.run();
|
||||
} catch (Exception e) {}
|
||||
}, "Scoring3-Task");
|
||||
scoring3Thread.set(current);
|
||||
current.start();
|
||||
while (current.isAlive()) {
|
||||
if (!scoring2Queue.isEmpty()) {
|
||||
current.interrupt();
|
||||
break;
|
||||
}
|
||||
Thread.sleep(200L);
|
||||
}
|
||||
scoring3Thread.set(null);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void printStatoCorrente() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("📋 STATO SCORING\n");
|
||||
Thread t = scoring3Thread.get();
|
||||
if (t != null && t.isAlive())
|
||||
sb.append("🟡 In esecuzione: scoring3\n");
|
||||
sb.append("📥 In coda SCORING2 (eventi): ");
|
||||
scoring2Queue.forEach(task -> sb.append(task.idEvento).append(" "));
|
||||
sb.append("\n");
|
||||
sb.append("📥 In coda SCORING3 (eventi): ");
|
||||
scoring3Queue.forEach(task -> sb.append(task.idEvento).append(" "));
|
||||
sb.append("\n");
|
||||
DBAdapter.printDebug(sb.toString());
|
||||
}
|
||||
|
||||
private static void logEsecuzione(String tipo, long idEvento) {
|
||||
DBAdapter.printDebug("▶️ Esecuzione " + tipo + " per evento ID " + idEvento + " @ " + System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package it.acxent.face.dispatcher;
|
||||
|
||||
public class ScoringTask {
|
||||
public final long idEvento;
|
||||
|
||||
public final ScoringType type;
|
||||
|
||||
public final Runnable action;
|
||||
|
||||
public ScoringTask(long idEvento, ScoringType type, Runnable action) {
|
||||
this.idEvento = idEvento;
|
||||
this.type = type;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package it.acxent.face.dispatcher;
|
||||
|
||||
public enum ScoringType {
|
||||
SCORING2, SCORING3;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.dispatcher;
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Face extends DBAdapter implements Serializable {
|
||||
public static final String PATH_IMG_FACE = "_face/";
|
||||
|
||||
private static final long serialVersionUID = 1701107257097L;
|
||||
|
||||
private long id_face;
|
||||
|
||||
private String md5;
|
||||
|
||||
public Face(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public Face() {}
|
||||
|
||||
public void setId_face(long newId_face) {
|
||||
this.id_face = newId_face;
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public long getId_face() {
|
||||
return this.id_face;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<Face> findByCR(FaceCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
if (!CR.getLabel().isEmpty())
|
||||
wc.addWc("A.label ='" + CR.getLabel() + "'");
|
||||
if (!CR.getMd5().isEmpty())
|
||||
wc.addWc("A.md5 ='" + CR.getMd5() + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void xxfindByMd5Recognition(String l_md5) {
|
||||
String s_Sql_Find = "select A.* from FACE 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 String getFullFileName() {
|
||||
return getPathFaceImg() + getPathFaceImg() + ".jpg";
|
||||
}
|
||||
|
||||
public String getPathFaceImg() {
|
||||
return getParm("path_img_base").getTesto() + "_face/" + getParm("path_img_base").getTesto();
|
||||
}
|
||||
|
||||
public String getPathIdStepDir() {
|
||||
if (getPathIdStep() <= 0L)
|
||||
return "";
|
||||
if (getId_face() == 0L)
|
||||
System.out.println("getPathIdStepDir pio");
|
||||
return "_" + getPathIdStep() * (getId_face() / getPathIdStep() + 1L) + "/";
|
||||
}
|
||||
|
||||
public ResParm superSave() {
|
||||
return save();
|
||||
}
|
||||
|
||||
public void findByMd5(String l_md5) {
|
||||
String s_Sql_Find = "select A.* from FACE 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 void findByLabel(long l_label) {
|
||||
String s_Sql_Find = "select A.* from FACE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_face=" + l_label);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FaceCR extends CRAdapter {
|
||||
private long id_face;
|
||||
|
||||
private String md5;
|
||||
|
||||
private String label;
|
||||
|
||||
public FaceCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceCR() {}
|
||||
|
||||
public void setId_face(long newId_face) {
|
||||
this.id_face = newId_face;
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public void setLabel(String newLabel) {
|
||||
this.label = newLabel;
|
||||
}
|
||||
|
||||
public long getId_face() {
|
||||
return this.id_face;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return (this.label == null) ? "" : this.label.trim();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class FaceFaceRecognizer extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1724847547826L;
|
||||
|
||||
private long id_faceFaceRecognizer;
|
||||
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private long id_face;
|
||||
|
||||
private long id_faceLabel;
|
||||
|
||||
private long flgLock;
|
||||
|
||||
private FaceRecognizer faceRecognizer;
|
||||
|
||||
private Face face;
|
||||
|
||||
private Face faceLabel;
|
||||
|
||||
public FaceFaceRecognizer(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceFaceRecognizer() {}
|
||||
|
||||
public void setId_faceFaceRecognizer(long newId_faceFaceRecognizer) {
|
||||
this.id_faceFaceRecognizer = newId_faceFaceRecognizer;
|
||||
}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
setFaceRecognizer(null);
|
||||
}
|
||||
|
||||
public void setId_face(long newId_face) {
|
||||
this.id_face = newId_face;
|
||||
setFace(null);
|
||||
}
|
||||
|
||||
public void setId_faceLabel(long newId_faceLabel) {
|
||||
this.id_faceLabel = newId_faceLabel;
|
||||
setFaceLabel(null);
|
||||
}
|
||||
|
||||
public void setFlgLock(long newFlgLock) {
|
||||
this.flgLock = newFlgLock;
|
||||
}
|
||||
|
||||
public long getId_faceFaceRecognizer() {
|
||||
return this.id_faceFaceRecognizer;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public long getId_face() {
|
||||
return this.id_face;
|
||||
}
|
||||
|
||||
public long getId_faceLabel() {
|
||||
return this.id_faceLabel;
|
||||
}
|
||||
|
||||
public long getFlgLock() {
|
||||
return this.flgLock;
|
||||
}
|
||||
|
||||
public void setFaceRecognizer(FaceRecognizer newFaceRecognizer) {
|
||||
this.faceRecognizer = newFaceRecognizer;
|
||||
}
|
||||
|
||||
public FaceRecognizer getFaceRecognizer() {
|
||||
this.faceRecognizer = (FaceRecognizer)getSecondaryObject(this.faceRecognizer, FaceRecognizer.class, getId_faceRecognizer());
|
||||
return this.faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFace(Face newFace) {
|
||||
this.face = newFace;
|
||||
}
|
||||
|
||||
public Face getFace() {
|
||||
this.face = (Face)getSecondaryObject(this.face, Face.class, getId_face());
|
||||
return this.face;
|
||||
}
|
||||
|
||||
public void setFaceLabel(Face newFaceLabel) {
|
||||
this.faceLabel = newFaceLabel;
|
||||
}
|
||||
|
||||
public Face getFaceLabel() {
|
||||
this.faceLabel = (Face)getSecondaryObject(this.faceLabel, Face.class, getId_faceLabel());
|
||||
return this.faceLabel;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FaceFaceRecognizer> findByCR(FaceFaceRecognizerCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLabelPrincipale() {
|
||||
if (getId_faceFaceRecognizer() > 0L && getId_face() == getId_faceLabel())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public ResParm resetTrainingByFaceRecognizer(long l_id_facerecognizer) {
|
||||
return update("update FACE_FACE_RECOGNIZER SET id_facelabel=null where id_faceRecognizer=" + l_id_facerecognizer);
|
||||
}
|
||||
|
||||
public void findByRecognizerLabel(long l_id_faceRecognizer, long l_label) {
|
||||
String s_Sql_Find = "select A.* from FACE_FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_faceRecognizer=" + l_id_faceRecognizer);
|
||||
wc.addWc("A.id_face=" + l_label);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public long getTotFaceByFaceRecognizer(long l_id_faceRecognizer) {
|
||||
String s_Sql_Find = "select count(*) as tot from FACE_FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_faceRecognizer=" + l_id_faceRecognizer);
|
||||
wc.addWc("A.id_faceLabel>0");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return (long)getTots(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FaceFaceRecognizer> findByFaceRecognizer(long l_id_faceRecognizer, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_faceRecognizer=" + l_id_faceRecognizer);
|
||||
wc.addWc("A.id_faceLabel>0");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FaceFaceRecognizerCR extends CRAdapter {
|
||||
private static final long serialVersionUID = 3284264235323747301L;
|
||||
|
||||
private long id_faceFaceRecognizer;
|
||||
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private long id_face;
|
||||
|
||||
private long id_faceLabel;
|
||||
|
||||
private long flgLock;
|
||||
|
||||
private FaceRecognizer faceRecognizer;
|
||||
|
||||
private Face face;
|
||||
|
||||
private Face faceLabel;
|
||||
|
||||
public FaceFaceRecognizerCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceFaceRecognizerCR() {}
|
||||
|
||||
public void setId_faceFaceRecognizer(long newId_faceFaceRecognizer) {
|
||||
this.id_faceFaceRecognizer = newId_faceFaceRecognizer;
|
||||
}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
setFaceRecognizer(null);
|
||||
}
|
||||
|
||||
public void setId_face(long newId_face) {
|
||||
this.id_face = newId_face;
|
||||
setFace(null);
|
||||
}
|
||||
|
||||
public void setId_faceLabel(long newId_faceLabel) {
|
||||
this.id_faceLabel = newId_faceLabel;
|
||||
setFaceLabel(null);
|
||||
}
|
||||
|
||||
public void setFlgLock(long newFlgLock) {
|
||||
this.flgLock = newFlgLock;
|
||||
}
|
||||
|
||||
public long getId_faceFaceRecognizer() {
|
||||
return this.id_faceFaceRecognizer;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public long getId_face() {
|
||||
return this.id_face;
|
||||
}
|
||||
|
||||
public long getId_faceLabel() {
|
||||
return this.id_faceLabel;
|
||||
}
|
||||
|
||||
public long getFlgLock() {
|
||||
return this.flgLock;
|
||||
}
|
||||
|
||||
public void setFaceRecognizer(FaceRecognizer newFaceRecognizer) {
|
||||
this.faceRecognizer = newFaceRecognizer;
|
||||
}
|
||||
|
||||
public FaceRecognizer getFaceRecognizer() {
|
||||
this.faceRecognizer = (FaceRecognizer)getSecondaryObject(this.faceRecognizer, FaceRecognizer.class,
|
||||
|
||||
getId_faceRecognizer());
|
||||
return this.faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFace(Face newFace) {
|
||||
this.face = newFace;
|
||||
}
|
||||
|
||||
public Face getFace() {
|
||||
this.face = (Face)getSecondaryObject(this.face, Face.class,
|
||||
|
||||
getId_face());
|
||||
return this.face;
|
||||
}
|
||||
|
||||
public void setFaceLabel(Face newFaceLabel) {
|
||||
this.faceLabel = newFaceLabel;
|
||||
}
|
||||
|
||||
public Face getFaceLabel() {
|
||||
this.faceLabel = (Face)getSecondaryObject(this.faceLabel, Face.class,
|
||||
|
||||
getId_faceLabel());
|
||||
return this.faceLabel;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,554 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.face.api.opencv.FaceRecognition;
|
||||
import it.acxent.face.api.opencv.TrainingImage;
|
||||
import it.acxent.util.Timer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.face.EigenFaceRecognizer;
|
||||
import org.opencv.face.FisherFaceRecognizer;
|
||||
import org.opencv.face.LBPHFaceRecognizer;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
public class FaceRecognizer extends it.acxent.dm.FaceRecognizer implements Serializable {
|
||||
class ThreadCaricaModelli extends Thread {
|
||||
private FaceRecognizerCR CR;
|
||||
|
||||
private boolean useFile = false;
|
||||
|
||||
public ThreadCaricaModelli(FaceRecognizerCR l_CR, boolean l_usaFile) {
|
||||
this.CR = l_CR;
|
||||
this.useFile = l_usaFile;
|
||||
if (!FaceRecognizer.threadCaricaModelli) {
|
||||
FaceRecognizer.threadCaricaModelli = true;
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
boolean debug = true;
|
||||
String TAG_THREAD_MSG = " CACHE MODELS ";
|
||||
Timer timerTotal = new Timer();
|
||||
Timer timer = new Timer();
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " CACHE MODELS FaceRecognition.getInstance ");
|
||||
FaceRecognition.getInstance(FaceRecognizer.this.getApFull());
|
||||
timerTotal.start();
|
||||
Vectumerator<FaceRecognizer> vec = FaceRecognizer.this.findByCR(this.CR, 0, 0);
|
||||
int i = 0;
|
||||
while (vec.hasMoreElements()) {
|
||||
i++;
|
||||
FaceRecognizer row = (FaceRecognizer)vec.nextElement();
|
||||
if (this.useFile) {
|
||||
if (row.isModelFileExist(0L)) {
|
||||
timer.start();
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " CACHE MODELS Recognizer modelli files " + String.valueOf(DBAdapter.getNow()) + " ...." + row.getCodice());
|
||||
StatusMsg.updateMsgByTag(FaceRecognizer.this.getApFull(), " CACHE MODELS ", " Recognizer " + row.getCodice() + " ...." + String.valueOf(timer.getTStart()));
|
||||
row.precaricaModelliFiles();
|
||||
timer.stop();
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " CACHE MODELS Recognizer modelli files " + String.valueOf(DBAdapter.getNow()) + " ...." + row.getCodice());
|
||||
continue;
|
||||
}
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " CACHE MODELS Recognizer modelli files " + String.valueOf(DBAdapter.getNow()) + " FILE NON TROVATO: " + row.getCodice());
|
||||
continue;
|
||||
}
|
||||
if (row.getFlgDisabilita() == 0L) {
|
||||
timer.start();
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " CACHE MODELS Recognizer by training " + String.valueOf(DBAdapter.getNow()) + " ...." + row.getCodice());
|
||||
StatusMsg.updateMsgByTag(FaceRecognizer.this.getApFull(), " CACHE MODELS ", " Recognizer " + row.getCodice() + " ...." + String.valueOf(timer.getTStart()));
|
||||
row.precaricaModelli();
|
||||
timer.stop();
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " CACHE MODELS Recognizer by training " + String.valueOf(DBAdapter.getNow()) + " ...." + row.getCodice());
|
||||
}
|
||||
}
|
||||
timerTotal.stop();
|
||||
StatusMsg.updateMsgByTag(FaceRecognizer.this.getApFull(), " CACHE MODELS ", "FINE: " + timerTotal.getDurata());
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " CACHE MODELS FINE: " + String.valueOf(DBAdapter.getNow()));
|
||||
DBAdapter.sleepInSecond(4);
|
||||
StatusMsg.deleteMsgByTag(FaceRecognizer.this.getApFull(), " CACHE MODELS ");
|
||||
FaceRecognizer.threadCaricaModelli = false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean debug = false;
|
||||
|
||||
private static final long serialVersionUID = 1701089773600L;
|
||||
|
||||
private long id_users;
|
||||
|
||||
private Users users;
|
||||
|
||||
private org.opencv.face.FaceRecognizer ocvFrLBPH;
|
||||
|
||||
private org.opencv.face.FaceRecognizer ocvFrEigen;
|
||||
|
||||
private org.opencv.face.FaceRecognizer ocvFrFish;
|
||||
|
||||
public static boolean threadCaricaModelli = false;
|
||||
|
||||
private long nTrainingImagesMax;
|
||||
|
||||
private long flgTrainingMode;
|
||||
|
||||
private long flgDisabilita;
|
||||
|
||||
private static final ConcurrentHashMap<String, org.opencv.face.FaceRecognizer> recognizerCache = new ConcurrentHashMap<>();
|
||||
|
||||
private static final ReentrantLock trainingLock = new ReentrantLock();
|
||||
|
||||
public static final String TAG_TRAINING_RUN = "TRAINING_RUN";
|
||||
|
||||
public FaceRecognizer(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecognizer() {}
|
||||
|
||||
public static synchronized ResParm addNTrainingImages(FaceRecognizer bean, long newNTrainingImages) {
|
||||
bean.setNTrainingImages(bean.getNTrainingImages() + newNTrainingImages);
|
||||
return bean.save();
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FaceRecognizer> findByCR(FaceRecognizerCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = " order by A.descrizione";
|
||||
WcString wc = new WcString();
|
||||
if (CR.getId_faceRecognizer() > 0L)
|
||||
wc.addWc("A.id_faceRecognizer=" + CR.getId_faceRecognizer());
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void findByCode(String l_code) {
|
||||
String s_Sql_Find = "select A.* from FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.codice='" + l_code + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findByFaceRecognizer(long l_id_faceRecognizer) {
|
||||
String s_Sql_Find = "select A.* from FACE_FACE_RECOGNIZER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_faceRecognizer=" + l_id_faceRecognizer);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isModelFileExist(long recognizerType) {
|
||||
String fullFileName = getFullFileName(recognizerType);
|
||||
return new File(fullFileName).exists();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public org.opencv.face.FaceRecognizer getOcvFaceRecognizerWithLoadedModelOriginal(long recognizerType) {
|
||||
String fullFileName = getFullFileName(recognizerType);
|
||||
String cacheKey = "" + recognizerType + ":" + recognizerType;
|
||||
if (recognizerCache.containsKey(cacheKey))
|
||||
return recognizerCache.get(cacheKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
public org.opencv.face.FaceRecognizer getOcvFaceRecognizerWithLoadedModel(long recognizerType) {
|
||||
boolean debug = false;
|
||||
String fullFileName = getFullFileName(recognizerType);
|
||||
String cacheKey = "" + recognizerType + ":" + recognizerType;
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel key: " + cacheKey);
|
||||
if (debug) {
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel elenco chiavi presenti!!");
|
||||
for (String key : recognizerCache.keySet())
|
||||
System.out.println("Key: " + key);
|
||||
}
|
||||
if (recognizerCache.containsKey(cacheKey)) {
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel key: " + cacheKey + " TROVATO!!!!");
|
||||
return recognizerCache.get(cacheKey);
|
||||
}
|
||||
trainingLock.lock();
|
||||
try {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel key: " + cacheKey + " DENTRO IL LOCK!");
|
||||
if (recognizerCache.containsKey(cacheKey)) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel key: " + cacheKey + " TROVATO ALL'INTERNO DEL LOCK!!!!");
|
||||
return recognizerCache.get(cacheKey);
|
||||
}
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel prima di trainingAndCreateModel...");
|
||||
trainingAndCreateModel(false);
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel FATTO!!!");
|
||||
if (recognizerCache.containsKey(cacheKey)) {
|
||||
if (debug)
|
||||
System.out.println(
|
||||
String.valueOf(DBAdapter.getNowTs()) + " getOcvFaceRecognizerWithLoadedModel key: " + String.valueOf(DBAdapter.getNowTs()) + " TROVATO DOPO IL TRAINING");
|
||||
return recognizerCache.get(cacheKey);
|
||||
}
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel key: " + cacheKey + " NON TROVATO DOPO IL TRAINING!!!!");
|
||||
throw new IllegalStateException("Impossibile creare il modello per il tipo di recognizer: " + recognizerType);
|
||||
} finally {
|
||||
trainingLock.unlock();
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModel key: " + cacheKey + " FUORI IL LOCK!");
|
||||
}
|
||||
}
|
||||
|
||||
public org.opencv.face.FaceRecognizer getOcvFaceRecognizerWithLoadedModelByFile(long recognizerType) {
|
||||
boolean debug = true;
|
||||
String fullFileName = getFullFileName(recognizerType);
|
||||
String cacheKey = "" + recognizerType + ":" + recognizerType;
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile key: " + cacheKey);
|
||||
if (debug) {
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile elenco chiavi presenti!!");
|
||||
for (String key : recognizerCache.keySet())
|
||||
System.out.println("Key: " + key);
|
||||
}
|
||||
if (recognizerCache.containsKey(cacheKey)) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile key: " + cacheKey + " TROVATO!!!!");
|
||||
return recognizerCache.get(cacheKey);
|
||||
}
|
||||
if (!isModelFileExist(recognizerType)) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile key: " + cacheKey + " CACHE NON TROVATA E FILE MODELLO NON TROVATO! RITORNO NULL");
|
||||
return null;
|
||||
}
|
||||
trainingLock.lock();
|
||||
try {
|
||||
if (debug)
|
||||
System.out.println(
|
||||
String.valueOf(DBAdapter.getNowTs()) + " getOcvFaceRecognizerWithLoadedModelByFile key: " + String.valueOf(DBAdapter.getNowTs()) + " DENTRO IL LOCK!");
|
||||
if (recognizerCache.containsKey(cacheKey)) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile key: " + cacheKey + " TROVATO ALL'INTERNO DEL LOCK!!!!");
|
||||
return recognizerCache.get(cacheKey);
|
||||
}
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile prima di recognizer.read...");
|
||||
org.opencv.face.FaceRecognizer recognizer = getOcvFaceRecognizerForModel(recognizerType);
|
||||
try {
|
||||
recognizer.read(fullFileName);
|
||||
recognizerCache.put(cacheKey, recognizer);
|
||||
} catch (Exception e) {
|
||||
System.out.println(String.valueOf(DBAdapter.getNowTs()) + " getOcvFaceRecognizerWithLoadedModelByFile prima di recognizer.read ECCEZIONE! " + String.valueOf(DBAdapter.getNowTs()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile FATTO!!!");
|
||||
if (recognizerCache.containsKey(cacheKey)) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile key: " + cacheKey + " TROVATO DOPO IL TRAINING");
|
||||
return recognizerCache.get(cacheKey);
|
||||
}
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " getOcvFaceRecognizerWithLoadedModelByFile key: " + cacheKey + " NON TROVATO DOPO IL TRAINING!!!!");
|
||||
throw new IllegalStateException("Impossibile creare il modello per il tipo di recognizer: " + recognizerType);
|
||||
} finally {
|
||||
trainingLock.unlock();
|
||||
if (debug)
|
||||
System.out.println(
|
||||
String.valueOf(DBAdapter.getNowTs()) + " getOcvFaceRecognizerWithLoadedModelByFile key: " + String.valueOf(DBAdapter.getNowTs()) + " FUORI IL LOCK!");
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOcvFaceRecognizerWithLoadedModel(long recognizerType) {
|
||||
String fullFileName = getFullFileName(recognizerType);
|
||||
String cacheKey = "" + recognizerType + ":" + recognizerType;
|
||||
if (recognizerCache.containsKey(cacheKey))
|
||||
recognizerCache.remove(cacheKey);
|
||||
}
|
||||
|
||||
public void removeAllOcvFaceRecognizerWithLoadedModel() {
|
||||
synchronized (recognizerCache) {
|
||||
recognizerCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void addOcvFaceRecognizerWithLoadedModel(long recognizerType, org.opencv.face.FaceRecognizer recognizer) {
|
||||
String fullFileName = getFullFileName(recognizerType);
|
||||
String cacheKey = "" + recognizerType + ":" + recognizerType;
|
||||
if (recognizerCache.containsKey(cacheKey))
|
||||
recognizerCache.remove(cacheKey);
|
||||
DBAdapter.printDebug(this.debug, " addOcvFaceRecognizerWithLoadedModel key: " + cacheKey);
|
||||
recognizerCache.put(cacheKey, recognizer);
|
||||
}
|
||||
|
||||
public void precaricaModelliFiles() {
|
||||
for (int i = 0; i < 1; i++)
|
||||
getOcvFaceRecognizerWithLoadedModelByFile((long)i);
|
||||
}
|
||||
|
||||
public void precaricaModelli() {
|
||||
for (int i = 0; i < 1; i++)
|
||||
getOcvFaceRecognizerWithLoadedModel((long)i);
|
||||
}
|
||||
|
||||
private org.opencv.face.FaceRecognizer getOcvFaceRecognizerForModel(long recognizerType) {
|
||||
if (recognizerType == 0L)
|
||||
return (org.opencv.face.FaceRecognizer)LBPHFaceRecognizer.create();
|
||||
if (recognizerType == 2L)
|
||||
return (org.opencv.face.FaceRecognizer)EigenFaceRecognizer.create();
|
||||
if (recognizerType == 1L)
|
||||
return (org.opencv.face.FaceRecognizer)FisherFaceRecognizer.create();
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getId_users() {
|
||||
return this.id_users;
|
||||
}
|
||||
|
||||
public Users getUsers() {
|
||||
this.users = (Users)getSecondaryObject((DBAdapter)this.users, Users.class, getId_users());
|
||||
return this.users;
|
||||
}
|
||||
|
||||
public void setId_users(long newId_users) {
|
||||
this.id_users = newId_users;
|
||||
setUsers(null);
|
||||
}
|
||||
|
||||
public void setUsers(Users newUsers) {
|
||||
this.users = newUsers;
|
||||
}
|
||||
|
||||
public String getFullFileName(long l_tipo) {
|
||||
return getPathRecognizer() + getPathRecognizer() + "_" + getTipo(l_tipo);
|
||||
}
|
||||
|
||||
public String getFullFileNameBin(long l_tipo) {
|
||||
return getPathRecognizer() + getPathRecognizer() + "_" + getTipo(l_tipo) + ".dat";
|
||||
}
|
||||
|
||||
public String getPathRecognizer() {
|
||||
return getParm("path_img_base").getTesto() + "_recognizer/";
|
||||
}
|
||||
|
||||
public ResParm trainingAndCreateModel(boolean saveModel) {
|
||||
ResParm rp = new ResParm();
|
||||
String TAG_THREAD_MSG = "TRAINING_RUN";
|
||||
Timer timer = new Timer();
|
||||
timer.start();
|
||||
try {
|
||||
boolean debug = true;
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNowTs()) + " TRAINING_RUN trainingAndCreateModel FaceRecognition.getInstance ");
|
||||
FaceRecognition.getInstance(getApFull());
|
||||
if (getId_faceRecognizer() == 0L) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " TRAINING_RUN trainingAndCreateModel NO getId_faceRecognizer ");
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore! FaceRecognizer nullo !!");
|
||||
} else {
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "START TRAINING FOR: " + getCodice());
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " TRAINING_RUN START TRAINING FOR: " + getCodice());
|
||||
int NUM_IMMAGINI_MAX = (int)getNTrainingImagesMax();
|
||||
int totFotoElaborate = 0;
|
||||
FaceFaceRecognizer faceFR = new FaceFaceRecognizer(getApFull());
|
||||
long totRecord = faceFR.getTotFaceByFaceRecognizer(getId_faceRecognizer());
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " TRAINING_RUN totrecordfacebyfacerec: " + totRecord);
|
||||
int j = 0;
|
||||
List<TrainingImage> imageFilenames = new ArrayList<>();
|
||||
Vectumerator<FaceFaceRecognizer> vec = faceFR.findByFaceRecognizer(getId_faceRecognizer(), 1, NUM_IMMAGINI_MAX);
|
||||
while (vec.hasMoreElements()) {
|
||||
j++;
|
||||
FaceFaceRecognizer row = (FaceFaceRecognizer)vec.nextElement();
|
||||
imageFilenames.add(new TrainingImage(row.getFace().getFullFileName(), (int)row.getId_faceLabel()));
|
||||
if (j % 10 == 0)
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "(MAX: " + NUM_IMMAGINI_MAX + ") Preparing images for model: " + j + "/" + totRecord);
|
||||
}
|
||||
totFotoElaborate = j;
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "Training create for " + totFotoElaborate + "/" + totRecord + " ... FR CODE: " +
|
||||
getCodice() + " .... ");
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " TRAINING_RUN trainingCreate --> trainingcreate");
|
||||
rp = trainingCreate(imageFilenames, totFotoElaborate);
|
||||
File path = new File(getPathRecognizer());
|
||||
if (!path.exists())
|
||||
path.mkdirs();
|
||||
for (int i = 0; i < 1; i++) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " TRAINING_RUN trainingAndCreateModel salvo modello: " +
|
||||
getFullFileName((long)i));
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "Saving " + getFullFileName((long)i) + " " + totFotoElaborate + "/" + totRecord + " ... FR CODE: " +
|
||||
getCodice() + " .... ");
|
||||
if (saveModel) {
|
||||
getOcvFaceRecognizer((long)i).save(getFullFileName((long)i));
|
||||
} else {
|
||||
File theFile = new File(getFullFileName((long)i));
|
||||
if (theFile.exists())
|
||||
theFile.delete();
|
||||
}
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " TRAINING_RUN trainingAndCreateModel metto in CACHE....: " +
|
||||
getFullFileName((long)i));
|
||||
addOcvFaceRecognizerWithLoadedModel((long)i, getOcvFaceRecognizer((long)i));
|
||||
}
|
||||
timer.stop();
|
||||
setTsStart(timer.getTStart());
|
||||
setTsStop(timer.getTStop());
|
||||
setNTrainingImages((long)totFotoElaborate);
|
||||
rp.append(save());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
rp.setStatus(false);
|
||||
rp.setException(e);
|
||||
if (this.debug)
|
||||
DBAdapter.printDebug(this.debug, " TRAINING_RUN trainingAndCreateModel ECCEZIONE!!!! " + e.getMessage());
|
||||
}
|
||||
if (this.debug)
|
||||
System.out.println(
|
||||
String.valueOf(DBAdapter.getNowTs()) + " TRAINING_RUN FINITO MODELLO " + String.valueOf(DBAdapter.getNowTs()) + " DURATA: " + getCodice());
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "FINITO MODELLO " + getCodice() + " DURATA: " + timer.getDurata());
|
||||
DBAdapter.sleepInSecond(5);
|
||||
StatusMsg.deleteMsgByTag(getApFull(), "TRAINING_RUN");
|
||||
return rp;
|
||||
}
|
||||
|
||||
private ResParm trainingCreate(List<TrainingImage> trainingImages, int counter) {
|
||||
ResParm rp = new ResParm();
|
||||
try {
|
||||
boolean debug = true;
|
||||
int j = 0;
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + "trainingCreate " + String.valueOf(DBAdapter.getNow()) + " immagini. counterStart: " + trainingImages.size());
|
||||
if (trainingImages.size() > 0) {
|
||||
Mat labels = new Mat(trainingImages.size(), 1, CvType.CV_32SC1);
|
||||
MatOfInt labelsMat = new MatOfInt();
|
||||
List<Mat> trainingImagesMat = new ArrayList<>();
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + "train: ciclo trainingImages. size: " + String.valueOf(DBAdapter.getNow()));
|
||||
for (TrainingImage trainingImage : trainingImages) {
|
||||
File imageFile = new File(trainingImage.getImageFileName());
|
||||
Mat image = Imgcodecs.imread(imageFile.getAbsolutePath());
|
||||
Mat grayImage = new Mat();
|
||||
Imgproc.cvtColor(image, grayImage, 6);
|
||||
trainingImagesMat.add(grayImage);
|
||||
labels.put(j, 0, new double[] { (double)trainingImage.getLabel() });
|
||||
j++;
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " train: " + String.valueOf(DBAdapter.getNow()) + " count...:" + trainingImage.getImageFileName() + "/" + j + " label: " + counter);
|
||||
}
|
||||
labels.convertTo((Mat)labelsMat, CvType.CV_32SC1);
|
||||
for (int i = 0; i < 1; i++) {
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " addestramento per modello n.: " + String.valueOf(DBAdapter.getNow()) + " ...");
|
||||
getOcvFaceRecognizer((long)i).train(trainingImagesMat, labels);
|
||||
if (debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " addestramento per modello n.: " + String.valueOf(DBAdapter.getNow()) + " FATTO!");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
rp.setStatus(false);
|
||||
rp.setException(e);
|
||||
if (this.debug)
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " trainingCreate ECCEZIONE!!!! " + String.valueOf(DBAdapter.getNow()));
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public ResParm resetTraining() {
|
||||
FaceFaceRecognizer ffr = new FaceFaceRecognizer(getApFull());
|
||||
return ffr.resetTrainingByFaceRecognizer(getId_faceRecognizer());
|
||||
}
|
||||
|
||||
private org.opencv.face.FaceRecognizer getOcvFaceRecognizer(long l_type) {
|
||||
if (l_type == 0L) {
|
||||
if (this.ocvFrLBPH == null)
|
||||
this.ocvFrLBPH = (org.opencv.face.FaceRecognizer)LBPHFaceRecognizer.create();
|
||||
return this.ocvFrLBPH;
|
||||
}
|
||||
if (l_type == 2L) {
|
||||
if (this.ocvFrEigen == null)
|
||||
this.ocvFrEigen = (org.opencv.face.FaceRecognizer)EigenFaceRecognizer.create();
|
||||
return this.ocvFrEigen;
|
||||
}
|
||||
if (l_type == 1L) {
|
||||
if (this.ocvFrFish == null)
|
||||
this.ocvFrFish = (org.opencv.face.FaceRecognizer)FisherFaceRecognizer.create();
|
||||
return this.ocvFrFish;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final ResParm startCaricaModelli(FaceRecognizerCR l_CR, boolean useFile) {
|
||||
if (!threadCaricaModelli) {
|
||||
new ThreadCaricaModelli(l_CR, useFile);
|
||||
return new ResParm(true, "Thread threadCaricaModelli avviato. usefile: " + useFile);
|
||||
}
|
||||
return new ResParm(false, "ATTENZIONE!! Thread in esecuzione!!!");
|
||||
}
|
||||
|
||||
public long getNTrainingImagesMax() {
|
||||
return (this.nTrainingImagesMax <= 0L) ? 10000L : this.nTrainingImagesMax;
|
||||
}
|
||||
|
||||
public void setNTrainingImagesMax(long nTrainingImagesMax) {
|
||||
this.nTrainingImagesMax = nTrainingImagesMax;
|
||||
}
|
||||
|
||||
public long getFlgTrainingMode() {
|
||||
return this.flgTrainingMode;
|
||||
}
|
||||
|
||||
public void setFlgTrainingMode(long flgTrainingMode) {
|
||||
this.flgTrainingMode = flgTrainingMode;
|
||||
}
|
||||
|
||||
public long getFlgDisabilita() {
|
||||
return this.flgDisabilita;
|
||||
}
|
||||
|
||||
public void setFlgDisabilita(long flgDisabilita) {
|
||||
this.flgDisabilita = flgDisabilita;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import java.sql.Date;
|
||||
|
||||
public class FaceRecognizerCR extends CRAdapter {
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private String flgTIpo;
|
||||
|
||||
private String codice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private String sessionId;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private long nTrainingImages;
|
||||
|
||||
private Date dataTraining;
|
||||
|
||||
private long id_users;
|
||||
|
||||
private Users users;
|
||||
|
||||
public FaceRecognizerCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FaceRecognizerCR() {}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
}
|
||||
|
||||
public void setFlgTIpo(String newFlgTIpo) {
|
||||
this.flgTIpo = newFlgTIpo;
|
||||
}
|
||||
|
||||
public void setCodice(String newCodice) {
|
||||
this.codice = newCodice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setSessionId(String newSessionId) {
|
||||
this.sessionId = newSessionId;
|
||||
}
|
||||
|
||||
public void setFileName(String newFileName) {
|
||||
this.fileName = newFileName;
|
||||
}
|
||||
|
||||
public void setNTrainingImages(long newNTrainingImages) {
|
||||
this.nTrainingImages = newNTrainingImages;
|
||||
}
|
||||
|
||||
public void setDataTraining(Date newDataTraining) {
|
||||
this.dataTraining = newDataTraining;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public String getFlgTIpo() {
|
||||
return (this.flgTIpo == null) ? "" : this.flgTIpo.trim();
|
||||
}
|
||||
|
||||
public String getCodice() {
|
||||
return (this.codice == null) ? "" : this.codice.trim();
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return (this.sessionId == null) ? "" : this.sessionId.trim();
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return (this.fileName == null) ? "" : this.fileName.trim();
|
||||
}
|
||||
|
||||
public long getNTrainingImages() {
|
||||
return this.nTrainingImages;
|
||||
}
|
||||
|
||||
public Date getDataTraining() {
|
||||
return this.dataTraining;
|
||||
}
|
||||
|
||||
public long getId_users() {
|
||||
return this.id_users;
|
||||
}
|
||||
|
||||
public Users getUsers() {
|
||||
this.users = (Users)getSecondaryObject((DBAdapter)this.users, Users.class, getId_users());
|
||||
return this.users;
|
||||
}
|
||||
|
||||
public void setId_users(long newId_users) {
|
||||
this.id_users = newId_users;
|
||||
setUsers(null);
|
||||
}
|
||||
|
||||
public void setUsers(Users newUsers) {
|
||||
this.users = newUsers;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Facer extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1730299088138L;
|
||||
|
||||
private long id_facer;
|
||||
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private String md5;
|
||||
|
||||
private long label;
|
||||
|
||||
private String fileAlternativo;
|
||||
|
||||
private double confidence;
|
||||
|
||||
private FaceRecognizer faceRecognizer;
|
||||
|
||||
public static final String PATH_IMG_FACE_RECOGNITION = "_faceRecognition/";
|
||||
|
||||
public Facer(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public Facer() {}
|
||||
|
||||
public void setId_facer(long newId_facer) {
|
||||
this.id_facer = newId_facer;
|
||||
}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
setFaceRecognizer(null);
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public void setLabel(long newLabel) {
|
||||
this.label = newLabel;
|
||||
}
|
||||
|
||||
public long getId_facer() {
|
||||
return this.id_facer;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setFaceRecognizer(FaceRecognizer newFaceRecognizer) {
|
||||
this.faceRecognizer = newFaceRecognizer;
|
||||
}
|
||||
|
||||
public FaceRecognizer getFaceRecognizer() {
|
||||
this.faceRecognizer = (FaceRecognizer)getSecondaryObject(this.faceRecognizer, FaceRecognizer.class, getId_faceRecognizer());
|
||||
return this.faceRecognizer;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<Facer> findByCR(FacerCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FACER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (CR.getLabel() > 0L)
|
||||
wc.addWc("A.label =" + CR.getLabel());
|
||||
if (!CR.getMd5().isEmpty())
|
||||
wc.addWc("A.md5 ='" + CR.getMd5() + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public String getFullFileName() {
|
||||
return getPathFaceImg() + getPathFaceImg() + ".jpg";
|
||||
}
|
||||
|
||||
public void findByMd5Recognizer(String l_md5, long l_id_faceRecognizer) {
|
||||
String s_Sql_Find = "select A.* from FACER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.md5='" + l_md5 + "'");
|
||||
wc.addWc("A.id_faceRecognizer=" + l_id_faceRecognizer);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findByLabel(long l_label) {
|
||||
String s_Sql_Find = "select A.* from FACER AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.label=" + l_label);
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPathFaceImg() {
|
||||
return getParm("path_img_base").getTesto() + "_faceRecognition/" + getParm("path_img_base").getTesto();
|
||||
}
|
||||
|
||||
public String getFileAlternativo() {
|
||||
return (this.fileAlternativo == null) ? "" : this.fileAlternativo.trim();
|
||||
}
|
||||
|
||||
public void setFileAlternativo(String fileAlternativo) {
|
||||
this.fileAlternativo = fileAlternativo;
|
||||
}
|
||||
|
||||
public double getConfidence() {
|
||||
return this.confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(double confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
|
||||
public class FacerCR extends CRAdapter {
|
||||
private long id_facer;
|
||||
|
||||
private long id_faceRecognizer;
|
||||
|
||||
private String md5;
|
||||
|
||||
private long label;
|
||||
|
||||
private FaceRecognizer faceRecognizer;
|
||||
|
||||
public FacerCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FacerCR() {}
|
||||
|
||||
public void setId_facer(long newId_facer) {
|
||||
this.id_facer = newId_facer;
|
||||
}
|
||||
|
||||
public void setId_faceRecognizer(long newId_faceRecognizer) {
|
||||
this.id_faceRecognizer = newId_faceRecognizer;
|
||||
setFaceRecognizer(null);
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public void setLabel(long newLabel) {
|
||||
this.label = newLabel;
|
||||
}
|
||||
|
||||
public long getId_facer() {
|
||||
return this.id_facer;
|
||||
}
|
||||
|
||||
public long getId_faceRecognizer() {
|
||||
return this.id_faceRecognizer;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
public long getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setFaceRecognizer(FaceRecognizer newFaceRecognizer) {
|
||||
this.faceRecognizer = newFaceRecognizer;
|
||||
}
|
||||
|
||||
public FaceRecognizer getFaceRecognizer() {
|
||||
this.faceRecognizer = (FaceRecognizer)getSecondaryObject(this.faceRecognizer, FaceRecognizer.class,
|
||||
|
||||
getId_faceRecognizer());
|
||||
return this.faceRecognizer;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
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.util.Vectumerator;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class FotoRequest extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1700680369881L;
|
||||
|
||||
public static final long REQUEST_TYPE_DETECT_ERROR = -1L;
|
||||
|
||||
public static final long REQUEST_TYPE_DETECT_ALL = 0L;
|
||||
|
||||
public static final long REQUEST_TYPE_DETECT_FACE = 1L;
|
||||
|
||||
public static final long REQUEST_TYPE_DETECT_NUMBERS = 3L;
|
||||
|
||||
private long id_fotoRequest;
|
||||
|
||||
private long id_users;
|
||||
|
||||
private String md5;
|
||||
|
||||
private String json;
|
||||
|
||||
private long nRichieste;
|
||||
|
||||
private FaceDetectionMethod faceDetectionMethod;
|
||||
|
||||
private Users users;
|
||||
|
||||
private long faceDetectionMethodCode;
|
||||
|
||||
private long flgRequestType;
|
||||
|
||||
public FotoRequest(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FotoRequest() {}
|
||||
|
||||
public static final String getRequestType(long l_flgRequestType) {
|
||||
if (l_flgRequestType == 0L)
|
||||
return "Completa";
|
||||
if (l_flgRequestType == 1L)
|
||||
return "Completa";
|
||||
if (l_flgRequestType == 3L)
|
||||
return "Completa";
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setId_fotoRequest(long newId_fotoRequest) {
|
||||
this.id_fotoRequest = newId_fotoRequest;
|
||||
}
|
||||
|
||||
public void setId_users(long newId_users) {
|
||||
this.id_users = newId_users;
|
||||
setUsers(null);
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public void setJson(String newJsonCompleto) {
|
||||
this.json = newJsonCompleto;
|
||||
}
|
||||
|
||||
public void setNRichieste(long newNRichieste) {
|
||||
this.nRichieste = newNRichieste;
|
||||
}
|
||||
|
||||
public long getId_fotoRequest() {
|
||||
return this.id_fotoRequest;
|
||||
}
|
||||
|
||||
public long getId_users() {
|
||||
return this.id_users;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
public String getJson() {
|
||||
if (hasDetectFacesResponseFaces(this.json))
|
||||
return this.json.trim();
|
||||
return "";
|
||||
}
|
||||
|
||||
public long getNRichieste() {
|
||||
return this.nRichieste;
|
||||
}
|
||||
|
||||
public void setUsers(Users newUsers) {
|
||||
this.users = newUsers;
|
||||
}
|
||||
|
||||
public Users getUsers() {
|
||||
this.users = (Users)getSecondaryObject((DBAdapter)this.users, Users.class, getId_users());
|
||||
return this.users;
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<FotoRequest> findByCR(FotoRequestCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from FOTO_REQUEST AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (CR.getId_users() > 0L)
|
||||
wc.addWc("A.id_users=" + CR.getId_users());
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<FotoRequest> findByUsers(long l_id_users, int pageNumber, int pageRows) {
|
||||
FotoRequestCR CR = new FotoRequestCR();
|
||||
CR.setId_users(l_id_users);
|
||||
return findByCR(CR, pageNumber, pageRows);
|
||||
}
|
||||
|
||||
public void findByUserMd5DetectionmethodRequesttype(long l_id_user, String l_md5, long l_flgFaceDetectionMethod, long l_flgRequestType) {
|
||||
String s_Sql_Find = "select A.* from FOTO_REQUEST AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.id_users=" + l_id_user);
|
||||
wc.addWc("A.md5='" + l_md5 + "'");
|
||||
if (l_flgRequestType == 0L) {
|
||||
wc.addWc("(A.flgRequestType is null || A.flgRequestType=0) ");
|
||||
} else {
|
||||
wc.addWc("A.flgRequestType=" + l_flgRequestType);
|
||||
}
|
||||
if (l_flgFaceDetectionMethod == 0L) {
|
||||
wc.addWc("(A.faceDetectionMethodCode is null || A.faceDetectionMethodCode=0) ");
|
||||
} else {
|
||||
wc.addWc("A.faceDetectionMethodCode=" + l_flgFaceDetectionMethod);
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasDetectFacesResponseFaces(String jsonString) {
|
||||
if (jsonString == null || jsonString.isEmpty())
|
||||
return false;
|
||||
try {
|
||||
JsonElement parsed = JsonParser.parseString(jsonString);
|
||||
if (!parsed.isJsonObject())
|
||||
return false;
|
||||
JsonObject json = parsed.getAsJsonObject();
|
||||
if (json.has("responses")) {
|
||||
JsonArray responses = json.getAsJsonArray("responses");
|
||||
if (responses.size() > 0) {
|
||||
JsonObject response = responses.get(0).getAsJsonObject().getAsJsonObject("response");
|
||||
JsonArray annotations = response.getAsJsonArray("faceAnnotations");
|
||||
return (annotations != null && annotations.size() > 0);
|
||||
}
|
||||
}
|
||||
} catch (JsonSyntaxException e) {
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setJson(long l_flgRequestType, String l_json) {
|
||||
setFlgRequestType(l_flgRequestType);
|
||||
setJson(l_json);
|
||||
}
|
||||
|
||||
public void addRichiesta() {
|
||||
setNRichieste(getNRichieste() + 1L);
|
||||
}
|
||||
|
||||
public final FaceDetectionMethod getFaceDetectionMethod() {
|
||||
if (this.faceDetectionMethod == null && getFaceDetectionMethodCode() >= 0L) {
|
||||
this.faceDetectionMethod = new FaceDetectionMethod(getApFull());
|
||||
this.faceDetectionMethod.findByCodice(getFaceDetectionMethodCode());
|
||||
}
|
||||
return (this.faceDetectionMethod == null) ? new FaceDetectionMethod(getApFull()) : this.faceDetectionMethod;
|
||||
}
|
||||
|
||||
public long getFaceDetectionMethodCode() {
|
||||
return this.faceDetectionMethodCode;
|
||||
}
|
||||
|
||||
public void setFaceDetectionMethodCode(long flgFaceDetectionMethod) {
|
||||
this.faceDetectionMethodCode = flgFaceDetectionMethod;
|
||||
}
|
||||
|
||||
public long getFlgRequestType() {
|
||||
return this.flgRequestType;
|
||||
}
|
||||
|
||||
public void setFlgRequestType(long flgRequestType) {
|
||||
this.flgRequestType = flgRequestType;
|
||||
}
|
||||
|
||||
public void setFaceDetectionMethod(FaceDetectionMethod faceDetectionMethod) {
|
||||
this.faceDetectionMethod = faceDetectionMethod;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
|
||||
public class FotoRequestCR extends CRAdapter {
|
||||
private long id_fotoRequest;
|
||||
|
||||
private long id_users;
|
||||
|
||||
private String md5;
|
||||
|
||||
private String jsonCompleto;
|
||||
|
||||
private String jsonNumeri;
|
||||
|
||||
private String jsonFace;
|
||||
|
||||
private long nRichieste;
|
||||
|
||||
private Users users;
|
||||
|
||||
public FotoRequestCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public FotoRequestCR() {}
|
||||
|
||||
public void setId_fotoRequest(long newId_fotoRequest) {
|
||||
this.id_fotoRequest = newId_fotoRequest;
|
||||
}
|
||||
|
||||
public void setId_users(long newId_users) {
|
||||
this.id_users = newId_users;
|
||||
setUsers(null);
|
||||
}
|
||||
|
||||
public void setMd5(String newMd5) {
|
||||
this.md5 = newMd5;
|
||||
}
|
||||
|
||||
public void setJsonCompleto(String newJsonCompleto) {
|
||||
this.jsonCompleto = newJsonCompleto;
|
||||
}
|
||||
|
||||
public void setJsonNumeri(String newJsonNumeri) {
|
||||
this.jsonNumeri = newJsonNumeri;
|
||||
}
|
||||
|
||||
public void setJsonFace(String newJsonFace) {
|
||||
this.jsonFace = newJsonFace;
|
||||
}
|
||||
|
||||
public void setNRichieste(long newNRichieste) {
|
||||
this.nRichieste = newNRichieste;
|
||||
}
|
||||
|
||||
public long getId_fotoRequest() {
|
||||
return this.id_fotoRequest;
|
||||
}
|
||||
|
||||
public long getId_users() {
|
||||
return this.id_users;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return (this.md5 == null) ? "" : this.md5.trim();
|
||||
}
|
||||
|
||||
public String getJsonCompleto() {
|
||||
return (this.jsonCompleto == null) ? "" : this.jsonCompleto.trim();
|
||||
}
|
||||
|
||||
public String getJsonNumeri() {
|
||||
return (this.jsonNumeri == null) ? "" : this.jsonNumeri.trim();
|
||||
}
|
||||
|
||||
public String getJsonFace() {
|
||||
return (this.jsonFace == null) ? "" : this.jsonFace.trim();
|
||||
}
|
||||
|
||||
public long getNRichieste() {
|
||||
return this.nRichieste;
|
||||
}
|
||||
|
||||
public void setUsers(Users newUsers) {
|
||||
this.users = newUsers;
|
||||
}
|
||||
|
||||
public Users getUsers() {
|
||||
this.users = (Users)getSecondaryObject((DBAdapter)this.users, Users.class,
|
||||
|
||||
getId_users());
|
||||
return this.users;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.util.DbConsole;
|
||||
import java.sql.Time;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class Test extends DbConsole {
|
||||
public static void main(String[] args) {
|
||||
Test bean = new Test();
|
||||
bean.doImport();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void doImport() {
|
||||
String db = "fr";
|
||||
int i = 0;
|
||||
int se1 = 10;
|
||||
int se2 = 100;
|
||||
String hostname = "localhost:3308";
|
||||
String temp = getCi().readLine("Hostname (" + hostname + "):");
|
||||
if (!temp.isEmpty())
|
||||
hostname = temp;
|
||||
temp = getCi().readLine("Database name (" + db + "):");
|
||||
if (!temp.isEmpty())
|
||||
db = temp;
|
||||
System.out.println("Db: " + db);
|
||||
ApplParmFull apTarget = new ApplParmFull(new ApplParm(3, "//" + hostname + "/" + db, "root", "root", 1, 10, 300));
|
||||
apTarget.setDebug(false);
|
||||
StringBuffer msg = new StringBuffer();
|
||||
try {
|
||||
FotoRequest bean = new FotoRequest(apTarget);
|
||||
bean.findByPrimaryKey(28402L);
|
||||
String json = bean.getJson();
|
||||
System.out.println(json.length());
|
||||
System.out.println(json);
|
||||
String jc = DBAdapter.compressText(json);
|
||||
System.out.println(jc.length());
|
||||
String ja = DBAdapter.decompressText(jc);
|
||||
System.out.println(ja.length());
|
||||
System.out.println(ja);
|
||||
bean.save();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected Time getTimeFromString(String theTime) {
|
||||
try {
|
||||
if (theTime.matches("[0-9][0-9][0-9][0-9]"))
|
||||
theTime = theTime.substring(0, 2) + ":" + theTime.substring(0, 2);
|
||||
if (theTime.matches("[0-9]{1,2}+:[0-9]{1,2}+")) {
|
||||
StringTokenizer st = new StringTokenizer(theTime, ":");
|
||||
int hour = Integer.parseInt(st.nextToken());
|
||||
int min = Integer.parseInt(st.nextToken());
|
||||
int sec = st.hasMoreElements() ? Integer.parseInt(st.nextToken()) : 0;
|
||||
return new Time((long)((hour - 1) * 3600000 + min * 60000 + sec * 1000));
|
||||
}
|
||||
if (theTime.matches("[0-9]{1,2}+:[0-9]{1,2}+:[0-9]{1,2}+")) {
|
||||
StringTokenizer st = new StringTokenizer(theTime, ":");
|
||||
int hour = Integer.parseInt(st.nextToken());
|
||||
int min = Integer.parseInt(st.nextToken());
|
||||
int sec = st.hasMoreElements() ? Integer.parseInt(st.nextToken()) : 0;
|
||||
return new Time((long)((hour - 1) * 3600000 + min * 60000 + sec * 1000));
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.common.Parm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.face.api.vision.GoogleVisionApi;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class Users extends it.acxent.anag.Users {
|
||||
public Users() {}
|
||||
|
||||
public Users(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public void initApplicationParms(ApplParmFull ap) {
|
||||
if (ap != null) {
|
||||
super.initApplicationParms(ap);
|
||||
String l_tipoParm = "";
|
||||
Parm bean = new Parm(ap);
|
||||
l_tipoParm = "FACE-FR";
|
||||
bean.findByCodice("path_opencv_lib");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("path_opencv_lib");
|
||||
bean.setDescrizione("path_opencv_lib");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/usr/local/Cellar/opencv/4.8.1_1/share/java/opencv4/libopencv_java481.dylib");
|
||||
bean.setNota("PERCORSO LIBRERIA NATIVA OPENCV<BR>MAC: /usr/local/Cellar/opencv/4.8.1_1/share/java/opencv4/libopencv_java481.dylib<br>ubuntu: /home/ocv/build/lib/libopencv_java480.so");
|
||||
bean.save();
|
||||
bean.findByCodice("path_img_base");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("path_img_base");
|
||||
bean.setDescrizione("path_img_base");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_ocv/img/");
|
||||
bean.setNota("PERCORSO MEMORIZZAZIONI IMMAGINI CHE ARRIVANO<br>/Users/acolzi/Downloads/_ocv/img/");
|
||||
bean.save();
|
||||
File dirFace = new File(bean.getTesto() + "_face/");
|
||||
if (!dirFace.exists())
|
||||
dirFace.mkdirs();
|
||||
File dirFaceRecognition = new File(bean.getTesto() + "_faceRecognition/");
|
||||
if (!dirFaceRecognition.exists())
|
||||
dirFaceRecognition.mkdirs();
|
||||
bean.findByCodice("path_img_tmp");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("path_img_tmp");
|
||||
bean.setDescrizione("path_img_tmp");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_ocv/_tmp/");
|
||||
bean.setNota("PERCORSO MEMORIZZAZIONI TEMPORANEO IMMAGINI<br>/Users/acolzi/Downloads/_ocv/_tmp/ /mnt/foto/_ocv/_tmp/");
|
||||
bean.save();
|
||||
File dirTmp = new File(bean.getTesto());
|
||||
if (!dirTmp.exists())
|
||||
dirTmp.mkdirs();
|
||||
bean.findByCodice("PATH_FACE_TRAINING_MODELS");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PATH_FACE_TRAINING_MODELS");
|
||||
bean.setDescrizione("PATH_FACE_TRAINING_MODELS");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_ocv/models/training/");
|
||||
bean.setNota("PERCORSO DOVE MEMORIZZO I TRAINIG MODELS<br>/Users/acolzi/Downloads/_ocv/models/training/");
|
||||
bean.save();
|
||||
File dirTM = new File(bean.getTesto());
|
||||
if (!dirTM.exists())
|
||||
dirTM.mkdirs();
|
||||
bean.findByCodice("NUMBER_BOX_DECT_CONFIG");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUMBER_BOX_DECT_CONFIG");
|
||||
bean.setDescrizione("NUMBER_BOX_DECT_CONFIG");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_ocv/models/detection.cfg");
|
||||
bean.setNota("DETECTION CONFIG PER BOX PETTORALI<br>/Users/acolzi/Downloads/_ocv/models/detection.cfg");
|
||||
bean.save();
|
||||
bean.findByCodice("NUMBER_BOX_DECT_MODEL");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUMBER_BOX_DECT_MODEL");
|
||||
bean.setDescrizione("NUMBER_BOX_DECT_MODEL");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_ocv/models/detection.weights");
|
||||
bean.setNota("DETECTION MODEL PER BOX PETTORALI<br>/Users/acolzi/Downloads/_ocv/models/detection.weights");
|
||||
bean.save();
|
||||
bean.findByCodice("NUMBER_RECOG_CONFIG");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUMBER_RECOG_CONFIG");
|
||||
bean.setDescrizione("NUMBER_RECOG_CONFIG");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_ocv/models/recognition.cfg");
|
||||
bean.setNota("RECOGNITION CONFIG PER IMMAGINE CON SOLO NUMERI<br>/Users/acolzi/Downloads/_ocv/models/recognition.cfg");
|
||||
bean.save();
|
||||
bean.findByCodice("NUMBER_RECOG_MODEL");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("NUMBER_RECOG_MODEL");
|
||||
bean.setDescrizione("NUMBER_RECOG_MODEL");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/_ocv/models/recognition.weights");
|
||||
bean.setNota("RECOGNITION MODEL PER IMMAGINE CON SOLO NUMERI<br>/Users/acolzi/Downloads/_ocv/models/recognition.weights");
|
||||
bean.save();
|
||||
GoogleVisionApi.initApplicationParms(ap);
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<Users> findByCR(UsersCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from USERS AS A";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("dataFineVld is null");
|
||||
wc = managePolicyFind(CR, wc);
|
||||
if (!CR.isCode1())
|
||||
wc.addWc("A.id_users <>1");
|
||||
if (!CR.getFlgValido().isEmpty())
|
||||
wc.addWc("A.flgValido='" + CR.getFlgValido() + "'");
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
String temp = CR.getSearchTxt().trim().replace("*", "%");
|
||||
StringTokenizer st = new StringTokenizer(temp, " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
int countToken = 0;
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = prepareSqlString(st.nextToken());
|
||||
countToken++;
|
||||
if (countToken > 1)
|
||||
token = "%" + token;
|
||||
txt.append("(A.nome like'%" + token + "%' or A.cognome like'%" + token + "%' or A.eMail like'%" + token + "%' or A.codFisc like'%" + token + "%' or A.login like'%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
if (!CR.getEMail().isEmpty())
|
||||
wc.addWc("A.eMail like'%" + CR.getEMail() + "%'");
|
||||
if (CR.getFlgMl() == 0L) {
|
||||
wc.addWc("(A.flgMl is null or A.flgMl=0)");
|
||||
} else if (CR.getFlgMl() > 0L) {
|
||||
wc.addWc("A.flgMl =" + CR.getFlgMl());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (Exception e) {
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package it.acxent.face.fr;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
|
||||
public class UsersCR extends it.acxent.common.UsersCR {
|
||||
public boolean isCode1() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public UsersCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public UsersCR() {}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.fr;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package it.acxent.face.fr.rest;
|
||||
|
||||
public class FaceRestResult {
|
||||
private String msg;
|
||||
|
||||
public FaceRestResult(String msg, boolean status, Object result) {
|
||||
this.msg = msg;
|
||||
this.ok = status;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
private boolean ok = true;
|
||||
|
||||
private Object result;
|
||||
|
||||
public FaceRestResult() {}
|
||||
|
||||
public String getMsg() {
|
||||
return (this.msg == null) ? "" : this.msg.trim();
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public boolean isOk() {
|
||||
return this.ok;
|
||||
}
|
||||
|
||||
public void setOk(boolean status) {
|
||||
this.ok = status;
|
||||
}
|
||||
|
||||
public Object getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public void setResult(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,891 @@
|
|||
package it.acxent.face.fr.rest;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.dm.FaceDetectionMethod;
|
||||
import it.acxent.dm.FaceDetectionMethodCR;
|
||||
import it.acxent.face.api.opencv.FaceRecognition;
|
||||
import it.acxent.face.api.opencv.TrainingImage;
|
||||
import it.acxent.face.fr.Face;
|
||||
import it.acxent.face.fr.FaceFaceRecognizer;
|
||||
import it.acxent.face.fr.FaceRecognizer;
|
||||
import it.acxent.face.fr.Facer;
|
||||
import it.acxent.face.fr.FotoRequest;
|
||||
import it.acxent.face.fr.Users;
|
||||
import it.acxent.rest._AblRestAdapter;
|
||||
import it.acxent.util.Debug;
|
||||
import it.acxent.util.Timer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
@WebServlet(urlPatterns = {"/face/*"})
|
||||
public class FaceRestSvlt extends _AblRestAdapter {
|
||||
private static Debug debugHelper = new Debug();
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
private Cache<String, Object> cache;
|
||||
|
||||
private static final long serialVersionUID = -8266400675249237394L;
|
||||
|
||||
public void __templateChiamata(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
boolean debug = false;
|
||||
String parametroTest = getRequestParameter(req, "id");
|
||||
if (debug)
|
||||
System.out.println(" parm id: " + parametroTest + " apiParms: " +
|
||||
getApiParms() + " json post: " + getApiJSONObject().toString(4));
|
||||
try {
|
||||
long l_id_user = getRequestLongParameter(req, "id_user");
|
||||
boolean authOk = checkBasicAuth(req, res);
|
||||
if (!authOk)
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello, _elencofoto");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello,_elencofoto eccezione: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void _detectFacesAndNumbers_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
boolean debug = true;
|
||||
if (debug) {
|
||||
System.out.println("************ _detectFacesAndNumbers_POST req res *********************");
|
||||
System.out.println(req.toString());
|
||||
System.out.println("************");
|
||||
System.out.println(res.toString());
|
||||
System.out.println("************");
|
||||
}
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 1");
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
HashSet<File> hsFiles = new HashSet<>();
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 2");
|
||||
Users user = getUsersByBasicAuth(req, res);
|
||||
StringBuilder err = new StringBuilder();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
try {
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 3");
|
||||
JSONObject jo = getApiJSONObject();
|
||||
if (debug) {
|
||||
System.out.println("************ _detectFacesAndNumbers_POST *********************");
|
||||
System.out.println("json in arrivo");
|
||||
System.out.println(jo.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
}
|
||||
String pathBase = getApFull().getParm("path_img_tmp").getTesto();
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 3.1 : " + pathBase);
|
||||
File pathBaseFile = new File(pathBase);
|
||||
if (!pathBaseFile.exists())
|
||||
pathBaseFile.mkdirs();
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 4");
|
||||
boolean itsOk = true;
|
||||
FaceRecognition fa = null;
|
||||
fa = FaceRecognition.getInstance(apFull);
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 5");
|
||||
JSONArray jresponses = new JSONArray();
|
||||
int numberOfFaces = 0;
|
||||
int numberOfNumbers = 0;
|
||||
JSONArray jRequestsA = jo.getJSONArray("requests");
|
||||
for (int i = 0; i < jRequestsA.length(); i++) {
|
||||
JSONObject jRequest = jRequestsA.getJSONObject(i);
|
||||
String imageContent = null, imagePath = null;
|
||||
boolean hasImage = false;
|
||||
if (jRequest.has("path")) {
|
||||
imagePath = jRequest.getString("path");
|
||||
} else {
|
||||
hasImage = true;
|
||||
imageContent = jRequest.getJSONObject("image").getString("content");
|
||||
}
|
||||
String md5 = jRequest.getString("md5");
|
||||
long detectionMethod = jRequest.getLong("faceDetectionType");
|
||||
boolean numbers = jRequest.getBoolean("numbers");
|
||||
FotoRequest fr = new FotoRequest(getApFull());
|
||||
long l_requestType = 0L;
|
||||
if (!numbers && detectionMethod > 0L) {
|
||||
l_requestType = 1L;
|
||||
} else if (numbers == true && detectionMethod < 0L) {
|
||||
l_requestType = 3L;
|
||||
} else if (!numbers && detectionMethod < 0L) {
|
||||
l_requestType = -1L;
|
||||
}
|
||||
if (l_requestType >= 0L) {
|
||||
fr.findByUserMd5DetectionmethodRequesttype(user.getId_users(), md5, detectionMethod, l_requestType);
|
||||
String dbJson = fr.getJson();
|
||||
if (!dbJson.isEmpty() && !dbJson.equals("{}")) {
|
||||
JSONObject jresponse = new JSONObject(dbJson);
|
||||
jresponses.put(jresponse);
|
||||
fr.addRichiesta();
|
||||
fr.save();
|
||||
} else {
|
||||
String currentImage;
|
||||
if (hasImage) {
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(imageContent);
|
||||
currentImage = pathBase + pathBase + ".jpg";
|
||||
File file = new File(currentImage);
|
||||
if (!file.exists()) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(decodedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
hsFiles.add(file);
|
||||
} else {
|
||||
currentImage = imagePath;
|
||||
}
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 6");
|
||||
JSONObject jresponse = fa.detectFaces(currentImage, detectionMethod, numbers);
|
||||
if (hasImage)
|
||||
for (File elemento : hsFiles)
|
||||
elemento.delete();
|
||||
jresponses.put(jresponse);
|
||||
if (jresponse.has("numOfFaces"))
|
||||
numberOfFaces += jresponse.getInt("numOfFaces");
|
||||
if (jresponse.has("numOfNumbers"))
|
||||
numberOfNumbers += jresponse.getInt("numOfNumbers");
|
||||
if (user.getId_users() > 0L) {
|
||||
fr.setId_users(user.getId_users());
|
||||
fr.setJson(jresponse.toString());
|
||||
fr.setMd5(md5);
|
||||
fr.setFaceDetectionMethodCode(detectionMethod);
|
||||
fr.setFlgRequestType(l_requestType);
|
||||
fr.addRichiesta();
|
||||
fr.save();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
itsOk = false;
|
||||
err.append("Tipo richiesta e metodo detect faces non impostati");
|
||||
}
|
||||
}
|
||||
if (debug)
|
||||
System.out.println("************ _detectFacesAndNumbers_POST 7");
|
||||
JSONObject joRes = new JSONObject();
|
||||
if (itsOk) {
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", "Trovate in totale " + numberOfFaces + " visi e " + numberOfNumbers + " numeri su " +
|
||||
jresponses.length() + " foto: " + msg.toString());
|
||||
joRes.put("responses", jresponses);
|
||||
} else {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Errore! " + err.toString());
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println("************ _detectFacesAndNumbers_POST RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
}
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject joRes = new JSONObject();
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Eccezione!! " + e.getMessage());
|
||||
System.out.println("************ _detectFacesAndNumbers_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String hostname = "localhost";
|
||||
String db = "cc";
|
||||
ApplParmFull ap = new ApplParmFull(new ApplParm(14, "//" + hostname + ":1433;databaseName=" + db + ";user=sa;password=T3st000!", null, null, 1, 10, 300));
|
||||
}
|
||||
|
||||
protected boolean checkBasicAuth(HttpServletRequest req, HttpServletResponse res) {
|
||||
boolean authOk = false;
|
||||
try {
|
||||
String[] auth = getBasicAuthorizationHeaders(req, res);
|
||||
if (auth != null) {
|
||||
Users bean = getUsersByBasicAuth(req, res);
|
||||
if (bean.getDBState() == 1) {
|
||||
authOk = true;
|
||||
} else {
|
||||
System.out.println("FaceRestSvlt.checkBasicAuth KO: login-->" + auth[0] + " pwd-->" + auth[1]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return authOk;
|
||||
}
|
||||
|
||||
protected String getApiBaseUrl() {
|
||||
return "/fr/face/";
|
||||
}
|
||||
|
||||
protected Users getUsersByBasicAuth(HttpServletRequest req, HttpServletResponse res) {
|
||||
String[] auth = getBasicAuthorizationHeaders(req, res);
|
||||
Users bean = new Users(getApFull());
|
||||
if (auth != null)
|
||||
bean.findLogonUtente(auth[0], auth[1], req.getRemoteAddr());
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void _trainingSendImages_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
boolean debug = false;
|
||||
StringBuilder err = new StringBuilder();
|
||||
try {
|
||||
JSONObject jo = getApiJSONObject();
|
||||
if (debug) {
|
||||
System.out.println("************ _trainingSendimages_POST *********************");
|
||||
System.out.println("json in arrivo");
|
||||
System.out.println(jo.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
}
|
||||
long newFaces = 0L;
|
||||
long newFacesNoImg = 0L;
|
||||
long findFaces = 0L;
|
||||
JSONObject joRes = new JSONObject();
|
||||
String code = jo.getString("code");
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "RECEIVING TRAINING IMAGES FOR " + code + " .... ");
|
||||
FaceRecognizer frzer = new FaceRecognizer(getApFull());
|
||||
frzer.findByCode(code);
|
||||
if (frzer.getId_faceRecognizer() == 0L) {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "ERRORE! Recognizer " + code + " non trovato.");
|
||||
} else {
|
||||
JSONArray jRequestsA = jo.getJSONArray("requests");
|
||||
JSONArray jNoImageA = new JSONArray();
|
||||
JSONArray jLabelsA = new JSONArray();
|
||||
Face face = new Face(getApFull());
|
||||
Face faceLabel = new Face(getApFull());
|
||||
FaceFaceRecognizer ffr = new FaceFaceRecognizer(getApFull());
|
||||
Timer timer = new Timer();
|
||||
timer.start();
|
||||
String eta = " ....";
|
||||
for (int i = 0; i < jRequestsA.length(); i++) {
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "RECEIVING TRAINING IMAGES FOR " + code + " .... " + i + 1 + "/" +
|
||||
jRequestsA.length() + 1 + " new: " + newFaces + " new noimg: " + newFacesNoImg + " find faces:" + findFaces + eta);
|
||||
JSONObject jRequest = jRequestsA.getJSONObject(i);
|
||||
String md5 = jRequest.getString("md5");
|
||||
long label = jRequest.getLong("label");
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " _trainingSendImages_POST: getting md5: " + String.valueOf(DBAdapter.getNow()));
|
||||
if (label > 0L) {
|
||||
faceLabel.findByPrimaryKey(label);
|
||||
if (faceLabel.getId_face() == 0L) {
|
||||
err.append("Inviata immagine con label non trovate: " + label);
|
||||
err.append("\n");
|
||||
}
|
||||
}
|
||||
if (err.length() == 0) {
|
||||
face.findByMd5(md5);
|
||||
if (face.getId_face() == 0L) {
|
||||
newFaces++;
|
||||
if (jRequest.has("image")) {
|
||||
face.setMd5(md5);
|
||||
ResParm rp = face.save();
|
||||
if (rp.getStatus()) {
|
||||
String imageContent = jRequest.getJSONObject("image")
|
||||
.getString("content");
|
||||
File path = new File(face.getPathFaceImg());
|
||||
if (!path.exists())
|
||||
path.mkdirs();
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(imageContent);
|
||||
File file = new File(face.getFullFileName());
|
||||
if (!file.exists()) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(decodedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
err.append("Impossibile salvare l'immagine md5 " + md5 + ". " + e.getMessage());
|
||||
err.append("\n");
|
||||
} finally {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err.append("Impossibile salvare record md5 " + md5);
|
||||
err.append("\n");
|
||||
}
|
||||
} else {
|
||||
newFacesNoImg++;
|
||||
JSONObject jMd5 = new JSONObject();
|
||||
jMd5.put("md5", md5);
|
||||
jNoImageA.put(jMd5);
|
||||
}
|
||||
} else {
|
||||
findFaces++;
|
||||
}
|
||||
StatusMsg.updateMsgByTag(getApFull(), "TRAINING_RUN", "RECEIVING TRAINING IMAGES FOR " + code + " .... " + i + 1 + "/" +
|
||||
jRequestsA.length() + 1 + " new: " + newFaces + " new noimg: " + newFacesNoImg + " find faces:" + findFaces + eta);
|
||||
if (face.getId_face() > 0L) {
|
||||
ffr.findByRecognizerLabel(frzer.getId_faceRecognizer(), face.getId_face());
|
||||
boolean doSave = false;
|
||||
if (ffr.getId_faceFaceRecognizer() == 0L) {
|
||||
ffr.setId_face(face.getId_face());
|
||||
ffr.setId_faceRecognizer(frzer.getId_faceRecognizer());
|
||||
doSave = true;
|
||||
}
|
||||
if (ffr.getId_faceLabel() != label) {
|
||||
ffr.setId_faceLabel(label);
|
||||
doSave = true;
|
||||
}
|
||||
if (doSave)
|
||||
ResParm resParm = ffr.save();
|
||||
JSONObject jLabelrow = new JSONObject();
|
||||
jLabelrow.put("md5", face.getMd5());
|
||||
jLabelrow.put("label", ffr.getId_faceLabel());
|
||||
jLabelrow.put("labelMd5", ffr.getFaceLabel().getMd5());
|
||||
jLabelsA.put(jLabelrow);
|
||||
}
|
||||
}
|
||||
eta = " " + timer.getEta((long)jRequestsA.length(), (long)i);
|
||||
}
|
||||
if (err.length() > 0) {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Codice " + code + " Errore: " + err.toString());
|
||||
} else {
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", "Training in corso: ricezione immagini....");
|
||||
joRes.put("code", code);
|
||||
joRes.put("numberTrainingImages",
|
||||
ffr.getTotFaceByFaceRecognizer(frzer.getId_faceRecognizer()));
|
||||
if (jNoImageA.length() > 0)
|
||||
joRes.put("noImg", jNoImageA);
|
||||
if (jLabelsA.length() > 0)
|
||||
joRes.put("labels", jLabelsA);
|
||||
}
|
||||
}
|
||||
if (!debug);
|
||||
System.out.println("************ _trainingSendimages_POST RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject joRes = new JSONObject();
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Eccezione!! " + e.getMessage());
|
||||
System.out.println("************ _trainingSendimages_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
}
|
||||
StatusMsg.deleteMsgByTag(getApFull(), "TRAINING_RUN");
|
||||
}
|
||||
|
||||
private ResParm trainingCreate(String l_sessionId, List<TrainingImage> trainingImages, int recognizerType) {
|
||||
ResParm rp = new ResParm();
|
||||
org.opencv.face.FaceRecognizer ocvFr = (org.opencv.face.FaceRecognizer)getCache()
|
||||
.getIfPresent(l_sessionId + "_" + l_sessionId);
|
||||
int counter = 0;
|
||||
String counterKey = l_sessionId + "_" + l_sessionId + "_counter";
|
||||
Integer Icounter = (Integer)getCache().getIfPresent(counterKey);
|
||||
if (Icounter != null)
|
||||
counter = Icounter;
|
||||
if (trainingImages.size() > 0) {
|
||||
Mat labels = new Mat(trainingImages.size(), 1, CvType.CV_32SC1);
|
||||
MatOfInt labelsMat = new MatOfInt();
|
||||
List<Mat> trainingImagesMat = new ArrayList<>();
|
||||
for (TrainingImage trainingImage : trainingImages) {
|
||||
File imageFile = new File(trainingImage.getImageFileName());
|
||||
Mat image = Imgcodecs.imread(imageFile.getAbsolutePath());
|
||||
Mat grayImage = new Mat();
|
||||
Imgproc.cvtColor(image, grayImage, 6);
|
||||
trainingImagesMat.add(grayImage);
|
||||
labels.put(counter, 0, new double[] { (double)trainingImage.getLabel() });
|
||||
counter++;
|
||||
}
|
||||
labels.convertTo((Mat)labelsMat, CvType.CV_32SC1);
|
||||
ocvFr.train(trainingImagesMat, labels);
|
||||
getCache().put(counterKey, Integer.valueOf(counter));
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
private Cache<String, Object> getCache() {
|
||||
if (this.cache == null)
|
||||
this.cache = CacheBuilder.newBuilder().maximumSize(100L).expireAfterAccess(100L, TimeUnit.MINUTES).build();
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
public void _recognize_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
boolean debug = true;
|
||||
Users user = getUsersByBasicAuth(req, res);
|
||||
StringBuilder err = new StringBuilder();
|
||||
try {
|
||||
JSONObject jo = getApiJSONObject();
|
||||
if (debug) {
|
||||
System.out.println("************ _recognize_POST *********************");
|
||||
System.out.println("json in arrivo");
|
||||
System.out.println(jo.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
debugHelper.writeLog("************ _recognize_POST *********************");
|
||||
debugHelper.writeLog("json in arrivo");
|
||||
debugHelper.writeLog(jo.toString(4));
|
||||
debugHelper.writeLog("*-------------- FINE ---------------------------*");
|
||||
}
|
||||
JSONObject joRes = new JSONObject();
|
||||
JSONArray jResponses = new JSONArray();
|
||||
String code = jo.getString("code");
|
||||
FaceRecognition fa = null;
|
||||
fa = FaceRecognition.getInstance(apFull);
|
||||
FaceRecognizer frzer = new FaceRecognizer(getApFull());
|
||||
frzer.findByCode(code);
|
||||
if (frzer.getId_faceRecognizer() == 0L) {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "ERRORE! Recognizer " + code + " non trovato.");
|
||||
} else {
|
||||
JSONArray jRequestsA = jo.getJSONArray("requests");
|
||||
JSONArray jNoImageA = new JSONArray();
|
||||
Facer facer = new Facer(getApFull());
|
||||
for (int i = 0; i < jRequestsA.length(); i++) {
|
||||
JSONObject jRequest = jRequestsA.getJSONObject(i);
|
||||
String md5 = jRequest.getString("md5");
|
||||
facer.findByMd5Recognizer(md5, frzer.getId_faceRecognizer());
|
||||
if (facer.getId_facer() == 0L)
|
||||
if (jRequest.has("image")) {
|
||||
facer.setMd5(md5);
|
||||
facer.setId_faceRecognizer(frzer.getId_faceRecognizer());
|
||||
ResParm rp = facer.save();
|
||||
if (rp.getStatus()) {
|
||||
String imageContent = jRequest.getJSONObject("image")
|
||||
.getString("content");
|
||||
File path = new File(facer.getPathFaceImg());
|
||||
if (!path.exists())
|
||||
path.mkdirs();
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(imageContent);
|
||||
File file = new File(facer.getFullFileName());
|
||||
if (!file.exists()) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(decodedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
err.append("Impossibile salvare l'immagine md5 " + md5 + ". " + e.getMessage());
|
||||
err.append("\n");
|
||||
} finally {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err.append("Impossibile salvare record md5 " + md5);
|
||||
err.append("\n");
|
||||
}
|
||||
} else if (jRequest.has("originalPath")) {
|
||||
String originalFilePath = jRequest.getString("originalPath");
|
||||
File originalFile = new File(originalFilePath);
|
||||
if (originalFile.exists()) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " _recognize_POST trovato " + originalFilePath);
|
||||
facer.setMd5(md5);
|
||||
facer.setId_faceRecognizer(frzer.getId_faceRecognizer());
|
||||
facer.setFileAlternativo(originalFilePath);
|
||||
ResParm rp = facer.save();
|
||||
if (!rp.getStatus()) {
|
||||
err.append("Impossibile salvare record md5 " + md5 + " filealt: " + originalFilePath);
|
||||
err.append("\n");
|
||||
}
|
||||
} else {
|
||||
JSONObject jMd5 = new JSONObject();
|
||||
jMd5.put("md5", md5);
|
||||
jNoImageA.put(jMd5);
|
||||
}
|
||||
} else {
|
||||
JSONObject jMd5 = new JSONObject();
|
||||
jMd5.put("md5", md5);
|
||||
jNoImageA.put(jMd5);
|
||||
}
|
||||
JSONObject jResponse = new JSONObject();
|
||||
if (facer.getId_facer() > 0L) {
|
||||
String currentFileName;
|
||||
if (facer.getFileAlternativo().isEmpty()) {
|
||||
currentFileName = facer.getFullFileName();
|
||||
} else {
|
||||
currentFileName = facer.getFileAlternativo();
|
||||
}
|
||||
if (debug)
|
||||
System.out.println(
|
||||
String.valueOf(DBAdapter.getNowTs()) + " _recognize_POST chiamo face recognition su " + String.valueOf(DBAdapter.getNowTs()));
|
||||
JSONArray jLabelsA = fa.faceRecognition(currentFileName, frzer);
|
||||
jResponse.put("md5", md5);
|
||||
jResponse.put("labels", jLabelsA);
|
||||
jResponses.put(jResponse);
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " _recognize_POST risposta da face recognition;\n" +
|
||||
jResponses.toString(4));
|
||||
}
|
||||
}
|
||||
if (err.length() > 0) {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Codice " + code + " Errore: " + err.toString());
|
||||
} else {
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", "Recognizer Ok.");
|
||||
joRes.put("code", code);
|
||||
if (jResponses.length() > 0)
|
||||
joRes.put("responses", jResponses);
|
||||
if (jNoImageA.length() > 0)
|
||||
joRes.put("noImg", jNoImageA);
|
||||
}
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", "Recognizer Ok");
|
||||
joRes.put("code", code);
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println("************ _recognize_POST RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
debugHelper.writeLog("************ _recognize_POST RISPOSTA AL CLIENT *********************");
|
||||
debugHelper.writeLog(joRes.toString(4));
|
||||
}
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject joRes = new JSONObject();
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Eccezione!! " + e.getMessage());
|
||||
System.out.println("************ _recognize_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
debugHelper.writeLog("************ _recognize_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
debugHelper.writeLog(joRes.toString(4));
|
||||
debugHelper.writeLog("*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void _syncFaceDetectionMethods_GET(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
try {
|
||||
JSONObject joRes = new JSONObject();
|
||||
FaceDetectionMethod fdm = new FaceDetectionMethod(apFull);
|
||||
Vectumerator<FaceDetectionMethod> vec = fdm.findByCR(new FaceDetectionMethodCR(), 0, 0);
|
||||
JSONArray jaFdm = new JSONArray();
|
||||
while (vec.hasMoreElements()) {
|
||||
FaceDetectionMethod row = (FaceDetectionMethod)vec.nextElement();
|
||||
JSONObject jRow = new JSONObject();
|
||||
jRow.put("codice", row.getCodice());
|
||||
jRow.put("flgDetectionType", row.getFlgDetectionType());
|
||||
jRow.put("descrizione", row.getDescrizione());
|
||||
jRow.put("descrizioneLunga", row.getDescrizioneLunga());
|
||||
jaFdm.put(jRow);
|
||||
}
|
||||
joRes.put("faceDetectionMethods", jaFdm);
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", "Trovati " + vec.getTotNumberOfRecords() + " metodi");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject joRes = new JSONObject();
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Eccezione!! " + e.getMessage());
|
||||
System.out.println("************ _trainingRun_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void _checkLabel_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
ResParm rp = new ResParm(true);
|
||||
boolean debug = false;
|
||||
try {
|
||||
JSONObject jo = getApiJSONObject();
|
||||
if (debug) {
|
||||
System.out.println("************ _checklabel_POST *********************");
|
||||
System.out.println("json in arrivo");
|
||||
System.out.println(jo.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
}
|
||||
JSONObject joRes = new JSONObject();
|
||||
long label = jo.getLong("label");
|
||||
String md5 = jo.getString("md5");
|
||||
boolean reqImage = jo.getBoolean("reqImage");
|
||||
boolean addLabel = jo.getBoolean("addLabel");
|
||||
FaceRecognizer frzer = new FaceRecognizer(apFull);
|
||||
String code = "";
|
||||
if (jo.has("code")) {
|
||||
code = jo.getString("code");
|
||||
frzer.findByCode(code);
|
||||
}
|
||||
Face face = new Face(apFull);
|
||||
if (!md5.isEmpty()) {
|
||||
face.findByMd5(md5);
|
||||
if (debug)
|
||||
System.out.println("-- face find by md5--> " + face.getDescRecord());
|
||||
} else if (face.getId_face() == 0L && label > 0L) {
|
||||
face.findByLabel(label);
|
||||
}
|
||||
if (face.getId_face() == 0L) {
|
||||
if (addLabel && !md5.isEmpty()) {
|
||||
face.setMd5(md5);
|
||||
rp = face.save();
|
||||
if (debug)
|
||||
System.out.println("-- face add nuovo by md5--> " + face.getDescRecord());
|
||||
if (rp.getStatus()) {
|
||||
StringBuilder err = new StringBuilder();
|
||||
String imageContent = jo.getJSONObject("image")
|
||||
.getString("content");
|
||||
File path = new File(face.getPathFaceImg());
|
||||
if (!path.exists())
|
||||
path.mkdirs();
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(imageContent);
|
||||
File file = new File(face.getFullFileName());
|
||||
if (!file.exists()) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(decodedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
err.append("Impossibile salvare l'immagine md5 " + face.getMd5() + ". " + e.getMessage());
|
||||
err.append("\n");
|
||||
} finally {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
if (err.length() > 0) {
|
||||
handleDebug(err.toString());
|
||||
rp.setStatus(false);
|
||||
rp.setMsg(err.toString());
|
||||
}
|
||||
} else {
|
||||
handleDebug(rp.getErrMsg());
|
||||
}
|
||||
FaceFaceRecognizer ffr = new FaceFaceRecognizer(getApFull());
|
||||
if (frzer.getId_faceRecognizer() == 0L) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Attenzione! Aggiunta immagine ma impossibile associare a recognizer nullo!");
|
||||
} else {
|
||||
ffr.setId_faceRecognizer(frzer.getId_faceRecognizer());
|
||||
ffr.setId_face(face.getId_face());
|
||||
ffr.setId_faceLabel(face.getId_face());
|
||||
rp = ffr.save();
|
||||
if (debug)
|
||||
System.out.println("-- ffr add nuovo dopo face--> " + ffr.getDescRecord());
|
||||
}
|
||||
if (debug)
|
||||
System.out.println("-- prima della scrittura finale se creato addlabel --> " + ffr.getDescRecord());
|
||||
if (rp.getStatus()) {
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", rp.getMsg());
|
||||
joRes.put("id", ffr.getId_face());
|
||||
joRes.put("label", ffr.getId_faceLabel());
|
||||
joRes.put("labelMd5", face.getMd5());
|
||||
} else {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", rp.getMsg());
|
||||
joRes.put("id", ffr.getId_face());
|
||||
joRes.put("label", ffr.getId_faceLabel());
|
||||
joRes.put("labelMd5", face.getMd5());
|
||||
}
|
||||
} else {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Label " + label + " non trovata ");
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Label " + label + " non trovata: " + rp.getMsg());
|
||||
}
|
||||
} else {
|
||||
FaceFaceRecognizer ffr = new FaceFaceRecognizer(getApFull());
|
||||
if (addLabel) {
|
||||
if (frzer.getId_faceRecognizer() == 0L) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Attenzione! Aggiunta immagine ma impossibile associare a recognizer nullo!");
|
||||
} else {
|
||||
ffr.findByRecognizerLabel(frzer.getId_faceRecognizer(), face.getId_face());
|
||||
if (debug)
|
||||
System.out.println("-- ffr add o modificato trovato???--> " + ffr.getDescRecord());
|
||||
if (ffr.getId_faceFaceRecognizer() == 0L || ffr.getId_face() != ffr.getId_faceLabel()) {
|
||||
ffr.setId_faceRecognizer(frzer.getId_faceRecognizer());
|
||||
ffr.setId_face(face.getId_face());
|
||||
ffr.setId_faceLabel(face.getId_face());
|
||||
ffr.save();
|
||||
if (debug)
|
||||
System.out.println("-- ffr add o modificato se trovato face con md5--> " + ffr.getDescRecord());
|
||||
}
|
||||
}
|
||||
} else if (frzer.getId_faceRecognizer() == 0L) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Attenzione! Impossibile associare a recognizer nullo!");
|
||||
} else {
|
||||
ffr.findByRecognizerLabel(frzer.getId_faceRecognizer(), face.getId_face());
|
||||
if (ffr.getId_faceFaceRecognizer() == 0L) {
|
||||
ffr.setId_faceRecognizer(frzer.getId_faceRecognizer());
|
||||
ffr.setId_face(face.getId_face());
|
||||
ffr.save();
|
||||
}
|
||||
}
|
||||
if (debug)
|
||||
System.out.println("-- prima della scrittura finale se trovato --> " + ffr.getDescRecord());
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", rp.getMsg());
|
||||
joRes.put("id", ffr.getId_face());
|
||||
joRes.put("label", ffr.getId_faceLabel());
|
||||
joRes.put("labelMd5", face.getMd5());
|
||||
if (reqImage) {
|
||||
JSONObject jImage = new JSONObject();
|
||||
byte[] fileContent = FileUtils.readFileToByteArray(new File(face.getFullFileName()));
|
||||
String encodedString = Base64.getEncoder().encodeToString(fileContent);
|
||||
jImage.put("content", encodedString);
|
||||
joRes.put("image", jImage);
|
||||
}
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println("************ _checklabel_POST RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
}
|
||||
System.out.println(String.valueOf(DBAdapter.getNow()) + " _checkLabel_POST. md5: " + String.valueOf(DBAdapter.getNow()) + " label: " + md5);
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject joRes = new JSONObject();
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Eccezione!! " + e.getMessage());
|
||||
System.out.println("************ _checklabel_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void _trainingRun_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
boolean debug = true;
|
||||
try {
|
||||
JSONObject jo = getApiJSONObject();
|
||||
if (debug) {
|
||||
System.out.println("************ _trainingRun_POST *********************");
|
||||
System.out.println("json in arrivo");
|
||||
System.out.println(jo.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
}
|
||||
JSONObject joRes = new JSONObject();
|
||||
String code = jo.getString("code");
|
||||
FaceRecognizer frzer = new FaceRecognizer(apFull);
|
||||
frzer.findByCode(code);
|
||||
if (frzer.getId_faceRecognizer() == 0L) {
|
||||
if (debug)
|
||||
System.out.println("_trainingRun_POST RECOGNIZER NON TROVATO ");
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "ERRORE! Recognizer " + code + " non trovato.");
|
||||
} else {
|
||||
if (debug)
|
||||
System.out.println("_trainingRun_POST trainingAndCreateModel su thread separato.... ");
|
||||
Thread thread = new Thread(() -> {
|
||||
ResParm rpT = new ResParm();
|
||||
try {
|
||||
rpT = frzer.trainingAndCreateModel(true);
|
||||
if (debug)
|
||||
System.out.println("_trainingRun_POST MODELLO CREATO.... " + rpT.getMsg());
|
||||
} catch (Exception e) {
|
||||
if (debug)
|
||||
System.out.println("_trainingRun_POST MODELLO NON CREATO....: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
if (debug)
|
||||
System.out.println("_trainingRun_POST preparo la risposta........................................... ");
|
||||
joRes.put("code", code);
|
||||
joRes.put("numberTrainingImages", frzer.getNTrainingImages());
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", "Training concluso con successo. Creazione modello in corso...");
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println("************ _trainingRun_POST RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
}
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject joRes = new JSONObject();
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Eccezione!! " + e.getMessage());
|
||||
System.out.println("************ _trainingRun_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void _resetTraining_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
try {
|
||||
JSONObject jo = getApiJSONObject();
|
||||
JSONObject joRes = new JSONObject();
|
||||
String code = jo.getString("code");
|
||||
FaceRecognizer frzer = new FaceRecognizer(apFull);
|
||||
frzer.findByCode(code);
|
||||
if (frzer.getId_faceRecognizer() == 0L) {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "ERRORE! Recognizer " + code + " non trovato.");
|
||||
} else {
|
||||
ResParm rp = frzer.resetTraining();
|
||||
if (rp.getStatus()) {
|
||||
joRes.put("success", "true");
|
||||
joRes.put("msg", "Codice " + code + " resettato");
|
||||
} else {
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Codice " + code + " NON resettato correttamente: " + rp.getMsg());
|
||||
}
|
||||
}
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject joRes = new JSONObject();
|
||||
joRes.put("success", "false");
|
||||
joRes.put("msg", "Eccezione!! " + e.getMessage());
|
||||
System.out.println("************ _resetTrainig_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
System.out.println(joRes.toString(4));
|
||||
System.out.println("*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected Class<? extends _AblRestAdapter> getConcreteApiClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.fr.rest;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package it.acxent.face.fr.servlet.admin;
|
||||
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.dm.FaceDetectionMethod;
|
||||
import it.acxent.dm.FaceDetectionMethodCR;
|
||||
import it.acxent.servlet.AblServletSvlt;
|
||||
import it.acxent.servlet.AddImgSvlt;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class FaceDetectionMethodSvlt extends AblServletSvlt implements AddImgSvlt {
|
||||
private static final long serialVersionUID = 5676887616087638826L;
|
||||
|
||||
protected void fillComboAfterDetail(DBAdapter beanA, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterSearch(CRAdapter CRA, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return new FaceDetectionMethod(getApFull(req));
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return new FaceDetectionMethodCR(getApFull(req));
|
||||
}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {
|
||||
super.search(req, res);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package it.acxent.face.fr.servlet.admin;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.fr.FaceRecognizer;
|
||||
import it.acxent.face.fr.FaceRecognizerCR;
|
||||
import it.acxent.servlet.AblServletSvlt;
|
||||
import it.acxent.servlet.AddImgSvlt;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class FaceRecognizerSvlt extends AblServletSvlt implements AddImgSvlt {
|
||||
private static final long serialVersionUID = 5676887616087638826L;
|
||||
|
||||
private static boolean debug = true;
|
||||
|
||||
protected void fillComboAfterDetail(DBAdapter beanA, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterSearch(CRAdapter CRA, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return new FaceRecognizer(getApFull(req));
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return new FaceRecognizerCR(getApFull(req));
|
||||
}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {
|
||||
super.search(req, res);
|
||||
}
|
||||
|
||||
public void _resetTraining(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
FaceRecognizer bean = new FaceRecognizer(apFull);
|
||||
long l_id = getRequestLongParameter(req, "id_faceRecognizer");
|
||||
ResParm rp = new ResParm();
|
||||
bean.findByPrimaryKey(l_id);
|
||||
rp = bean.resetTraining();
|
||||
if (rp.getStatus()) {
|
||||
sendMessage(req, "Reset training ok");
|
||||
} else {
|
||||
sendMessage(req, "Errore! " + rp.getMsg());
|
||||
}
|
||||
showBean(req, res);
|
||||
}
|
||||
|
||||
public void _rebuildModel(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
FaceRecognizer bean = new FaceRecognizer(apFull);
|
||||
long l_id = getRequestLongParameter(req, "id_faceRecognizer");
|
||||
FaceRecognizerCR CR = new FaceRecognizerCR(apFull);
|
||||
CR.setId_faceRecognizer(l_id);
|
||||
bean.findByPrimaryKey(l_id);
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
ResParm rp = new ResParm();
|
||||
bean.trainingAndCreateModel(true);
|
||||
DBAdapter.printDebug(debug, " trainingAndCreateModel. Operazione completata: " + rp.getMsg());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
sendMessage(req, "trainingAndCreateModel lanciato in un thread separato....");
|
||||
showBean(req, res);
|
||||
}
|
||||
|
||||
public void _precaricaModelliFile(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
FaceRecognizerCR CR = new FaceRecognizerCR(apFull);
|
||||
fillObject(req, CR);
|
||||
CR.setPageRow(getPageRow(req));
|
||||
FaceRecognizer bean = new FaceRecognizer(apFull);
|
||||
ResParm rp = bean.startCaricaModelli(CR, true);
|
||||
sendMessage(req, rp.getMsg());
|
||||
search(req, res);
|
||||
}
|
||||
|
||||
public void _removeAllModelFromCache(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
FaceRecognizer bean = new FaceRecognizer(apFull);
|
||||
bean.removeAllOcvFaceRecognizerWithLoadedModel();
|
||||
sendMessage(req, "Rimossi i modelli dalla cache");
|
||||
search(req, res);
|
||||
}
|
||||
|
||||
public void _precaricaModelli(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
FaceRecognizerCR CR = new FaceRecognizerCR(apFull);
|
||||
fillObject(req, CR);
|
||||
CR.setPageRow(getPageRow(req));
|
||||
FaceRecognizer bean = new FaceRecognizer(apFull);
|
||||
ResParm rp = bean.startCaricaModelli(CR, false);
|
||||
sendMessage(req, rp.getMsg());
|
||||
search(req, res);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package it.acxent.face.fr.servlet.admin;
|
||||
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.face.fr.Face;
|
||||
import it.acxent.face.fr.FaceCR;
|
||||
import it.acxent.servlet.AblServletSvlt;
|
||||
import it.acxent.servlet.AddImgSvlt;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class FaceSvlt extends AblServletSvlt implements AddImgSvlt {
|
||||
private static final long serialVersionUID = 5676887616087638826L;
|
||||
|
||||
protected void fillComboAfterDetail(DBAdapter beanA, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterSearch(CRAdapter CRA, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return new Face(getApFull(req));
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return new FaceCR(getApFull(req));
|
||||
}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {
|
||||
super.search(req, res);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package it.acxent.face.fr.servlet.admin;
|
||||
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.face.fr.Face;
|
||||
import it.acxent.servlet.AcStndSvlt;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class GetFileSvlt extends AcStndSvlt {
|
||||
private static final long serialVersionUID = -3037980260742696647L;
|
||||
|
||||
protected boolean checkLoginProfile(HttpServletRequest req) {
|
||||
try {
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
handleDebug(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected String getLoginPage(HttpServletRequest req, HttpServletResponse res) {
|
||||
return "/documentoCR.jsp";
|
||||
}
|
||||
|
||||
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
|
||||
chiamaJsp(req, res);
|
||||
}
|
||||
|
||||
protected void chiamaJsp(HttpServletRequest req, HttpServletResponse res) {
|
||||
try {
|
||||
String fileName = "";
|
||||
long l_id_face = getRequestLongParameter(req, "id_face");
|
||||
String l_labelMd5 = getRequestParameter(req, "labelMd5");
|
||||
if (!l_labelMd5.isEmpty()) {
|
||||
Face ff = new Face(getApFull());
|
||||
ff.findByMd5(l_labelMd5);
|
||||
if (ff.getDBState() == 1)
|
||||
fileName = ff.getFullFileName();
|
||||
} else if (l_id_face > 0L) {
|
||||
Face ff = new Face(getApFull());
|
||||
ff.findByPrimaryKey(l_id_face);
|
||||
if (ff.getDBState() == 1)
|
||||
fileName = ff.getFullFileName();
|
||||
}
|
||||
File theFile = new File(fileName);
|
||||
if (theFile.exists())
|
||||
if (fileName.toLowerCase().endsWith("gif")) {
|
||||
System.out.println("Getfile www gifs-->>>>");
|
||||
res.setContentType("image/gif");
|
||||
ByteArrayOutputStream ba = DBAdapter.getByteArrayFromFile(fileName);
|
||||
res.setContentLength(ba.size());
|
||||
try {
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
ba.writeTo((OutputStream)out);
|
||||
out.flush();
|
||||
} catch (Exception e) {
|
||||
handleDebug(e, 0);
|
||||
}
|
||||
} else {
|
||||
theFile = new File(fileName);
|
||||
if (theFile.exists()) {
|
||||
res.setContentType("image/jpg");
|
||||
ByteArrayOutputStream ba = DBAdapter.getByteArrayFromFile(fileName);
|
||||
res.setContentLength(ba.size());
|
||||
try {
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
ba.writeTo((OutputStream)out);
|
||||
out.flush();
|
||||
} catch (Exception e) {
|
||||
handleDebug(e, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void mostraDettaglio(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void accessiSql(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package it.acxent.face.fr.servlet.admin;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.fr.FaceRecognizer;
|
||||
import it.acxent.face.fr.FaceRecognizerCR;
|
||||
import it.acxent.servlet.AcServlet;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet(loadOnStartup = 1)
|
||||
public class InitRecognizerSvlt extends AcServlet {
|
||||
private static final long serialVersionUID = -4052399191302059215L;
|
||||
|
||||
protected void processRequest(HttpServletRequest request, HttpServletResponse response) {}
|
||||
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
ApplParmFull apFull = getApFullSc(config);
|
||||
System.out.println("InitRecognizerSvlt ");
|
||||
FaceRecognizer bean = new FaceRecognizer(apFull);
|
||||
FaceRecognizerCR CR = new FaceRecognizerCR(apFull);
|
||||
ResParm rp = bean.startCaricaModelli(CR, false);
|
||||
System.out.println("InitRecognizerSvlt ... thread lanciato...");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.fr.servlet.admin;
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package it.acxent.face.fr.zoo;
|
||||
|
||||
import it.acxent.common.Parm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class Users extends it.acxent.anag.Users {
|
||||
public Users() {}
|
||||
|
||||
public Users(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public void initApplicationParms(ApplParmFull ap) {
|
||||
if (ap != null) {
|
||||
super.initApplicationParms(ap);
|
||||
String l_tipoParm = "";
|
||||
Parm bean = new Parm(ap);
|
||||
l_tipoParm = "FACE-FR-ZOO";
|
||||
bean.findByCodice("PATH_ZOO_BACKEND_TARGET");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PATH_ZOO_BACKEND_TARGET");
|
||||
bean.setDescrizione("PATH_ZOO_BACKEND_TARGET");
|
||||
bean.setFlgTipo(1L);
|
||||
bean.setNota(" Choose one of the backend-target pair:<br>0: (default) OpenCV implementation + CPU, <br>1: CUDA + GPU (CUDA), <br>2: CUDA + GPU (CUDA FP16), <br>3: TIM-VX + NPU, <br>4: CANN + NPU");
|
||||
bean.save();
|
||||
bean.findByCodice("PATH_ZOO_FACE_DETECTION_SCRIPT");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PATH_ZOO_FACE_DETECTION_SCRIPT");
|
||||
bean.setDescrizione("PATH_ZOO_FACE_DETECTION_SCRIPT");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/home/sites/fr/admin/_shell/detection.sh");
|
||||
bean.setNota("Script completo per recognizer: <br>/home/sites/zoo/admin/_shell/detection.sh<br>I parametri sono<br> --input_json INPUT_JSON<br>Path del file JSON di input.\n --output_json OUTPUT_JSON<br>Path del file JSON di output.\n --backend_target BACKEND_TARGET, -bt BACKEND_TARGET<br> -d DELETE Cancella file json input_json alla fine");
|
||||
bean.save();
|
||||
bean.findByCodice("PATH_ZOO_FACE_RECOGNITION_SCRIPT");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("PATH_ZOO_FACE_RECOGNITION_SCRIPT");
|
||||
bean.setDescrizione("PATH_ZOO_FACE_RECOGNITION_SCRIPT");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/home/sites/fr/admin/_shell/recognizer.sh");
|
||||
bean.setNota("Script completo per recognizer: <br>/home/sites/zoo/admin/_shell/recognizer.sh<br>I parametri sono<br> --input_json INPUT_JSON<br>Path del file JSON di input.\n --output_json OUTPUT_JSON<br>Path del file JSON di output.\n --backend_target BACKEND_TARGET, -bt BACKEND_TARGET<br> -d DELETE Cancella file json input_json alla fine");
|
||||
bean.save();
|
||||
}
|
||||
}
|
||||
|
||||
public Vectumerator<Users> findByCR(UsersCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from USERS AS A";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("dataFineVld is null");
|
||||
wc = managePolicyFind(CR, wc);
|
||||
if (!CR.isCode1())
|
||||
wc.addWc("A.id_users <>1");
|
||||
if (!CR.getFlgValido().isEmpty())
|
||||
wc.addWc("A.flgValido='" + CR.getFlgValido() + "'");
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
String temp = CR.getSearchTxt().trim().replace("*", "%");
|
||||
StringTokenizer st = new StringTokenizer(temp, " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
int countToken = 0;
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = prepareSqlString(st.nextToken());
|
||||
countToken++;
|
||||
if (countToken > 1)
|
||||
token = "%" + token;
|
||||
txt.append("(A.nome like'%" + token + "%' or A.cognome like'%" + token + "%' or A.eMail like'%" + token + "%' or A.codFisc like'%" + token + "%' or A.login like'%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
if (!CR.getEMail().isEmpty())
|
||||
wc.addWc("A.eMail like'%" + CR.getEMail() + "%'");
|
||||
if (CR.getFlgMl() == 0L) {
|
||||
wc.addWc("(A.flgMl is null or A.flgMl=0)");
|
||||
} else if (CR.getFlgMl() > 0L) {
|
||||
wc.addWc("A.flgMl =" + CR.getFlgMl());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (Exception e) {
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package it.acxent.face.fr.zoo;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
|
||||
public class UsersCR extends it.acxent.common.UsersCR {
|
||||
public boolean isCode1() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public UsersCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public UsersCR() {}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.fr.zoo;
|
||||
|
|
@ -0,0 +1,387 @@
|
|||
package it.acxent.face.fr.zoo.rest;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import it.acxent.db.ApplParm;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.api.opencv.TrainingImage;
|
||||
import it.acxent.face.fr.FotoRequest;
|
||||
import it.acxent.face.fr.zoo.Users;
|
||||
import it.acxent.rest._AblRestAdapter;
|
||||
import it.acxent.util.Debug;
|
||||
import it.acxent.util.FileWr;
|
||||
import it.acxent.util.ShellWrapper;
|
||||
import it.acxent.util.Timer;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.face.FaceRecognizer;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
@WebServlet(urlPatterns = {"/facezoo/*"})
|
||||
public class FaceZooRestSvlt extends _AblRestAdapter {
|
||||
private static Debug debugHelper = new Debug();
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
private Cache<String, Object> cache;
|
||||
|
||||
private static final long serialVersionUID = -8266400675249237394L;
|
||||
|
||||
public void __templateChiamata(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
boolean debug = false;
|
||||
String parametroTest = getRequestParameter(req, "id");
|
||||
DBAdapter.printDebug(" parm id: " + parametroTest + " apiParms: " + getApiParms() + " json post: " + getApiJSONObject().toString(4));
|
||||
try {
|
||||
long l_id_user = getRequestLongParameter(req, "id_user");
|
||||
boolean authOk = checkBasicAuth(req, res);
|
||||
if (!authOk)
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello, _elencofoto");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello,_elencofoto eccezione: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void _detectFaces_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
boolean debug = true;
|
||||
Timer timer = null;
|
||||
timer = new Timer();
|
||||
timer.start();
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 1");
|
||||
int MAX_ATTEMPTS = 3;
|
||||
int RETRY_DELAY_MS = 1000;
|
||||
JsonObject jresPy = null;
|
||||
HttpSession oldSession = req.getSession(false);
|
||||
Users user = getUsersByBasicAuth(req, res);
|
||||
StringBuilder err = new StringBuilder();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
FotoRequest fr = new FotoRequest(getApFull());
|
||||
try {
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 2");
|
||||
JsonObject jo = getApiJsonObject();
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 3 *********************");
|
||||
DBAdapter.printDebug(debug, "json in arrivo");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(jo));
|
||||
DBAdapter.printDebug(debug, "*-------------- FINE JSON IN ARRIVO ---------------------------*");
|
||||
String pathBase = getApFull().getParm("path_img_tmp").getTesto();
|
||||
String targetDirJsonData = pathBase + "_json/";
|
||||
File targetDirFile = new File(targetDirJsonData);
|
||||
if (!targetDirFile.exists())
|
||||
targetDirFile.mkdirs();
|
||||
JsonArray jresponses = new JsonArray();
|
||||
int numberOfFaces = 0;
|
||||
boolean cachedFaces = false;
|
||||
JsonObject jsonData = new JsonObject();
|
||||
float confidenceThresold = jo.get("conf_threshold").getAsFloat();
|
||||
jsonData.addProperty("conf_threshold", Float.valueOf(confidenceThresold));
|
||||
long detectionMethod = (long)(100 + (int)(confidenceThresold * 100.0F));
|
||||
HashSet<File> hsFiles = new HashSet<>();
|
||||
JsonArray jQueryA = new JsonArray();
|
||||
JsonArray jRequestsA = jo.getAsJsonArray("requests");
|
||||
for (int i = 0; i < jRequestsA.size(); i++) {
|
||||
JsonObject jRequest = jRequestsA.get(i).getAsJsonObject();
|
||||
String imageContent = null, imagePath = null;
|
||||
boolean hasImage = false;
|
||||
if (jRequest.has("path")) {
|
||||
imagePath = jRequest.get("path").getAsString();
|
||||
} else {
|
||||
hasImage = true;
|
||||
JsonObject imageObject = jRequest.getAsJsonObject("image");
|
||||
imageContent = imageObject.get("content").getAsString();
|
||||
}
|
||||
String md5 = jRequest.get("md5").getAsString();
|
||||
if (oldSession != null) {
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 1.2.1 session id: " +
|
||||
req.getSession().getId() + " i: " + i + " md5: " + md5);
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 1.2.2 session id inesistente md5: " + md5);
|
||||
}
|
||||
long l_requestType = 1L;
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 4 findByUserMd5DetectionmethodRequesttype *********************");
|
||||
DBAdapter.printDebug(debug, "md5: " + md5);
|
||||
fr.findByUserMd5DetectionmethodRequesttype(user.getId_users(), md5, detectionMethod, l_requestType);
|
||||
String dbJson = fr.getJson();
|
||||
if (!dbJson.isEmpty()) {
|
||||
JsonObject jresponse = JsonParser.parseString(dbJson).getAsJsonObject();
|
||||
jresponses.add((JsonElement)jresponse);
|
||||
fr.addRichiesta();
|
||||
fr.save();
|
||||
cachedFaces = true;
|
||||
DBAdapter.printDebug("************ _detectFaces_POST 5 findByUserMd5DetectionmethodRequesttype OK *********************");
|
||||
DBAdapter.printDebug(debug, "md5: " + md5);
|
||||
JsonObject jsonObject = JsonParser.parseString(fr.getJson()).getAsJsonObject();
|
||||
DBAdapter.printDebug(debug, "json sul db" + DBAdapter.gsonToString(jsonObject));
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 6 PREPARO RICHIESTA PHYTON *********************");
|
||||
DBAdapter.printDebug(debug, "md5: " + md5);
|
||||
JsonObject jQueryRow = new JsonObject();
|
||||
jQueryRow.addProperty("md5", md5);
|
||||
if (hasImage) {
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(imageContent);
|
||||
String currentImage = pathBase + pathBase + ".jpg";
|
||||
File file = new File(currentImage);
|
||||
if (!file.exists()) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(decodedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
jQueryRow.addProperty("path", currentImage);
|
||||
hsFiles.add(file);
|
||||
} else {
|
||||
jQueryRow.addProperty("path", imagePath);
|
||||
}
|
||||
jQueryA.add((JsonElement)jQueryRow);
|
||||
}
|
||||
}
|
||||
if (jQueryA.size() > 0) {
|
||||
jsonData.add("query", (JsonElement)jQueryA);
|
||||
DBAdapter.printDebug(debug, "_detectFaces_POST jsonData:\n" + DBAdapter.gsonToString(jsonData));
|
||||
String rndName = getTimeNameForFileUpload();
|
||||
String json_data_path = targetDirJsonData + "jDataDetect_" + targetDirJsonData + ".json";
|
||||
String json_res_path = targetDirJsonData + "jDataDetect_" + targetDirJsonData + "_res.json";
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 7 writing json *********************");
|
||||
DBAdapter.printDebug(debug, "json_data_path: " + json_data_path);
|
||||
jsonData.addProperty("debug", "FaceZooRest._detectFaces_POST");
|
||||
FileWr fw = new FileWr(json_data_path, false);
|
||||
fw.writeLine(DBAdapter.gsonToString(jsonData));
|
||||
fw.closeFile();
|
||||
List<String> pythonScript = Arrays.asList(getParm("PATH_ZOO_FACE_DETECTION_SCRIPT").getTesto(), "--input_json", json_data_path, "--output_json", json_res_path);
|
||||
for (int attempt = 1; attempt <= 3; attempt++) {
|
||||
String result = ShellWrapper.executeShellScript(pythonScript);
|
||||
jresPy = DBAdapter.tryParseJsonObject(result);
|
||||
if (jresPy != null)
|
||||
break;
|
||||
if (attempt < 3)
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (jresPy == null)
|
||||
throw new RuntimeException("Errore: impossibile ottenere un JSON valido dopo 3 tentativi");
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 8 RISPOSTA SCRIPT PYTHON *********************");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(jresPy));
|
||||
JsonArray jresponsesPy = jresPy.getAsJsonArray("responses");
|
||||
for (int j = 0; j < jresponsesPy.size(); j++) {
|
||||
JsonObject jresponsePy = jresponsesPy.get(j).getAsJsonObject();
|
||||
jresponses.add((JsonElement)jresponsePy);
|
||||
String md5 = jresponsePy.getAsJsonObject("response").get("md5")
|
||||
.getAsString();
|
||||
if (user.getId_users() > 0L) {
|
||||
fr.setId_users(user.getId_users());
|
||||
fr.setJson(jresponsePy.toString());
|
||||
fr.setMd5(md5);
|
||||
fr.setFaceDetectionMethodCode(detectionMethod);
|
||||
fr.setFlgRequestType(1L);
|
||||
fr.addRichiesta();
|
||||
fr.save();
|
||||
}
|
||||
}
|
||||
for (File elemento : hsFiles)
|
||||
elemento.delete();
|
||||
}
|
||||
JsonObject joRes = new JsonObject();
|
||||
if (errMsg.length() == 0) {
|
||||
String target = "vertices";
|
||||
numberOfFaces = DBAdapter.countOccurrences(jresponses.toString(), target);
|
||||
joRes.addProperty("success", "true");
|
||||
joRes.addProperty("msg", "Trovate in totale " + numberOfFaces + " visi su " +
|
||||
jresponses.size() + " foto. FaceCached?" + cachedFaces + " : " + msg.toString());
|
||||
joRes.add("responses", (JsonElement)jresponses);
|
||||
} else {
|
||||
joRes.addProperty("success", "false");
|
||||
joRes.addProperty("msg", "Errore! " + err.toString());
|
||||
}
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST 9 RISPOSTA AL CLIENT *********************");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(joRes));
|
||||
DBAdapter.printDebug(debug, "*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
timer.stop();
|
||||
DBAdapter.printDebug(debug, " _detectFaces_POST. Resp size: Trovate in totale " + numberOfFaces + " visi su " +
|
||||
jresponses.size() + " foto. FaceCached?" + cachedFaces + " ms " + timer.getDurataMilliSec());
|
||||
} catch (RuntimeException e) {
|
||||
JsonObject joRes = new JsonObject();
|
||||
joRes.addProperty("success", "false");
|
||||
joRes.addProperty("msg", "Eccezione!! " + e.getMessage());
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST ECCEZIONE RUNTIME!!!! RISPOSTA AL CLIENT *********************");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(joRes));
|
||||
DBAdapter.printDebug(debug, "*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, DBAdapter.gsonToString(joRes));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JsonObject joRes = new JsonObject();
|
||||
joRes.addProperty("success", "false");
|
||||
joRes.addProperty("msg", "Eccezione!! " + e.getMessage());
|
||||
DBAdapter.printDebug(debug, "************ _detectFaces_POST ECCEZIONE!!!! RISPOSTA AL CLIENT *********************");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(joRes));
|
||||
DBAdapter.printDebug(debug, "*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, DBAdapter.gsonToString(joRes));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String hostname = "localhost";
|
||||
String db = "cc";
|
||||
ApplParmFull ap = new ApplParmFull(new ApplParm(14, "//" + hostname + ":1433;databaseName=" + db + ";user=sa;password=T3st000!", null, null, 1, 10, 300));
|
||||
}
|
||||
|
||||
protected boolean checkBasicAuth(HttpServletRequest req, HttpServletResponse res) {
|
||||
boolean authOk = false;
|
||||
try {
|
||||
String[] auth = getBasicAuthorizationHeaders(req, res);
|
||||
if (auth != null) {
|
||||
Users bean = getUsersByBasicAuth(req, res);
|
||||
if (bean.getDBState() == 1) {
|
||||
authOk = true;
|
||||
} else {
|
||||
DBAdapter.printDebug(false, "FaceRestSvlt.checkBasicAuth KO: login-->" + auth[0] + " pwd-->" + auth[1]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return authOk;
|
||||
}
|
||||
|
||||
protected String getApiBaseUrl() {
|
||||
return "/fr/face/";
|
||||
}
|
||||
|
||||
protected Users getUsersByBasicAuth(HttpServletRequest req, HttpServletResponse res) {
|
||||
String[] auth = getBasicAuthorizationHeaders(req, res);
|
||||
Users bean = new Users(getApFull());
|
||||
if (auth != null)
|
||||
bean.findLogonUtente(auth[0], auth[1], req.getRemoteAddr());
|
||||
return bean;
|
||||
}
|
||||
|
||||
private ResParm trainingCreate(String l_sessionId, List<TrainingImage> trainingImages, int recognizerType) {
|
||||
ResParm rp = new ResParm();
|
||||
FaceRecognizer ocvFr = (FaceRecognizer)getCache()
|
||||
.getIfPresent(l_sessionId + "_" + l_sessionId);
|
||||
int counter = 0;
|
||||
String counterKey = l_sessionId + "_" + l_sessionId + "_counter";
|
||||
Integer Icounter = (Integer)getCache().getIfPresent(counterKey);
|
||||
if (Icounter != null)
|
||||
counter = Icounter;
|
||||
DBAdapter.printDebug(false, "trainingCreate " + trainingImages.size() + " immagini");
|
||||
if (trainingImages.size() > 0) {
|
||||
Mat labels = new Mat(trainingImages.size(), 1, CvType.CV_32SC1);
|
||||
MatOfInt labelsMat = new MatOfInt();
|
||||
List<Mat> trainingImagesMat = new ArrayList<>();
|
||||
for (TrainingImage trainingImage : trainingImages) {
|
||||
File imageFile = new File(trainingImage.getImageFileName());
|
||||
Mat image = Imgcodecs.imread(imageFile.getAbsolutePath());
|
||||
Mat grayImage = new Mat();
|
||||
Imgproc.cvtColor(image, grayImage, 6);
|
||||
trainingImagesMat.add(grayImage);
|
||||
labels.put(counter, 0, new double[] { (double)trainingImage.getLabel() });
|
||||
DBAdapter.printDebug("train: " +
|
||||
trainingImage.getImageFileName() + " count:" + counter + " label: " + trainingImage.getLabel());
|
||||
counter++;
|
||||
}
|
||||
labels.convertTo((Mat)labelsMat, CvType.CV_32SC1);
|
||||
ocvFr.train(trainingImagesMat, labels);
|
||||
getCache().put(counterKey, Integer.valueOf(counter));
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
private Cache<String, Object> getCache() {
|
||||
if (this.cache == null)
|
||||
this.cache = CacheBuilder.newBuilder().maximumSize(100L).expireAfterAccess(100L, TimeUnit.MINUTES).build();
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
public void _scoring_POST(HttpServletRequest req, HttpServletResponse res) {
|
||||
boolean debug = false;
|
||||
boolean debug2 = false;
|
||||
Timer timer = null;
|
||||
timer = new Timer();
|
||||
timer.start();
|
||||
String result = "";
|
||||
String json_data_path = null;
|
||||
String json_res_path = null;
|
||||
try {
|
||||
List<String> pythonScript;
|
||||
JsonObject jo = getApiJsonObject();
|
||||
DBAdapter.printDebug(debug, "************ _scoringZoo_POST *********************");
|
||||
DBAdapter.printDebug(debug, "json in arrivo");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(jo));
|
||||
DBAdapter.printDebug(debug, "*-------------- FINE ---------------------------*");
|
||||
JsonObject joRes = new JsonObject();
|
||||
json_data_path = jo.get("json_data_path").getAsString();
|
||||
json_res_path = jo.get("json_res_path").getAsString();
|
||||
if (debug || debug2) {
|
||||
pythonScript = Arrays.asList(getParm("PATH_ZOO_FACE_RECOGNITION_SCRIPT").getTesto(), "--input_json", json_data_path, "--output_json", json_res_path, "-d");
|
||||
} else {
|
||||
pythonScript = Arrays.asList(getParm("PATH_ZOO_FACE_RECOGNITION_SCRIPT").getTesto(), "--input_json", json_data_path, "-d");
|
||||
}
|
||||
result = ShellWrapper.executeShellScript(pythonScript);
|
||||
DBAdapter.printDebug(debug, " RESULT from SCRIPT PY: " + String.valueOf(pythonScript) + ":\n" + result);
|
||||
DBAdapter.printDebug(debug, "\n--------------------------");
|
||||
joRes = JsonParser.parseString(result.trim()).getAsJsonObject();
|
||||
DBAdapter.printDebug(debug, "************ _scoringZoo_POST RISPOSTA AL CLIENT *********************");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(joRes));
|
||||
timer.stop();
|
||||
int numResponses = -1;
|
||||
if (joRes.has("responses"))
|
||||
numResponses = joRes.getAsJsonArray("responses").size();
|
||||
DBAdapter.printDebug(debug, " _scoringZoo_POST.. Resp size: " + numResponses + " ms " + timer.getDurataMilliSec() + " json_data_path: " + json_data_path);
|
||||
sendJsonMsgResponse(req, res, joRes.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JsonObject joRes = new JsonObject();
|
||||
joRes.addProperty("success", "false");
|
||||
joRes.addProperty("msg", "Ritorno: " + result + "\nEccezione!! " + e.getMessage());
|
||||
DBAdapter.printDebug(debug, "************ _scoringZoo_POST ECCEZIONE!!!! json_data_path: " + json_data_path + "\nRISPOSTA AL CLIENT *********************");
|
||||
DBAdapter.printDebug(DBAdapter.gsonToString(joRes));
|
||||
DBAdapter.printDebug(debug, "*-------------- FINE ---------------------------*");
|
||||
sendJsonMsgResponse(req, res, DBAdapter.gsonToString(joRes));
|
||||
}
|
||||
}
|
||||
|
||||
protected Class<? extends _AblRestAdapter> getConcreteApiClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.fr.zoo.rest;
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face;
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SaveScoreProcessor {
|
||||
private static boolean debug = true;
|
||||
|
||||
private static SaveScoreProcessor instance;
|
||||
|
||||
private final BlockingQueue<SaveScoreTask> taskQueue;
|
||||
|
||||
private final ExecutorService executor;
|
||||
|
||||
private int activeConsumers = 0;
|
||||
|
||||
private static ApplParmFull ap;
|
||||
|
||||
private static int numThreads = 10;
|
||||
|
||||
public static final String TAG_THREAD_MSG = "SAVE_SCORE_TASK";
|
||||
|
||||
private static final int QUEUE_CAPACITY = 200;
|
||||
|
||||
private SaveScoreProcessor(int numThreads) {
|
||||
this.taskQueue = new ArrayBlockingQueue<>(200);
|
||||
this.executor = new ThreadPoolExecutor(numThreads, numThreads, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(200), new ThreadPoolExecutor.AbortPolicy());
|
||||
for (int i = 0; i < numThreads; i++)
|
||||
this.executor.submit(new SaveScoreTask(this.taskQueue, null, null));
|
||||
}
|
||||
|
||||
public static synchronized SaveScoreProcessor getInstance(ApplParmFull l_ap, int numThreads) {
|
||||
ap = l_ap;
|
||||
SaveScoreProcessor.numThreads = numThreads;
|
||||
if (instance == null)
|
||||
instance = new SaveScoreProcessor(numThreads);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static synchronized SaveScoreProcessor getInstance(ApplParmFull l_ap) {
|
||||
ap = l_ap;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public synchronized void aggiungiInCoda(ApplParmFull ap, JsonObject jo) {
|
||||
try {
|
||||
if (!this.taskQueue.offer(new SaveScoreTask(this.taskQueue, ap, jo), 1L, TimeUnit.SECONDS)) {
|
||||
DBAdapter.printDebug(debug, "Coda piena, impossibile aggiungere il task.");
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "Task aggiunto alla coda.");
|
||||
if (this.activeConsumers < numThreads) {
|
||||
DBAdapter.printDebug(debug, "Avvio di un nuovo thread consumer. Consumer attivi: " + this.activeConsumers);
|
||||
this.executor.submit(new SaveScoreTask(this.taskQueue, null, null));
|
||||
this.activeConsumers++;
|
||||
}
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", "AggiungiInCoda. activeConsumers: " + this.activeConsumers + " " +
|
||||
getInstance(ap).getDescProcess());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
DBAdapter.printDebug(debug, "Errore durante l'aggiunta alla coda: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Thread.currentThread().interrupt();
|
||||
DBAdapter.printDebug(debug, "Errore durante l'aggiunta alla coda: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.executor.shutdown();
|
||||
try {
|
||||
if (!this.executor.awaitTermination(60L, TimeUnit.SECONDS)) {
|
||||
DBAdapter.printDebug(debug, "Forzando l'arresto dei thread...");
|
||||
this.executor.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
this.executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
instance = null;
|
||||
DBAdapter.printDebug(debug, "SaveScoreProcessor è stato arrestato e l'istanza è stata resettata.");
|
||||
}
|
||||
|
||||
public final int getQueueSize() {
|
||||
return this.taskQueue.size();
|
||||
}
|
||||
|
||||
public boolean isIdle() {
|
||||
if (this.executor == null)
|
||||
return false;
|
||||
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor)this.executor;
|
||||
return (this.taskQueue.isEmpty() && threadPoolExecutor.getActiveCount() == 0);
|
||||
}
|
||||
|
||||
public String getDescProcess() {
|
||||
if (this.executor == null)
|
||||
return "Executor non attivo";
|
||||
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor)this.executor;
|
||||
return "Active thread: " + threadPoolExecutor.getActiveCount() + " task queue len: " + this.taskQueue.size();
|
||||
}
|
||||
|
||||
public synchronized void decrementActiveConsumers() {
|
||||
if (this.activeConsumers > 0)
|
||||
this.activeConsumers--;
|
||||
DBAdapter.printDebug(debug, "Consumer attivi decrementati: " + this.activeConsumers);
|
||||
if (this.activeConsumers > 0)
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", "Consumer attivi decrementati: " + this.activeConsumers + " " +
|
||||
getInstance(ap).getDescProcess());
|
||||
}
|
||||
|
||||
public synchronized int getActiveConsumers() {
|
||||
return this.activeConsumers;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
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.FaceScoreZoo;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
public class SaveScoreTask implements Runnable {
|
||||
private static boolean debug = true;
|
||||
|
||||
private final JsonObject jo;
|
||||
|
||||
private final ApplParmFull ap;
|
||||
|
||||
private final BlockingQueue<SaveScoreTask> queue;
|
||||
|
||||
public JsonObject getJsonObject() {
|
||||
return this.jo;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
String tag = DBAdapter.getTimeNameForFileUpload() + " ";
|
||||
SaveScoreTask sst = this.queue.take();
|
||||
StatusMsg.updateMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK", tag + "Elaborazione iniziata per task saveScoreResponse. " + tag);
|
||||
DBAdapter.printDebug(debug, "Elaborazione iniziata per task: " + SaveScoreProcessor.getInstance(this.ap).getDescProcess());
|
||||
FaceScoreZoo fsz = new FaceScoreZoo(sst.getApplParmFull());
|
||||
ResParm rp = fsz.saveScoreResponse(sst.getJsonObject());
|
||||
StatusMsg.updateMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK", tag + "Elaborazione conclusa per task saveScoreResponse. qs: " + tag);
|
||||
Evento.inviaNotificaRemotaWww(getApplParmFull(), 0L);
|
||||
synchronized (SaveScoreProcessor.class) {
|
||||
SaveScoreProcessor.getInstance(this.ap).decrementActiveConsumers();
|
||||
}
|
||||
if (SaveScoreProcessor.getInstance(this.ap).isIdle())
|
||||
StatusMsg.deleteMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.err.println("SaveScoreTask interrotto: " + e.getMessage());
|
||||
} finally {
|
||||
synchronized (SaveScoreProcessor.class) {
|
||||
SaveScoreProcessor.getInstance(this.ap).decrementActiveConsumers();
|
||||
}
|
||||
if (SaveScoreProcessor.getInstance(this.ap).isIdle())
|
||||
StatusMsg.deleteMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK");
|
||||
}
|
||||
}
|
||||
|
||||
public SaveScoreTask(BlockingQueue<SaveScoreTask> queue, ApplParmFull ap, JsonObject jo) {
|
||||
this.queue = queue;
|
||||
this.jo = jo;
|
||||
this.ap = ap;
|
||||
}
|
||||
|
||||
public ApplParmFull getApplParmFull() {
|
||||
return this.ap;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.FaceScoreZoo;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
@Deprecated
|
||||
public class SaveScoreWorker implements Runnable {
|
||||
private static boolean debug = true;
|
||||
|
||||
private final BlockingQueue<SaveScoreTask> queue;
|
||||
|
||||
private static ApplParmFull ap;
|
||||
|
||||
public SaveScoreWorker(ApplParmFull l_ap, BlockingQueue<SaveScoreTask> queue) {
|
||||
ap = l_ap;
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
String tag = DBAdapter.getTimeNameForFileUpload() + " ";
|
||||
SaveScoreTask sst = this.queue.take();
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", tag + "Elaborazione iniziata per task saveScoreResponse. qs: " + tag);
|
||||
DBAdapter.printDebug(debug, "Elaborazione iniziata per task: ");
|
||||
FaceScoreZoo fsz = new FaceScoreZoo(sst.getApplParmFull());
|
||||
ResParm rp = fsz.saveScoreResponse(sst.getJsonObject());
|
||||
if (SaveScoreProcessor.getInstance(ap, 30).getQueueSize() > 1) {
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", tag + "Elaborazione conclusa per task saveScoreResponse. qs: " + tag);
|
||||
continue;
|
||||
}
|
||||
StatusMsg.deleteMsgByTag(ap, "SAVE_SCORE_TASK");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.err.println("SelfieWorker interrotto: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue