Add saving detected image
This commit is contained in:
parent
9be0aed2da
commit
2c7b2cb4c4
@ -26,6 +26,7 @@ public class CacheStructureChecker {
|
||||
private void setupPathsToCheck() {
|
||||
this.listToCheck.add(this.path);
|
||||
this.listToCheck.add(this.path + ThumbnailCacheService.DIRECTORY_NAME);
|
||||
this.listToCheck.add(this.path + FacesCacheService.DIRECTORY_NAME);
|
||||
}
|
||||
|
||||
|
||||
|
40
src/main/java/dev/mateuszkowalczyk/ffm/app/cache/FacesCacheService.java
vendored
Normal file
40
src/main/java/dev/mateuszkowalczyk/ffm/app/cache/FacesCacheService.java
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
package dev.mateuszkowalczyk.ffm.app.cache;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.data.database.face.Face;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FacesCacheService implements Runnable {
|
||||
protected static final String DIRECTORY_NAME = "/faces";
|
||||
private final BufferedImage faceImage;
|
||||
private String path;
|
||||
|
||||
public FacesCacheService (BufferedImage face) {
|
||||
this.faceImage = face;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
|
||||
public void getPath(Face face) {
|
||||
this.path = CacheService.getInstance().getPath() + DIRECTORY_NAME + "/" + face.getName() + ".PNG";
|
||||
face.setPath(this.path);
|
||||
}
|
||||
|
||||
public void createCachedFace() {
|
||||
if (faceImage != null && this.path != null) {
|
||||
File imageFile = new File(this.path);
|
||||
try {
|
||||
ImageIO.write(this.faceImage, "PNG", imageFile);
|
||||
System.out.println(String.format("Saved on location: %s", imageFile.getAbsolutePath()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package dev.mateuszkowalczyk.ffm.data.database.face;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.data.database.annotation.Column;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.annotation.PrimaryKey;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.annotation.Table;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Table
|
||||
public class Face {
|
||||
@Column(type = Column.Type.INT)
|
||||
@PrimaryKey
|
||||
private long id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
private String path;
|
||||
|
||||
public Face() {
|
||||
this.name = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package dev.mateuszkowalczyk.ffm.data.database.face;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.data.database.Dao;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class FaceDAO implements Dao<Face> {
|
||||
|
||||
@Override
|
||||
public Optional<Face> get(long id) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Face face) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Face face) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Face face) {
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package dev.mateuszkowalczyk.ffm.image;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.app.cache.FacesCacheService;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.face.Face;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.photo.Photo;
|
||||
import dev.mateuszkowalczyk.ffm.utils.ResourceLoader;
|
||||
import org.opencv.core.Core;
|
||||
@ -44,6 +46,11 @@ public class FaceDetector implements Runnable {
|
||||
|
||||
matOfRect.toList().forEach(rect -> {
|
||||
BufferedImage croppedImage = this.crop(bufferedImage, rect);
|
||||
Face face = new Face();
|
||||
FacesCacheService facesCacheService = new FacesCacheService(croppedImage);
|
||||
facesCacheService.getPath(face);
|
||||
facesCacheService.createCachedFace();
|
||||
|
||||
});
|
||||
|
||||
} catch (IOException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user