revisi 16/12/2024

This commit is contained in:
2024-12-16 15:02:46 +07:00
parent f6ee4817e6
commit eceb94d524
9 changed files with 224 additions and 200 deletions

View File

@@ -11,9 +11,10 @@ import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Slider;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
@@ -23,7 +24,6 @@ import javafx.scene.image.WritableImage;
import javafx.scene.layout.AnchorPane;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.OpenCVFrameGrabber;
import org.bytedeco.opencv.global.opencv_imgproc;
@@ -86,12 +86,7 @@ public class Cameradetail {
private Slider gainSlider;
@FXML
private Slider exposureSlider;
@FXML
private CheckBox AutoExposure;
@FXML
private CheckBox AutoWhiteBalance;
@FXML
private CheckBox AutoFocus;
private final UMat BestMat = new UMat();
private final UMat LiveMat = new UMat();
@@ -99,17 +94,31 @@ public class Cameradetail {
private Size PhotoSize = new Size(1920, 1080);
private void setSliderValue(Slider sld, CameraProperty prop, double value){
sld.setMin(prop.Min);
sld.setMax(prop.Max);
sld.setValue(value);
if (sld!=null){
sld.setMin(prop.Min);
sld.setMax(prop.Max);
sld.setValue(value);
}
}
private void resize_streamanchor(){
if (streamanchor!=null){
if (streamanchor.getHeight()!=0){
if (streamanchor.getWidth()!=0){
camerastream.setFitHeight(streamanchor.getHeight()-10);
//camerastream.setFitWidth(streamanchor.getWidth());
camerastream.setPreserveRatio(true);
}
}
}
}
@FXML
public void initialize(){
camerastream.fitHeightProperty().bind(streamanchor.heightProperty());
//camerastream.fitWidthProperty().bind(streamanchor.widthProperty());
camerastream.setPreserveRatio(true);
streamanchor.heightProperty().addListener(obs -> resize_streamanchor());
streamanchor.widthProperty().addListener(obs -> resize_streamanchor());
Platform.runLater(()->{
setSliderValue(brightnessSlider, ArducamIMX477Preset.Brightness, config.getBrightness(cameraConfigEnum));
@@ -118,27 +127,10 @@ public class Cameradetail {
setSliderValue(hueSlider, ArducamIMX477Preset.Hue, config.getHue(cameraConfigEnum));
setSliderValue(gainSlider, ArducamIMX477Preset.Gain, config.getGain(cameraConfigEnum));
setSliderValue(exposureSlider, ArducamIMX477Preset.ExposureTime, config.getExposure(cameraConfigEnum));
AutoExposure.setSelected(config.getAutoExposure(cameraConfigEnum));
AutoWhiteBalance.setSelected(config.getAutoWhiteBalance(cameraConfigEnum));
AutoFocus.setSelected(config.getAutoFocus(cameraConfigEnum));
});
AutoExposure.selectedProperty().addListener((obs, oldVal, newVal) -> {
setAutoExposure(newVal);
config.setAutoExposure(cameraConfigEnum, newVal);
raise_log("AutoExposure for "+getCameraTitle()+" changed to " + newVal);
});
AutoWhiteBalance.selectedProperty().addListener((obs, oldVal, newVal) -> {
setAutoWB(newVal);
config.setAutoWhiteBalance(cameraConfigEnum, newVal);
raise_log("AutoWhiteBalance for "+getCameraTitle()+" changed to "+newVal);
});
AutoFocus.selectedProperty().addListener((obs, oldVal, newVal) -> {
setAutoFocus(newVal);
config.setAutoFocus(cameraConfigEnum, newVal);
raise_log("AutoFocus for "+getCameraTitle()+" changed to "+newVal);
});
brightnessSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
setBrightness(newVal.doubleValue());
@@ -181,9 +173,7 @@ public class Cameradetail {
hueSlider.adjustValue(ArducamIMX477Preset.Hue.Default);
gainSlider.adjustValue(ArducamIMX477Preset.Gain.Default);
exposureSlider.adjustValue(ArducamIMX477Preset.ExposureTime.Default);
AutoExposure.setSelected(true);
AutoFocus.setSelected(true);
AutoWhiteBalance.setSelected(true);
}
@@ -541,22 +531,13 @@ public class Cameradetail {
}
//TODO Revisi nama file
private String makeFileName(String prefix){
//make filename with prefix_POSITION_YYYY-MM-DD_HH-MM-SS
LocalDateTime ldt = LocalDateTime.now();
String timetag = ldt.getYear() + "-" + ldt.getMonthValue() + "-" + ldt.getDayOfMonth() + "_" + ldt.getHour() + "-" + ldt.getMinute() + "-" + ldt.getSecond();
return prefix+"_"
+ switch(cameratitle.getText()){
case "Camera Left 90" -> "LEFT90";
case "Camera Left 45" -> "LEFT45";
case "Camera Center" -> "CENTER";
case "Camera Right 45" -> "RIGHT45";
case "Camera Right 90" -> "RIGHT90";
default -> "UNKNOWN";
}
+ "_" + timetag + ".jpg";
return prefix+" "+timetag+" "+cameratitle.getText() + ".jpg";
}
@@ -596,9 +577,7 @@ public class Cameradetail {
Platform.runLater(()->setCameraStatus(ss));
raise_log(ss);
AutoExposure.setSelected(true);
AutoFocus.setSelected(true);
AutoWhiteBalance.setSelected(true);
Task<Image> task = new Task<>() {
@SuppressWarnings("BusyWait")
@@ -625,8 +604,11 @@ public class Cameradetail {
IsGrabbingLiveView.set(true);
Frame frame = mGrabber.grab(); // grab frame
Mat mat = matconverter.convert(frame); // convert to Mat
if (mat.empty()) continue; // kalau gak ada data, continue
int counter = fps.incrementAndGet();
if (counter % 5 != 0) continue; // frame skip to 6 fps
mat.copyTo(BestMat); // copy to BestMat for using OpenCL
fps.addAndGet(1);
IsGrabbingLiveView.set(false);
if (frame != null) {

View File

@@ -10,14 +10,19 @@ import Database.Sqlite;
import FTP.FTPUpload;
import FTP.FTPUploadEvent;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import javafx.stage.DirectoryChooser;
import lombok.val;
import java.util.*;
import java.util.concurrent.Callable;
@@ -26,7 +31,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javafx.scene.control.Alert.AlertType;
import org.bytedeco.javacv.OpenCVFrameConverter;
import org.bytedeco.javacv.OpenCVFrameGrabber;
import org.bytedeco.javacv.VideoInputFrameGrabber;
import org.bytedeco.opencv.opencv_core.Size;
@@ -36,6 +40,9 @@ import static Config.SomeCodes.*;
public class CaptureView {
@FXML
private AnchorPane CaptureViewAnchor;
@FXML
private AnchorPane cam1, cam2, cam3, cam4, cam5, controlpane;
@@ -44,6 +51,8 @@ public class CaptureView {
@FXML
private TextArea directorypath, prefixfile;
@FXML
private Button btnTakePhoto;
@FXML
private AnchorPane progressanchor;
@@ -56,6 +65,7 @@ public class CaptureView {
private List<String> cams;
@FXML
private void ChangeDirectory(){
DirectoryChooser dc = new DirectoryChooser();
@@ -224,6 +234,11 @@ public class CaptureView {
}
}
private void UpdateBtnTakePhoto(){
boolean valid = ValidDirectory(directorypath.getText()) && ValidString(prefixfile.getText());
btnTakePhoto.setDisable(!valid);
}
@FXML
public void initialize(){
audio_posisikan_muka = ExtractResource("/satu.wav");
@@ -234,6 +249,11 @@ public class CaptureView {
audioPlayer = new AudioPlayer(1,48000);
Logger.info("Audio Player : "+(audioPlayer.isInited()? "Inited" : "Not Inited"));
btnTakePhoto.setDisable(true);
directorypath.textProperty().addListener((obs, oldval, newval)-> UpdateBtnTakePhoto());
prefixfile.textProperty().addListener((obs, oldval, newval)-> UpdateBtnTakePhoto());
cams = null;
try{
String[] xxx = VideoInputFrameGrabber.getDeviceDescriptions();
@@ -244,6 +264,8 @@ public class CaptureView {
Logger.error("Error getting camera list: "+e.getMessage());
}
LoadCameraDetail(cam1, 1, CameraConfigEnum.CameraConfigLeft90);
LoadCameraDetail(cam2, 2, CameraConfigEnum.CameraConfigLeft45);
LoadCameraDetail(cam3, 3, CameraConfigEnum.CameraConfigCenter);
@@ -261,8 +283,9 @@ public class CaptureView {
if (ValidString(camleft90)){
int[] indexes = FindIndexes(cams, camleft90);
if (indexes.length>0){
indexleft90 = indexes[0];
if (indexleft90!=1){
indexleft90 = FindFirstIndex(cams, camleft90);
Logger.info("Left90 Index: "+indexleft90);
if (indexleft90!=-1){
final int finalindex = indexleft90;
new Thread(()-> SetupCameraWithController(image1, camleft90, finalindex)).start();
}
@@ -273,6 +296,7 @@ public class CaptureView {
int[] indexes = FindIndexes(cams, camleft45);
if (indexes.length>0){
indexleft45 = FindFirstIndex(cams, camleft45, indexleft90);
Logger.info("Left45 Index: "+indexleft45);
if (indexleft45!=-1) {
final int finalindex = indexleft45;
new Thread(()-> SetupCameraWithController(image2, camleft45, finalindex)).start();
@@ -284,6 +308,7 @@ public class CaptureView {
int[] indexes = FindIndexes(cams, camcenter);
if (indexes.length>0){
indexcenter = FindFirstIndex(cams, camcenter, indexleft90, indexleft45);
Logger.info("Center Index: "+indexcenter);
if (indexcenter!=-1) {
final int finalindex = indexcenter;
new Thread(()-> SetupCameraWithController(image3, camcenter, finalindex)).start();
@@ -295,6 +320,7 @@ public class CaptureView {
int[] indexes = FindIndexes(cams, camright45);
if (indexes.length>0){
indexright45 = FindFirstIndex(cams, camright45, indexleft90, indexleft45, indexcenter);
Logger.info("Right45 Index: "+indexright45);
if (indexright45!=-1) {
final int finalindex = indexright45;
new Thread(()-> SetupCameraWithController(image4, camright45, finalindex)).start();
@@ -307,6 +333,7 @@ public class CaptureView {
int[] indexes = FindIndexes(cams, camright90);
if (indexes.length>0){
indexright90 = FindFirstIndex(cams, camright90, indexleft90, indexleft45, indexcenter, indexright45);
Logger.info("Right90 Index: "+indexright90);
if (indexright90!=-1) {
final int finalindex = indexright90;
new Thread(()-> SetupCameraWithController(image5, camright90, finalindex)).start();
@@ -386,11 +413,11 @@ public class CaptureView {
private void SetupCameraWithController(Cameradetail image, String cameraname, int devicenumber){
if (image!=null){
String title = switch(image.getCameraConfigEnum()){
case CameraConfigCenter -> "Camera Center";
case CameraConfigLeft45 -> "Camera Left 45";
case CameraConfigLeft90 -> "Camera Left 90";
case CameraConfigRight45 -> "Camera Right 45";
case CameraConfigRight90 -> "Camera Right 90";
case CameraConfigCenter -> "03";
case CameraConfigLeft45 -> "02";
case CameraConfigLeft90 -> "01";
case CameraConfigRight45 -> "04";
case CameraConfigRight90 -> "05";
};
Platform.runLater(()-> image.setCameraTitle(title));
if (devicenumber!=-1){
@@ -468,17 +495,38 @@ public class CaptureView {
private void LoadCameraDetail(AnchorPane cam, int camid, CameraConfigEnum cc){
try{
FXMLLoader loader = new FXMLLoader(getClass().getResource("cameradetail.fxml"));
AnchorPane child = loader.load();
AnchorPane.setTopAnchor(child, 0.0);
AnchorPane.setBottomAnchor(child, 0.0);
AnchorPane.setLeftAnchor(child, 0.0);
AnchorPane.setRightAnchor(child, 0.0);
cam.getChildren().clear();
cam.getChildren().add(child);
cam.widthProperty().addListener(observable ->{
//System.out.println("Width property, cam "+camid+" width="+cam.getWidth()+" height="+cam.getHeight());
if (cam.getWidth()!=0) {
if (cam.getHeight()!=0){
AnchorPane.setTopAnchor(child, 0.0);
AnchorPane.setBottomAnchor(child, 0.0);
AnchorPane.setLeftAnchor(child, 0.0);
AnchorPane.setRightAnchor(child, 0.0);
}
}
});
cam.heightProperty().addListener(observable -> {
//System.out.println("Height property, cam "+camid+" width="+cam.getWidth()+" height="+cam.getHeight());
if (cam.getWidth()!=0) {
if (cam.getHeight()!=0){
AnchorPane.setTopAnchor(child, 0.0);
AnchorPane.setBottomAnchor(child, 0.0);
AnchorPane.setLeftAnchor(child, 0.0);
AnchorPane.setRightAnchor(child, 0.0);
}
}
});
switch(camid){
case 1:

View File

@@ -23,7 +23,7 @@ public class MainApplication extends Application {
Scene scene = new Scene(fxmlLoader.load(), screenbound.getWidth(), screenbound.getHeight());
stage.setTitle("MultiCam Capture App for ERHA");
stage.setScene(scene);
stage.setResizable(false);
stage.setResizable(true);
stage.setMaximized(true);
stage.setOnCloseRequest(e->{
config.Save();