Commit 21032025
This commit is contained in:
@@ -8,6 +8,7 @@ import javafx.scene.control.Alert;
|
||||
import javafx.scene.image.Image;
|
||||
import org.bytedeco.javacv.Java2DFrameConverter;
|
||||
import org.bytedeco.javacv.OpenCVFrameConverter;
|
||||
import org.bytedeco.opencv.global.opencv_core;
|
||||
import org.bytedeco.opencv.global.opencv_imgcodecs;
|
||||
import org.bytedeco.opencv.global.opencv_imgproc;
|
||||
import org.bytedeco.opencv.opencv_core.Mat;
|
||||
@@ -29,6 +30,8 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.bytedeco.opencv.global.opencv_core.CV_64F;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SomeCodes {
|
||||
public final static String currentDirectory = System.getProperty("user.dir");
|
||||
@@ -130,10 +133,6 @@ public class SomeCodes {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Make thumbfile from source jpg file
|
||||
* @param sourcejpg source jpg file
|
||||
@@ -516,6 +515,14 @@ public class SomeCodes {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Print(String... x){
|
||||
if (x!=null && x.length>0){
|
||||
for(String xx : x){
|
||||
System.out.println(xx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Region of Interest is inside UMat
|
||||
* @param ROI Region of Interest
|
||||
@@ -598,4 +605,50 @@ public class SomeCodes {
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
public static double CalculateSharpness(String filename){
|
||||
if (ValidFile(filename)){
|
||||
try(Mat mat = opencv_imgcodecs.imread(filename)){
|
||||
return CalculateSharpness(new UMat(mat));
|
||||
} catch (Exception e){
|
||||
Logger.error("Error calculating sharpness: "+filename+", Msg : "+e.getMessage());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double FindLowestValue(double... values){
|
||||
if (values!=null && values.length>0){
|
||||
double lowest = values[0];
|
||||
for(double x : values){
|
||||
if (x<lowest){
|
||||
lowest = x;
|
||||
}
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double CalculateSharpness(UMat mat){
|
||||
if (mat!=null && !mat.empty()){
|
||||
UMat gray = new UMat();
|
||||
opencv_imgproc.cvtColor(mat, gray, opencv_imgproc.COLOR_BGR2GRAY);
|
||||
UMat laplacian = new UMat();
|
||||
|
||||
opencv_imgproc.Laplacian(gray, laplacian, CV_64F);
|
||||
UMat mean = new UMat(1,1, CV_64F);
|
||||
UMat stddev = new UMat(1,1, CV_64F);
|
||||
opencv_core.meanStdDev(laplacian, mean, stddev);
|
||||
|
||||
Mat _std = new Mat();
|
||||
stddev.copyTo(_std);
|
||||
|
||||
return _std.ptr(0).getDouble() * _std.ptr(0).getDouble();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean IsBlurred(UMat mat, double threshold){
|
||||
return CalculateSharpness(mat)<threshold;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user