Trial 11022025
This commit is contained in:
@@ -10,7 +10,9 @@ import org.bytedeco.javacv.OpenCVFrameConverter;
|
||||
import org.bytedeco.opencv.global.opencv_imgcodecs;
|
||||
import org.bytedeco.opencv.global.opencv_imgproc;
|
||||
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.tinylog.Logger;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -96,6 +98,14 @@ public class SomeCodes {
|
||||
|
||||
}
|
||||
|
||||
public static String RectToString(Rect rect){
|
||||
if (rect!=null){
|
||||
return "X:"+rect.x()+",Y:"+rect.y()+",W:"+rect.width()+",H:"+rect.height();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find thumbfile in thumbs directory
|
||||
* @param sourcejpg source jpg file
|
||||
@@ -103,12 +113,7 @@ public class SomeCodes {
|
||||
*/
|
||||
public static String FindThumbfile(String sourcejpg){
|
||||
File sourcefile = new File(sourcejpg);
|
||||
Path thumbpath = Path.of(sourcefile.getParent(), "thumbs");
|
||||
try{
|
||||
if (!Files.exists(thumbpath)) Files.createDirectories(thumbpath);
|
||||
} catch (Exception e){
|
||||
Logger.error("Error creating thumbs directory: "+thumbpath+", Msg : "+e.getMessage());
|
||||
}
|
||||
Path thumbpath = Path.of(config.getThumbsDirectory());
|
||||
Path thumbfile = thumbpath.resolve(sourcefile.getName());
|
||||
if (Files.exists(thumbfile)){
|
||||
return thumbfile.toString();
|
||||
@@ -116,6 +121,22 @@ public class SomeCodes {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Wait(int millis){
|
||||
try{
|
||||
Thread.sleep(millis);
|
||||
} catch (Exception e){
|
||||
Logger.error("Error waiting: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect ScaleRect(Rect original, double scaleX, double scaleY){
|
||||
if (original!=null){
|
||||
return new Rect((int)(original.x()*scaleX), (int)(original.y()*scaleY),
|
||||
(int)(original.width()*scaleX), (int)(original.height()*scaleY));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make thumbfile from source jpg file
|
||||
* @param sourcejpg source jpg file
|
||||
@@ -126,23 +147,22 @@ public class SomeCodes {
|
||||
try{
|
||||
File ff = new File(sourcejpg);
|
||||
if (ff.exists()){
|
||||
Path thumbpath = Path.of(ff.getParent(), "thumbs");
|
||||
if (!Files.exists(thumbpath)) Files.createDirectories(thumbpath);
|
||||
String thumbfile = thumbpath.resolve(ff.getName()).toString();
|
||||
String thumbfile = Path.of(config.getPhotoDirectory(),"thumbs", ff.getName()).toString();
|
||||
File thumb = new File(thumbfile);
|
||||
if (thumb.exists()) return thumbfile;
|
||||
if (thumb.exists()) {
|
||||
return thumbfile;
|
||||
}
|
||||
|
||||
Mat source = opencv_imgcodecs.imread(sourcejpg);
|
||||
if (source!=null && !source.empty()){
|
||||
Mat resized = new Mat();
|
||||
opencv_imgproc.resize(source, resized, thumbsize);
|
||||
opencv_imgcodecs.imwrite(thumbfile, resized);
|
||||
Logger.info("Thumbfile created: "+thumbfile);
|
||||
return thumbfile;
|
||||
} else Logger.info("MakeThumbfile failed, Source File not valid image : "+sourcejpg);
|
||||
} else Logger.info("MakeThumbfile failed, Source File not found: "+sourcejpg);
|
||||
}
|
||||
}
|
||||
} catch (Exception e){
|
||||
Logger.error("Error making thumbfile: "+sourcejpg+", Msg : "+e.getMessage());
|
||||
System.out.println("Error making thumbfile: "+sourcejpg+", Msg : "+e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -290,8 +310,80 @@ public class SomeCodes {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Valid PatientID found
|
||||
* Patient ID is 10 digits number
|
||||
* @param patientid Patient ID
|
||||
* @return true if valid, false if not valid
|
||||
*/
|
||||
public static boolean ValidPatientID(String patientid){
|
||||
if (patientid!=null && patientid.length()==10){
|
||||
boolean valid = true;
|
||||
for(int i=0; i<patientid.length(); i++){
|
||||
if (!Character.isDigit(patientid.charAt(i))){
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static boolean ValidROI(Rect ROI){
|
||||
if (ROI!=null){
|
||||
if (ROI.width()>0){
|
||||
if (ROI.height()>0){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean ROIInsideUMat(Rect ROI, UMat mat){
|
||||
if (ValidROI(ROI)){
|
||||
if (mat!=null){
|
||||
return ROI.x()>=0 && ROI.y()>=0 &&
|
||||
ROI.x()+ROI.width()<=mat.cols() &&
|
||||
ROI.y()+ROI.height()<=mat.rows();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean IsSameROI(Rect ROI1, Rect ROI2){
|
||||
if (ValidROI(ROI1) && ValidROI(ROI2)){
|
||||
return ROI1.x()==ROI2.x() && ROI1.y()==ROI2.y() &&
|
||||
ROI1.width()==ROI2.width() && ROI1.height()==ROI2.height();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean IsInsideRect(Rect smaller, Rect bigger){
|
||||
if (smaller!=null && bigger!=null){
|
||||
return smaller.x()>=bigger.x() && smaller.y()>=bigger.y() &&
|
||||
smaller.x()+smaller.width()<=bigger.x()+bigger.width() &&
|
||||
smaller.y()+smaller.height()<=bigger.y()+bigger.height();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make directory if not exists
|
||||
* @param path directory path
|
||||
*/
|
||||
public static void MakeDirectory(String path){
|
||||
if (ValidString(path)){
|
||||
File ff = new File(path);
|
||||
if (!ff.isDirectory()){
|
||||
try{
|
||||
Files.createDirectories(ff.toPath());
|
||||
System.out.println("Directory created: "+path);
|
||||
} catch (Exception e){
|
||||
System.out.println("Error creating directory: "+path+", Msg : "+e.getMessage());
|
||||
}
|
||||
} else System.out.println("Directory exists: "+path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user