I'm doing a facial recognition system, and all that's missing is for me to finish everything. I have the following code:
for (int i = 0; i < facesDetectadas.size(); i++) {
Rect dadosFace = facesDetectadas.get(i);
rectangle(imagemCamera, dadosFace, new Scalar(255, 255, 0, 0), 2, i, i);
Mat faceCapturada = new Mat(imagemCinza, dadosFace);
opencv_imgproc.resize(faceCapturada, faceCapturada, new Size(160, 160));
IntPointer rotulo = new IntPointer(1);
DoublePointer confianca = new DoublePointer(1);
reconhecedor.predict(faceCapturada, rotulo, confianca);
int predicao = rotulo.get(0);
String nome;
if (predicao == -1) {
nome = "Desconhecido";
} else {
nome = pessoas[predicao] + " - " + confianca.get(0);
campoid.setText(String.valueOf(predicao));
rec();
}
int x = Math.max(dadosFace.tl().x() - 10, 0);
int y = Math.max(dadosFace.tl().y() - 10, 0);
putText(imagemCamera, nome, new Point(x, y), FONT_HERSHEY_PLAIN, 1.7, new Scalar(0, 255, 0, 2));
}
And above, I have in the "rec" method I have the same array:
Follow the rec method:
private void rec() {
SwingWorker worker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
conecta.conexao();
try {
String SQL = "SELECT * FROM reconhecer where id=" + campoid.getText() + "";
conecta.executaSQL(SQL);
while (conecta.rs.next()) {
camponome.setText(conecta.rs.getString(1));
campoidade.setText(conecta.rs.getString(2));
campoemail.setText(conecta.rs.getString(3));
campobloco.setText(conecta.rs.getString(5));
campoapto.setText(conecta.rs.getString(6));
campocondominio.setText(conecta.rs.getString(7));
System.out.println("Pessoa idêntificada como: " + conecta.rs.getString(1));
System.out.println("---------------");
Array identificacao = conecta.rs.getArray(2);
String[] pessoas = (String[]) identificacao.getArray();
for (int i = 0; i < pessoas.length; i++) {
System.out.println(pessoas[i]);
}
System.out.println("");
}
} catch (Exception ex) {
}
conecta.desconecta();
return null;
}
};
worker.execute();
}
Reason for doing this separately: I made a swing worker, and this makes it easy not to crash the application.
My problem and my question: My pessoas
where if
is, does not recognize pessoas
that is in rec
, how can I make pessoas
visible to everything? I tried to use global but it does not work either.