Trial 04022025
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package Config;
|
||||
|
||||
import id.co.gtc.erhacam.Detectors;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.File;
|
||||
@@ -40,6 +40,11 @@ public class ConfigFile {
|
||||
|
||||
private String PhotoDirectory;
|
||||
|
||||
private @Getter double cascadeScaleFactor;
|
||||
private @Getter int cascadeMinNeighbors;
|
||||
private @Getter int cascadeMinSize;
|
||||
private @Getter int cascadeMaxSize;
|
||||
|
||||
private boolean needsave = false;
|
||||
|
||||
public ConfigFile(){
|
||||
@@ -48,6 +53,34 @@ public class ConfigFile {
|
||||
Load();
|
||||
}
|
||||
|
||||
public void setCascadeScaleFactor(double value){
|
||||
if (cascadeScaleFactor != value){
|
||||
cascadeScaleFactor = value;
|
||||
needsave = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCascadeMinNeighbors(int value){
|
||||
if (cascadeMinNeighbors != value){
|
||||
cascadeMinNeighbors = value;
|
||||
needsave = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCascadeMinSize(int value){
|
||||
if (cascadeMinSize != value){
|
||||
cascadeMinSize = value;
|
||||
needsave = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCascadeMaxSize(int value){
|
||||
if (cascadeMaxSize != value){
|
||||
cascadeMaxSize = value;
|
||||
needsave = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPhotoDirectory(String path){
|
||||
if (ValidString(path)){
|
||||
if (!path.equals(PhotoDirectory)){
|
||||
@@ -528,6 +561,11 @@ public class ConfigFile {
|
||||
if (prop.getProperty(CameraConfigEnum.CameraConfigRight45.toString()) == null) allcorrect = false;
|
||||
if (prop.getProperty(CameraConfigEnum.CameraConfigRight90.toString()) == null) allcorrect = false;
|
||||
|
||||
if (prop.getProperty("cascadeScaleFactor") == null) allcorrect = false;
|
||||
if (prop.getProperty("cascadeMinNeighbors") == null) allcorrect = false;
|
||||
if (prop.getProperty("cascadeMinSize") == null) allcorrect = false;
|
||||
if (prop.getProperty("cascadeMaxSize") == null) allcorrect = false;
|
||||
|
||||
if (allcorrect){
|
||||
AudioPhase1 = prop.getProperty("AudioPhase1");
|
||||
AudioPhase2 = prop.getProperty("AudioPhase2");
|
||||
@@ -554,6 +592,15 @@ public class ConfigFile {
|
||||
ConfigRight45 = gson.fromJson(prop.getProperty(CameraConfigEnum.CameraConfigRight45.toString()), CameraConfig.class);
|
||||
ConfigRight90 = gson.fromJson(prop.getProperty(CameraConfigEnum.CameraConfigRight90.toString()), CameraConfig.class);
|
||||
|
||||
cascadeScaleFactor = toDouble(prop.getProperty("cascadeScaleFactor"));
|
||||
cascadeMinNeighbors = toInt(prop.getProperty("cascadeMinNeighbors"));
|
||||
cascadeMinSize = toInt(prop.getProperty("cascadeMinSize"));
|
||||
cascadeMaxSize = toInt(prop.getProperty("cascadeMaxSize"));
|
||||
|
||||
Detectors.setMaxSize(cascadeMaxSize);
|
||||
Detectors.setMinSize(cascadeMinSize);
|
||||
Detectors.setScaleFactor(cascadeScaleFactor);
|
||||
|
||||
Logger.info("Config Loaded");
|
||||
return;
|
||||
} else {
|
||||
@@ -568,6 +615,14 @@ public class ConfigFile {
|
||||
CreateDefault();
|
||||
}
|
||||
|
||||
private double toDouble(String cascadeScaleFactor) {
|
||||
try{
|
||||
return Double.parseDouble(cascadeScaleFactor);
|
||||
} catch (Exception e){
|
||||
return 1.1;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDefault(){
|
||||
AudioPhase1 = Path.of(currentDirectory, "audio", "phase1.mp3").toString();
|
||||
AudioPhase2 = Path.of(currentDirectory, "audio", "phase2.mp3").toString();
|
||||
@@ -590,6 +645,13 @@ public class ConfigFile {
|
||||
SetDefaultCameraConfig(ConfigCenter);
|
||||
SetDefaultCameraConfig(ConfigRight45);
|
||||
SetDefaultCameraConfig(ConfigRight90);
|
||||
cascadeScaleFactor = 1.1;
|
||||
cascadeMinNeighbors = 3;
|
||||
cascadeMinSize = 200;
|
||||
cascadeMaxSize = 400;
|
||||
Detectors.setMaxSize(cascadeMaxSize);
|
||||
Detectors.setMinSize(cascadeMinSize);
|
||||
Detectors.setScaleFactor(cascadeScaleFactor);
|
||||
Logger.info("Default Config Created");
|
||||
needsave = true;
|
||||
Save();
|
||||
@@ -640,6 +702,11 @@ public class ConfigFile {
|
||||
prop.setProperty(CameraConfigEnum.CameraConfigRight45.toString(), gson.toJson(ConfigRight45));
|
||||
prop.setProperty(CameraConfigEnum.CameraConfigRight90.toString(), gson.toJson(ConfigRight90));
|
||||
|
||||
prop.setProperty("cascadeScaleFactor", String.valueOf(cascadeScaleFactor));
|
||||
prop.setProperty("cascadeMinNeighbors", String.valueOf(cascadeMinNeighbors));
|
||||
prop.setProperty("cascadeMinSize", String.valueOf(cascadeMinSize));
|
||||
prop.setProperty("cascadeMaxSize", String.valueOf(cascadeMaxSize));
|
||||
|
||||
try{
|
||||
prop.store(new FileOutputStream(Path.of(currentDirectory, "config.properties").toString()), null);
|
||||
Logger.info("Config Saved");
|
||||
|
||||
Reference in New Issue
Block a user