commit 08/04/2025

This commit is contained in:
rdkartono
2025-04-08 15:27:12 +07:00
parent 6f3080293f
commit e72d25a213
8 changed files with 621 additions and 637 deletions

View File

@@ -3,8 +3,10 @@ package Config;
import com.google.gson.Gson;
import com.google.zxing.MultiFormatReader;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.bytedeco.javacv.OpenCVFrameConverter;
@@ -15,9 +17,9 @@ import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.Rect;
import org.bytedeco.opencv.opencv_core.Size;
import org.bytedeco.opencv.opencv_core.UMat;
import org.opencv.core.MatOfDouble;
import org.tinylog.Logger;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
@@ -32,7 +34,6 @@ import java.util.ArrayList;
import java.util.List;
import static org.bytedeco.opencv.global.opencv_core.CV_64F;
import static org.bytedeco.opencv.global.opencv_core.CV_64FC3;
@SuppressWarnings("unused")
public class SomeCodes {
@@ -603,6 +604,52 @@ public class SomeCodes {
}
}
public static void SetText(Object obj, String text){
if (obj!=null && text!=null){
if (Platform.isFxApplicationThread()){
if (obj instanceof Label){
((Label) obj).setText(text);
} else if (obj instanceof TextArea){
((TextArea) obj).setText(text);
} else if (obj instanceof TextField){
((TextField) obj).setText(text);
}
} else{
Platform.runLater(()->{
if (obj instanceof Label){
((Label) obj).setText(text);
} else if (obj instanceof TextArea){
((TextArea) obj).setText(text);
} else if (obj instanceof TextField){
((TextField) obj).setText(text);
}
});
}
}
}
public static void LabelVisible(Label label, boolean visible){
if (label!=null){
if (visible){
if (Platform.isFxApplicationThread()){
label.setVisible(true);
} else{
Platform.runLater(()->{
label.setVisible(true);
});
}
} else {
if (Platform.isFxApplicationThread()){
label.setVisible(false);
} else{
Platform.runLater(()->{
label.setVisible(false);
});
}
}
}
}
public static void ShowAlert(Alert.AlertType type, String title, String header, String content){
Alert alert = new Alert(type);
alert.setTitle(title);
@@ -647,15 +694,25 @@ public class SomeCodes {
return false;
}
/**
* Calculate sharpness of image
* @param mat image in UMat format, expected in gray scale
* @return sharpness value
*/
public static double CalculateSharpness(UMat mat){
if (mat!=null && !mat.empty()){
UMat gray = new UMat();
opencv_imgproc.cvtColor(mat, gray, opencv_imgproc.COLOR_BGR2GRAY);
opencv_imgproc.equalizeHist(gray, gray);
if (mat.channels()!=1){
UMat grey = new UMat();
opencv_imgproc.cvtColor(mat, grey, opencv_imgproc.COLOR_BGR2GRAY);
mat = grey;
}
opencv_imgproc.equalizeHist(mat, mat);
UMat laplacian = new UMat();
opencv_imgproc.Laplacian(gray, laplacian, CV_64F);
opencv_imgproc.Laplacian(mat, laplacian, CV_64F);
UMat mean = new UMat(1,1, CV_64F);
UMat stddev = new UMat(1,1, CV_64F);