add change face to another person
This commit is contained in:
parent
8a747a5982
commit
73a921e175
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DirectoryScanner implements Runnable {
|
public class DirectoryScanner implements Runnable {
|
||||||
private WorkspaceService workspaceService = WorkspaceService.getInstance();
|
private WorkspaceService workspaceService = WorkspaceService.getInstance();
|
||||||
@ -82,11 +83,29 @@ public class DirectoryScanner implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isImagePath(String filename) {
|
private boolean isImagePath(String filename) {
|
||||||
switch (filename.substring(filename.length() - 3).toLowerCase()) {
|
List<String> whiteListExtension = new ArrayList<String>();
|
||||||
case "jpg":
|
whiteListExtension.add("jpg");
|
||||||
|
whiteListExtension.add("jpeg");
|
||||||
|
whiteListExtension.add("png");
|
||||||
|
|
||||||
|
for (String extension: whiteListExtension) {
|
||||||
|
var fileExtension = filename.substring(filename.length() - extension.length());
|
||||||
|
|
||||||
|
if (fileExtension.toLowerCase().equals(extension)){
|
||||||
return true;
|
return true;
|
||||||
default:
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// filename.endsWith("jpeg");
|
||||||
|
//
|
||||||
|
// switch (filename.substring(filename.length() - 3).toLowerCase()) {
|
||||||
|
// case "jpeg":
|
||||||
|
// case "jpg":
|
||||||
|
// return true;
|
||||||
|
// default:
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,10 @@ import dev.mateuszkowalczyk.ffm.app.exception.NotFoundException;
|
|||||||
import dev.mateuszkowalczyk.ffm.data.database.face.Face;
|
import dev.mateuszkowalczyk.ffm.data.database.face.Face;
|
||||||
import dev.mateuszkowalczyk.ffm.data.database.face.FaceDAO;
|
import dev.mateuszkowalczyk.ffm.data.database.face.FaceDAO;
|
||||||
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
||||||
|
import dev.mateuszkowalczyk.ffm.data.database.person.PersonDAO;
|
||||||
import dev.mateuszkowalczyk.ffm.utils.ResourceLoader;
|
import dev.mateuszkowalczyk.ffm.utils.ResourceLoader;
|
||||||
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
||||||
|
import dev.mateuszkowalczyk.ffm.view.workspace.elements.ElementsEnum;
|
||||||
import dev.mateuszkowalczyk.ffm.view.workspace.elements.FaceContainerController;
|
import dev.mateuszkowalczyk.ffm.view.workspace.elements.FaceContainerController;
|
||||||
import dev.mateuszkowalczyk.ffm.view.workspace.elements.FacePaneController;
|
import dev.mateuszkowalczyk.ffm.view.workspace.elements.FacePaneController;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
@ -22,6 +24,7 @@ public class FaceWorkspace {
|
|||||||
|
|
||||||
public void loadFacesForPerson(MainPageController mainPageController, FaceContainerController faceContainerController, Person person) throws NotFoundException {
|
public void loadFacesForPerson(MainPageController mainPageController, FaceContainerController faceContainerController, Person person) throws NotFoundException {
|
||||||
List<Face> faceList = FaceDAO.getInstance().getAllForPerson(person);
|
List<Face> faceList = FaceDAO.getInstance().getAllForPerson(person);
|
||||||
|
List<Person> personList = PersonDAO.getInstance().getAll(true);
|
||||||
var resourceLoader = ResourceLoader.getInstance();
|
var resourceLoader = ResourceLoader.getInstance();
|
||||||
|
|
||||||
if (faceList.size() == 0) {
|
if (faceList.size() == 0) {
|
||||||
@ -31,7 +34,9 @@ public class FaceWorkspace {
|
|||||||
for (Face face : faceList) {
|
for (Face face : faceList) {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader();
|
FXMLLoader fxmlLoader = new FXMLLoader();
|
||||||
fxmlLoader.setLocation(resourceLoader.getResource("templates/workspace/elements/face_pane.fxml"));
|
fxmlLoader.setLocation(resourceLoader.getResource("templates/workspace/elements/face_pane.fxml"));
|
||||||
fxmlLoader.setController(new FacePaneController(mainPageController, faceContainerController, face));
|
var controller = new FacePaneController(mainPageController, faceContainerController, face);
|
||||||
|
controller.setPersonList(personList);
|
||||||
|
fxmlLoader.setController(controller);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
faceContainerController.addFacePane(fxmlLoader.load());
|
faceContainerController.addFacePane(fxmlLoader.load());
|
||||||
|
@ -89,7 +89,18 @@ public class FaceDAO implements Dao<Face> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Face face) {
|
public void update(Face face) {
|
||||||
|
String sql = "UPDATE face set personId = ? WHERE id = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement preparedStatement = this.databaseService.getConnection().prepareStatement(sql);
|
||||||
|
preparedStatement.setLong(1, face.getPersonId());
|
||||||
|
preparedStatement.setLong(2, face.getId());
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
this.getAll(true);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,7 +82,20 @@ public class PersonDAO implements Dao<Person> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Person person) {
|
public void update(Person person) {
|
||||||
|
String sql = "UPDATE persons SET name = ? WHERE id = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement preparedStatement = this.databaseService.getConnection().prepareStatement(sql);
|
||||||
|
preparedStatement.setString(1, person.getName());
|
||||||
|
preparedStatement.setLong(2, person.getId());
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
|
this.getAll(true);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,8 +16,8 @@ public class FaceRecognition {
|
|||||||
private FaceDAO faceDAO = FaceDAO.getInstance();
|
private FaceDAO faceDAO = FaceDAO.getInstance();
|
||||||
|
|
||||||
public void recognize(Face faceToRecognize) {
|
public void recognize(Face faceToRecognize) {
|
||||||
List<Face> faceList = faceDAO.getAll();
|
List<Face> faceList = faceDAO.getAll(true);
|
||||||
List<Person> personList = personDAO.getAll();
|
List<Person> personList = personDAO.getAll(true);
|
||||||
ArrayList<Mat> facesImages = new ArrayList<>();
|
ArrayList<Mat> facesImages = new ArrayList<>();
|
||||||
ArrayList<Integer> faceImagesIndex = new ArrayList<>();
|
ArrayList<Integer> faceImagesIndex = new ArrayList<>();
|
||||||
Person person;
|
Person person;
|
||||||
|
@ -22,9 +22,9 @@ public class ThumbnailService {
|
|||||||
|
|
||||||
float divider;
|
float divider;
|
||||||
if (originalImage.getWidth() > originalImage.getHeight()) {
|
if (originalImage.getWidth() > originalImage.getHeight()) {
|
||||||
divider = originalImage.getWidth() / 200;
|
divider = (float) originalImage.getWidth() / (float) 200;
|
||||||
} else {
|
} else {
|
||||||
divider = originalImage.getHeight() / 200;
|
divider = (float) originalImage.getHeight() / (float) 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = (int) (originalImage.getWidth() / divider);
|
int width = (int) (originalImage.getWidth() / divider);
|
||||||
|
@ -2,13 +2,14 @@ package dev.mateuszkowalczyk.ffm.view.workspace.elements;
|
|||||||
|
|
||||||
import dev.mateuszkowalczyk.ffm.app.exception.NotFoundException;
|
import dev.mateuszkowalczyk.ffm.app.exception.NotFoundException;
|
||||||
import dev.mateuszkowalczyk.ffm.app.face.FaceWorkspace;
|
import dev.mateuszkowalczyk.ffm.app.face.FaceWorkspace;
|
||||||
import dev.mateuszkowalczyk.ffm.data.database.face.FaceDAO;
|
|
||||||
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
||||||
import dev.mateuszkowalczyk.ffm.data.database.person.PersonDAO;
|
import dev.mateuszkowalczyk.ffm.data.database.person.PersonDAO;
|
||||||
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
||||||
|
import javafx.event.Event;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.FlowPane;
|
import javafx.scene.layout.FlowPane;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -21,6 +22,9 @@ public class FaceContainerController implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private FlowPane facesContainer;
|
private FlowPane facesContainer;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField personName;
|
||||||
|
|
||||||
public FaceContainerController(MainPageController mainPageController, Person person) {
|
public FaceContainerController(MainPageController mainPageController, Person person) {
|
||||||
this.mainPageController = mainPageController;
|
this.mainPageController = mainPageController;
|
||||||
this.person = person;
|
this.person = person;
|
||||||
@ -34,6 +38,13 @@ public class FaceContainerController implements Initializable {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
this.personName.setText(person.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePersonName(Event event) {
|
||||||
|
this.person.setName(this.personName.getText());
|
||||||
|
|
||||||
|
PersonDAO.getInstance().update(person);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
|
@ -1,25 +1,41 @@
|
|||||||
package dev.mateuszkowalczyk.ffm.view.workspace.elements;
|
package dev.mateuszkowalczyk.ffm.view.workspace.elements;
|
||||||
|
|
||||||
|
import dev.mateuszkowalczyk.ffm.app.face.FaceWorkspace;
|
||||||
import dev.mateuszkowalczyk.ffm.data.database.face.Face;
|
import dev.mateuszkowalczyk.ffm.data.database.face.Face;
|
||||||
import dev.mateuszkowalczyk.ffm.data.database.face.FaceDAO;
|
import dev.mateuszkowalczyk.ffm.data.database.face.FaceDAO;
|
||||||
|
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
||||||
|
import dev.mateuszkowalczyk.ffm.data.database.person.PersonDAO;
|
||||||
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.ChoiceBox;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class FacePaneController implements Initializable {
|
public class FacePaneController implements Initializable {
|
||||||
private MainPageController mainPageController;
|
private MainPageController mainPageController;
|
||||||
private FaceContainerController faceContainerController;
|
private FaceContainerController faceContainerController;
|
||||||
|
private FaceWorkspace faceWorkspace = FaceWorkspace.getInstance();
|
||||||
private Face face;
|
private Face face;
|
||||||
|
private ObservableList<String> list = FXCollections.observableArrayList();
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ImageView faceImage;
|
private ImageView faceImage;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ChoiceBox<String> choicePerson;
|
||||||
|
|
||||||
|
private List<Person> personList;
|
||||||
|
|
||||||
public FacePaneController(MainPageController mainPageController, FaceContainerController faceContainerController, Face face) {
|
public FacePaneController(MainPageController mainPageController, FaceContainerController faceContainerController, Face face) {
|
||||||
|
|
||||||
this.mainPageController = mainPageController;
|
this.mainPageController = mainPageController;
|
||||||
@ -32,13 +48,47 @@ public class FacePaneController implements Initializable {
|
|||||||
this.faceContainerController.refresh();
|
this.faceContainerController.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void markAsNewPerson(Event event) {
|
||||||
|
Person person = new Person();
|
||||||
|
PersonDAO.getInstance().add(person);
|
||||||
|
|
||||||
|
this.changePerson(person, this.face);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changePerson(Person person, Face face) {
|
||||||
|
face.setPersonId(person.getId());
|
||||||
|
FaceDAO.getInstance().update(face);
|
||||||
|
PersonDAO.getInstance().getAll(true);
|
||||||
|
|
||||||
|
this.faceContainerController.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
this.loadFace();
|
this.loadFace();
|
||||||
|
this.setChoiceBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChoiceBox() {
|
||||||
|
for (Person person: this.personList) {
|
||||||
|
this.list.add(person.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.choicePerson.setItems(this.list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadFace() {
|
private void loadFace() {
|
||||||
Image image = new Image("file:" + this.face.getPath());
|
Image image = new Image("file:" + this.face.getPath());
|
||||||
this.faceImage.setImage(image);
|
this.faceImage.setImage(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPersonList(List<Person> personList) {
|
||||||
|
this.personList = personList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePersonToFace(Event event) {
|
||||||
|
var selectedPerson = personList.get(list.indexOf(this.choicePerson.getValue()));
|
||||||
|
|
||||||
|
this.changePerson(selectedPerson, this.face);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.control.ToolBar?>
|
||||||
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
<?import javafx.scene.layout.FlowPane?>
|
<?import javafx.scene.layout.FlowPane?>
|
||||||
|
|
||||||
|
<BorderPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<FlowPane fx:id="facesContainer" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" />
|
<center>
|
||||||
|
<FlowPane fx:id="facesContainer" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" />
|
||||||
|
</center>
|
||||||
|
<top>
|
||||||
|
<ToolBar prefHeight="40.0" prefWidth="3485.0" BorderPane.alignment="CENTER">
|
||||||
|
<items>
|
||||||
|
<TextField fx:id="personName" />
|
||||||
|
<Button mnemonicParsing="false" onAction="#updatePersonName" text="Button" />
|
||||||
|
</items>
|
||||||
|
</ToolBar>
|
||||||
|
</top>
|
||||||
|
</BorderPane>
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.ChoiceBox?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.image.ImageView?>
|
<?import javafx.scene.image.ImageView?>
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
<?import javafx.scene.layout.Pane?>
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
|
||||||
|
|
||||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<children>
|
<children>
|
||||||
<Pane layoutX="27.0" layoutY="25.0" prefHeight="200.0" prefWidth="200.0" style="-fx-border-color: grey;">
|
<Pane layoutX="27.0" layoutY="25.0" prefHeight="200.0" prefWidth="200.0" style="-fx-border-color: grey;">
|
||||||
@ -14,5 +15,9 @@
|
|||||||
</children>
|
</children>
|
||||||
</Pane>
|
</Pane>
|
||||||
<Button layoutX="309.0" layoutY="197.0" mnemonicParsing="false" onAction="#removeThis" text="This is not a face" />
|
<Button layoutX="309.0" layoutY="197.0" mnemonicParsing="false" onAction="#removeThis" text="This is not a face" />
|
||||||
|
<Button layoutX="323.0" layoutY="25.0" mnemonicParsing="false" onAction="#markAsNewPerson" text="New person" />
|
||||||
|
<ChoiceBox fx:id="choicePerson" layoutX="248.0" layoutY="76.0" prefWidth="150.0" />
|
||||||
|
<Label layoutX="322.0" layoutY="58.0" text="Change person" />
|
||||||
|
<Button layoutX="405.0" layoutY="76.0" mnemonicParsing="false" onAction="#writePersonToFace" text="change" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
Loading…
Reference in New Issue
Block a user