commit 27/2025

Tambah Crop Setting
This commit is contained in:
2025-05-27 11:26:29 +07:00
parent 9e69714ae1
commit d0fe8123e9
9 changed files with 280 additions and 224 deletions

View File

@@ -1,9 +1,10 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
<inspection_tool class="AutoCloseableResource" enabled="false" level="WARNING" enabled_by_default="false">
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.lang.foreign.Arena,ofAuto,java.lang.foreign.Arena,global,java.util.concurrent.Executors,newFixedThreadPool" />
</inspection_tool>
<inspection_tool class="ClassEscapesItsScope" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="CommentedOutCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="minLines" value="3" />
</inspection_tool>
@@ -15,5 +16,6 @@
<option name="processComments" value="true" />
</inspection_tool>
<inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="UnusedReturnValue" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@@ -1,12 +1,12 @@
#Mon May 26 14:20:06 WIB 2025
#Tue May 27 10:31:40 WIB 2025
AudioPhase1=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase1.mp3
AudioPhase2=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase2.mp3
AudioPhase3=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase3.mp3
AudioPhase4=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase4.mp3
AudioPhase5=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase5.mp3
Cam1BottomCrop=10.0
Cam1LeftCrop=10.0
Cam1RightCrop=10.0
Cam1BottomCrop=20.0
Cam1LeftCrop=8.0
Cam1RightCrop=8.0
Cam1TopCrop=10.0
Cam2BottomCrop=10.0
Cam2LeftCrop=10.0
@@ -31,7 +31,7 @@ CameraConfigLeft90={"Brightness"\:0.0,"Contrast"\:0.0,"Saturation"\:0.0,"Hue"\:0
CameraConfigRight45={"Brightness"\:0.0,"Contrast"\:0.0,"Saturation"\:0.0,"Hue"\:0.0,"Gain"\:1.0,"Exposure"\:1.0,"Sharpness"\:0.0,"Gamma"\:0.0,"AutoExposure"\:true,"AutoFocus"\:true,"AutoWhiteBalance"\:true}
CameraConfigRight90={"Brightness"\:0.0,"Contrast"\:0.0,"Saturation"\:0.0,"Hue"\:0.0,"Gain"\:1.0,"Exposure"\:1.0,"Sharpness"\:0.0,"Gamma"\:0.0,"AutoExposure"\:true,"AutoFocus"\:true,"AutoWhiteBalance"\:true}
CameraLeft45=
CameraLeft90=
CameraLeft90=OBSBOT Meet 2 StreamCamera
CameraRight45=
CameraRight90=
FTPHost=192.168.10.2
@@ -41,9 +41,9 @@ FTPPort=21
FTPUser=user
FlipCamera=false
MirrorCamera=false
PhotoDirectory=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam
PhotoDirectory=C\:\\Users\\rdkar\\OneDrive\\Desktop\\Erha Capture
SharpnessThreshold=300.0
cascadeMaxSize=500
cascadeMaxSize=360
cascadeMinNeighbors=3
cascadeMinSize=250
cascadeScaleFactor=1.1
cascadeScaleFactor=1.05

View File

@@ -55,23 +55,23 @@ public class ConfigFile {
private @Getter final double leftcropmax = 30.0;
private @Getter final double rightcropmax = 30.0;
private @Getter double Cam1TopCrop = 10.0;
private @Getter double Cam1BottomCrop = 10.0;
private @Getter double Cam1LeftCrop = 10.0;
private @Getter double Cam1RightCrop = 10.0;
private @Getter double Cam1BottomCrop = 20.0;
private @Getter double Cam1LeftCrop = 8.0;
private @Getter double Cam1RightCrop = 8.0;
private @Getter double Cam2TopCrop = 10.0;
private @Getter double Cam2BottomCrop = 10.0;
private @Getter double Cam2LeftCrop = 10.0;
private @Getter double Cam2RightCrop = 10.0;
private @Getter double Cam2BottomCrop = 20.0;
private @Getter double Cam2LeftCrop = 8.0;
private @Getter double Cam2RightCrop = 8.0;
private @Getter double Cam3TopCrop = 10.0;
private @Getter double Cam3BottomCrop = 10.0;
private @Getter double Cam3LeftCrop = 10.0;
private @Getter double Cam3RightCrop = 10.0;
private @Getter double Cam3BottomCrop = 20.0;
private @Getter double Cam3LeftCrop = 8.0;
private @Getter double Cam3RightCrop = 8.0;
private @Getter double Cam4TopCrop = 10.0;
private @Getter double Cam4BottomCrop = 10.0;
private @Getter double Cam4LeftCrop = 10.0;
private @Getter double Cam4RightCrop = 10.0;
private @Getter double Cam4BottomCrop = 20.0;
private @Getter double Cam4LeftCrop = 8.0;
private @Getter double Cam4RightCrop = 8.0;
private @Getter double Cam5TopCrop = 10.0;
private @Getter double Cam5BottomCrop = 10.0;
private @Getter double Cam5BottomCrop = 20.0;
private @Getter double Cam5LeftCrop = 10.0;
private @Getter double Cam5RightCrop = 10.0;
@@ -940,10 +940,10 @@ public class ConfigFile {
SetDefaultCameraConfig(ConfigCenter);
SetDefaultCameraConfig(ConfigRight45);
SetDefaultCameraConfig(ConfigRight90);
cascadeScaleFactor = 1.1;
cascadeScaleFactor = 1.05;
cascadeMinNeighbors = 3;
cascadeMinSize = 250;
cascadeMaxSize = 500;
cascadeMaxSize = 360;
Detectors.setFaceMaxSize(cascadeMaxSize);
Detectors.setFaceMinSize(cascadeMinSize);
Detectors.setScaleFactor(cascadeScaleFactor);
@@ -952,29 +952,29 @@ public class ConfigFile {
SharpnessThreshold = 300.0;
Cam1TopCrop = 10.0;
Cam1BottomCrop = 10.0;
Cam1LeftCrop = 10.0;
Cam1RightCrop = 10.0;
Cam1BottomCrop = 20.0;
Cam1LeftCrop = 8.0;
Cam1RightCrop = 8.0;
Cam2TopCrop = 10.0;
Cam2BottomCrop = 10.0;
Cam2LeftCrop = 10.0;
Cam2RightCrop = 10.0;
Cam2BottomCrop = 20.0;
Cam2LeftCrop = 8.0;
Cam2RightCrop = 8.0;
Cam3TopCrop = 10.0;
Cam3BottomCrop = 10.0;
Cam3LeftCrop = 10.0;
Cam3RightCrop = 10.0;
Cam3BottomCrop = 20.0;
Cam3LeftCrop = 8.0;
Cam3RightCrop = 8.0;
Cam4TopCrop = 10.0;
Cam4BottomCrop = 10.0;
Cam4LeftCrop = 10.0;
Cam4RightCrop = 10.0;
Cam4BottomCrop = 20.0;
Cam4LeftCrop = 8.0;
Cam4RightCrop = 8.0;
Cam5TopCrop = 10.0;
Cam5BottomCrop = 10.0;
Cam5LeftCrop = 10.0;
Cam5RightCrop = 10.0;
Cam5BottomCrop = 20.0;
Cam5LeftCrop = 8.0;
Cam5RightCrop = 8.0;
Logger.info("Default Config Created");
needsave = true;

View File

@@ -643,7 +643,7 @@ public class SomeCodes {
* Check if Region of Interest 1 is same with Region of Interest 2
* @param ROI1 Region of Interest 1
* @param ROI2 Region of Interest 2
* @return true if same, false if not same
* @return true if same, false if different
*/
public static boolean IsSameROI(Rect ROI1, Rect ROI2){
if (ValidROI(ROI1) && ValidROI(ROI2)){
@@ -778,7 +778,7 @@ public class SomeCodes {
public static double CalculateSharpness(String filename){
if (ValidFile(filename)){
try(Mat mat = opencv_imgcodecs.imread(filename)){
return CalculateSharpness(new UMat(mat));
return CalculateSharpness(mat);
} catch (Exception e){
Logger.error("Error calculating sharpness: "+filename+", Msg : "+e.getMessage());
}
@@ -816,23 +816,23 @@ public class SomeCodes {
* @param mat image in UMat format, expected in gray scale
* @return sharpness value
*/
public static double CalculateSharpness(UMat mat){
public static double CalculateSharpness(Mat mat){
if (mat!=null && !mat.empty()){
if (mat.channels()!=1){
UMat grey = new UMat();
Mat grey = new Mat();
opencv_imgproc.cvtColor(mat, grey, opencv_imgproc.COLOR_BGR2GRAY);
mat = grey;
}
opencv_imgproc.equalizeHist(mat, mat);
UMat laplacian = new UMat();
Mat laplacian = new Mat();
opencv_imgproc.Laplacian(mat, laplacian, CV_64F);
UMat mean = new UMat(1,1, CV_64F);
UMat stddev = new UMat(1,1, CV_64F);
Mat mean = new Mat(1,1, CV_64F);
Mat stddev = new Mat(1,1, CV_64F);
opencv_core.meanStdDev(laplacian, mean, stddev);
@@ -847,7 +847,7 @@ public class SomeCodes {
return 0;
}
public static boolean IsBlurred(UMat mat, double threshold){
public static boolean IsBlurred(Mat mat, double threshold){
return CalculateSharpness(mat)<threshold;
}

View File

@@ -35,7 +35,6 @@ import java.awt.image.BufferedImage;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
@@ -117,11 +116,11 @@ public class Cameradetail {
private @Getter final UMat BestMat = new UMat();
private @Getter final UMat LiveMat = new UMat();
private @Getter final UMat ReducedMat = new UMat();
private @Getter final UMat GrayMat = new UMat();
private @Getter final Mat GrayMat = new Mat();
private @Getter Rect BestMatROI;
private @Getter Rect ReducedMatROI;
private @Getter Rect LiveMatROI;
// private @Getter Rect BestMatROI;
// private @Getter Rect ReducedMatROI;
// private @Getter Rect LiveMatROI;
private boolean IsPortrait = false;
@@ -157,7 +156,6 @@ public class Cameradetail {
private boolean use_qr = false;
private boolean use_face = false;
private int _hardwareID = -1;
private void setSliderValue(Slider sld, CameraProperty prop, double value){
@@ -267,12 +265,10 @@ public class Cameradetail {
public void setCameraTitle(String title){
if (ValidString(title)){
if (!Objects.equals(this.title, title)){
this.title = title;
LabelSetText(cameratitle, title,null);
}
}
}
public void setSharpness_indicator(double value){
if (value >= config.getSharpnessThreshold()){
@@ -422,7 +418,6 @@ public class Cameradetail {
}
mGrabber = grabber;
_hardwareID = hardwareID;
}
//Exposure and Focus Tricks :
@@ -687,7 +682,7 @@ public class Cameradetail {
* @return filename path of the saved photo, or null if failed
*/
public PhotoResult TakePhoto(String directory, String prefix) {
PhotoResult result = new PhotoResult(cameratitle.getText());
PhotoResult result = new PhotoResult(title);
if (!ValidDirectory(directory)) directory = currentDirectory;
if (mGrabber!=null){
@@ -699,37 +694,48 @@ public class Cameradetail {
if (!BestMat.empty()){
UMat cloned;
UMat cloned = new UMat();
synchronized (BestMat){
cloned = BestMat.clone();
BestMat.copyTo(cloned);
}
// save BestMat at quality 9 PNG
String filename = GetFullQualityPhotoPath(directory, prefix);
if (opencv_imgcodecs.imwrite(filename, cloned, parampng)){
result.setFullres(filename);
} else System.out.println("TakePhoto failed, Unable to Save FullQUality Photo for camera "+cameratitle.getText());
String xx = CropBestMat(directory, prefix, BestMatROI);
if (ValidFile(xx)) {
result.setFullcrop(xx);
result.setBestROI(new Rect(BestMatROI.x(), BestMatROI.y(), BestMatROI.width(), BestMatROI.height()));
}
String fullresfile = GetFullQualityPhotoPath(directory, prefix);
if (opencv_imgcodecs.imwrite(fullresfile, cloned, parampng)){
result.setFullres(fullresfile);
} else System.out.println("TakePhoto failed, Unable to Save FullQUality Photo for camera "+title);
// save ReducedMat at 100% JPEG
String reducedfilename = GetReducedPhotoPath(directory, prefix);
String reducedfile = GetReducedPhotoPath(directory, prefix);
opencv_imgproc.resize(cloned, ReducedMat, ReducedSize);
if (!opencv_imgcodecs.imwrite(reducedfilename, ReducedMat, paramjpeg)){
System.out.println("TakePhoto failed, Unable to Save Reduced Photo for camera "+cameratitle.getText());
} else result.setCompressedfile(reducedfilename);
String xy = CropReducedMat(directory, prefix, ReducedMatROI);
if (ValidFile(xy)){
result.setCompressedcrop(xy);
result.setReducedROI(new Rect(ReducedMatROI.x(), ReducedMatROI.y(), ReducedMatROI.width(), ReducedMatROI.height()));
if (opencv_imgcodecs.imwrite(reducedfile, ReducedMat, paramjpeg)){
result.setCompressedfile(reducedfile);
} else {
System.out.println("TakePhoto failed, Unable to Save Reduced Photo for camera "+title);
}
String fullcropfile = GetFullQualityCropPhotoPath(directory, prefix);
UMat croppedfull = CropMat(cloned);
if (croppedfull!=null && !croppedfull.empty()){
if (opencv_imgcodecs.imwrite(fullcropfile, croppedfull, parampng)){
result.setFullcrop(fullcropfile);
} else {
System.out.println("TakePhoto failed, Unable to Save FullCrop Photo for camera "+title);
}
} else System.out.println("TakePhoto failed, Unable to Save FullCrop Photo for camera "+title);
String reducedcropfile = GetReducedCropPhotoPath(directory, prefix);
UMat reducedcrop = CropMat(ReducedMat);
if (reducedcrop!=null && !reducedcrop.empty()){
if (opencv_imgcodecs.imwrite(reducedcropfile, reducedcrop, paramjpeg)){
result.setCompressedcrop(reducedcropfile);
} else {
System.out.println("TakePhoto failed, Unable to Save ReducedCrop Photo for camera "+title);
}
} else System.out.println("TakePhoto failed, Unable to Save ReducedCrop Photo for camera "+title);
cloned.release();
} else raise_log("TakePhoto failed, Live View is Empty");
@@ -749,9 +755,9 @@ public class Cameradetail {
public String CropBestMat(String directory, String prefix, Rect ROI){
UMat cloned;
UMat cloned = new UMat();
synchronized (BestMat){
cloned = BestMat.clone();
BestMat.copyTo(cloned);
}
if (!cloned.empty()) {
if (ValidROI(ROI)){
@@ -796,34 +802,34 @@ public class Cameradetail {
private String makeFileName(String prefix, String extension){
LocalDateTime ldt = LocalDateTime.now();
String timetag = ldt.getYear() + "-" + ldt.getMonthValue() + "-" + ldt.getDayOfMonth() + "_" + ldt.getHour() + "-" + ldt.getMinute() + "-" + ldt.getSecond();
return prefix+" "+timetag+" "+cameratitle.getText() + extension;
return prefix+" "+timetag+" "+title + extension;
}
@SuppressWarnings("SameParameterValue")
private String makeReducedFileName(String prefix, String extension){
LocalDateTime ldt = LocalDateTime.now();
String timetag = ldt.getYear() + "-" + ldt.getMonthValue() + "-" + ldt.getDayOfMonth() + "_" + ldt.getHour() + "-" + ldt.getMinute() + "-" + ldt.getSecond();
return prefix+" "+timetag+" "+cameratitle.getText() + "_reduced" + extension;
return prefix+" "+timetag+" "+title + "_reduced" + extension;
}
public void Release(){
if (mGrabber!=null){
try{
StopLiveView();
mGrabber.release();
mGrabber = null;
} catch (Exception e){
System.out.println("Release failed, Unable to Release Camera, Error: " + e.getMessage());
}
}
}
// public void Release(){
// if (mGrabber!=null){
// try{
// StopLiveView();
// mGrabber.release();
// mGrabber = null;
// } catch (Exception e){
// System.out.println("Release failed, Unable to Release Camera, Error: " + e.getMessage());
// }
// }
// }
public void StopLiveView(){
Capturing.set(false);
if (mGrabber!=null){
try{
mGrabber.close();
System.out.println("Camera "+cameratitle.getText()+" stopped");
System.out.println("Camera "+title+" stopped");
setCameraStatus("Camera Stopped");
} catch (Exception e){
raise_log("StopLiveView failed, Unable to Stop Camera, Error: " + e.getMessage());
@@ -858,11 +864,8 @@ public class Cameradetail {
while(Capturing.get()){
try {
qr_semaphore.acquire();
UMat gray;
synchronized (lockObject){
gray = GrayMat;
}
String qr = DetectQRFromMat(gray);
String qr = DetectQRFromMat(GrayMat.clone());
if (ValidBarCode(qr)){
if (event!=null) event.onDetectedQRCode(qr);
}
@@ -887,10 +890,7 @@ public class Cameradetail {
while(Capturing.get()){
try {
face_semaphore.acquire();
UMat gray;
synchronized (lockObject){
gray = GrayMat;
}
DetectorResult theface = null;
boolean have_frontal_face = false;
@@ -898,7 +898,7 @@ public class Cameradetail {
int _face_width = 0;
int _face_height = 0;
List<DetectorResult> frontalfaces = HaveFrontalFace(gray);
List<DetectorResult> frontalfaces = HaveFrontalFace(GrayMat.clone());
if (!frontalfaces.isEmpty()){
for(DetectorResult rect : frontalfaces){
if (rect.haveFace() ){
@@ -916,7 +916,7 @@ public class Cameradetail {
} else {
// gak punya frontal face
// coba cek punya profile left face 45 gak
List<DetectorResult> Left45Faces = HaveLeft45Face(gray);
List<DetectorResult> Left45Faces = HaveLeft45Face(GrayMat.clone());
if (!Left45Faces.isEmpty()){
for(DetectorResult rect : Left45Faces){
if (rect.haveFace()){
@@ -938,9 +938,10 @@ public class Cameradetail {
if (event!=null) event.onFrontalFaceDetector(true, _face_width, _face_height);
LabelVisible(face_indicator,true);
if (theface.getFace()!=null){
LiveMatROI = new Rect(theface.getFace().x(), theface.getFace().y(), theface.getFace().width(), theface.getFace().height());
}
// Revisi 26/05/2025, LiveMatROI dihitung dari topcrop, bottomcrop, leftcrop dan rightcrop
// if (theface.getFace()!=null){
// LiveMatROI = new Rect(theface.getFace().x(), theface.getFace().y(), theface.getFace().width(), theface.getFace().height());
// }
if (theface.getEyesCount()>=2){
// ada mata (buka mata)
@@ -955,7 +956,7 @@ public class Cameradetail {
if (eye_state.get()!=1){
// transisi dari tutup mata ke buka mata
if (eye_state.get()==-1) {
System.out.println("First Eye Detected from camera "+cameratitle.getText());
System.out.println("First Eye Detected from camera "+title);
eye_state.set(1);
} else {
eye_state.set(1);
@@ -969,13 +970,13 @@ public class Cameradetail {
long diff = now - last_blink.get();
// kalau beda waktu antara blink 1 dan blink 2 kurang dari 3 detik
if (diff<=3000){
System.out.println("Double Blink Detected from camera "+cameratitle.getText());
System.out.println("Double Blink Detected from camera "+title);
if (event!=null) event.onDoubleBlink((int)diff);
}
waiting_for_second_blink.set(false);
} else {
waiting_for_second_blink.set(true);
System.out.println("First Blink Detected from camera "+cameratitle.getText());
System.out.println("First Blink Detected from camera "+title);
}
last_blink.set(now);
}
@@ -1029,13 +1030,19 @@ public class Cameradetail {
}
if (LiveMat != null && !LiveMat.empty()){
Mat imgmat = new Mat();
LiveMat.copyTo(imgmat);
// copy back to CPU
LiveMat.copyTo(imgmat);
setCameraStream(MatToImage(imgmat));
imgmat.release();
}
} catch (Exception e) {
//System.out.println(Thread.currentThread().getName()+" interrupted");
}
@@ -1055,7 +1062,7 @@ public class Cameradetail {
Frame frame = mGrabber.grab(); // grab frame
delta = System.currentTimeMillis() - now;
now = System.currentTimeMillis();
} catch (FrameGrabber.Exception ignored) {
} catch (Exception ignored) {
}
@@ -1081,11 +1088,9 @@ public class Cameradetail {
if (Capturing.get()) {
try{
if (mGrabber!=null)
if (mGrabber==null) continue;
frame = mGrabber.grab();
else throw new FrameGrabber.Exception("Grabber is null");
} catch (FrameGrabber.Exception e){
} catch (Exception e){
if (Capturing.get()){
// kalau ada exception padahal masih capturing. Kalau sudah tidak capturing, tidak peduli
if (ValidString(e.getMessage())){
@@ -1139,15 +1144,29 @@ public class Cameradetail {
// rotate 90 degree counter clockwise karena kamera potrait
opencv_core.rotate(originalmat, BestMat, opencv_core.ROTATE_90_COUNTERCLOCKWISE);
originalmat.release();
if (!BestMat.empty()) {
// LiveMat and GrayMat are synchronized
synchronized (lockObject){
opencv_imgproc.resize(BestMat, LiveMat, LiveSize); // resize to LiveSize
opencv_imgproc.cvtColor(LiveMat,GrayMat, COLOR_BGR2GRAY); // convert to grayscale
// resize BestMat to LiveSize
UMat _liveMat = new UMat();
opencv_imgproc.resize(BestMat, _liveMat, LiveSize);
// crop LiveMat
UMat croppedLiveMat = CropMat(_liveMat);
if (croppedLiveMat!=null && !croppedLiveMat.empty()){
croppedLiveMat.copyTo(LiveMat);
croppedLiveMat.release();
} else {
_liveMat.copyTo(LiveMat);
_liveMat.release();
}
// convert to grayscale
Mat xx = new Mat();
LiveMat.copyTo(xx);
opencv_imgproc.cvtColor(xx,GrayMat, COLOR_BGR2GRAY);
}
if (use_qr){
@@ -1172,6 +1191,29 @@ public class Cameradetail {
}
});
private UMat CropMat(UMat mat){
if (mat != null && !mat.empty()){
int width = mat.cols();
int height = mat.rows();
int x = (int) (width * leftcrop / 100);
int y = (int) (height * topcrop / 100);
int w = (int) (width * (100 - leftcrop - rightcrop) / 100);
int h = (int) (height * (100 - topcrop - bottomcrop) / 100);
// Ensure the crop dimensions are valid
if (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= width && y + h <= height) {
Rect roi = new Rect(x, y, w, h);
UMat crop = new UMat();
mat.apply(roi).copyTo(crop);
return crop;
}
}
return null;
}
public void ChangeCropValue(){
if ("01".equals(title)){
topcrop = config.getCam1TopCrop();
@@ -1281,81 +1323,78 @@ public class Cameradetail {
}
/**
* Remap LiveMatROI to BestMatROI and ReducedMatROI Resolution
* @param scaleX scale factor for width
* @param scaleY scale factor for height
*/
public void RemapROI(double scaleX, double scaleY, boolean printdebug){
BestMatROI = null;
ReducedMatROI = null;
if (ValidROI(LiveMatROI)){
if (ROIInsideUMat(LiveMatROI, LiveMat)){
if (printdebug) System.out.println("LiveMatROI camera "+cameratitle.getText()+" = "+RectToString(LiveMatROI));
double scaleXBest = 1.0*BestSize.width()/LiveSize.width();
double scaleYBest = 1.0*BestSize.height()/LiveSize.height();
int XBest = (int) (LiveMatROI.x()*scaleXBest);
int YBest = (int) (LiveMatROI.y()*scaleYBest);
int WBest = (int) (LiveMatROI.width()*scaleXBest);
int HBest = (int) (LiveMatROI.height()*scaleYBest);
int deltaWBest = (int) (BestSize.width() * scaleX);
int deltaHBest = (int) (BestSize.height() * scaleY);
XBest = XBest - deltaWBest/2;
if (XBest<0) XBest = 0;
YBest = YBest - deltaHBest/2;
if (YBest<0) YBest = 0;
WBest = WBest + deltaWBest;
if (WBest>BestSize.width()) WBest = BestSize.width();
HBest = HBest + deltaHBest;
if (HBest>BestSize.height()) HBest = BestSize.height();
BestMatROI = new Rect(XBest, YBest, WBest, HBest);
if (printdebug){
System.out.println("scaleXBest = "+scaleXBest+" scaleYBest = "+scaleYBest);
System.out.println("BestMatROI camera "+cameratitle.getText()+" = "+RectToString(BestMatROI));
}
double scaleXReduced = 1.0*ReducedSize.width()/LiveSize.width();
double scaleYReduced = 1.0*ReducedSize.height()/LiveSize.height();
int XReduced = (int) (LiveMatROI.x()*scaleXReduced);
int YReduced = (int) (LiveMatROI.y()*scaleYReduced);
int WReduced = (int) (LiveMatROI.width()*scaleXReduced);
int HReduced = (int) (LiveMatROI.height()*scaleYReduced);
int deltaWReduced = (int) (ReducedSize.width() * scaleX);
int deltaHReduced = (int) (ReducedSize.height() * scaleY);
XReduced = XReduced - deltaWReduced/2;
if (XReduced<0) XReduced = 0;
YReduced = YReduced - deltaHReduced/2;
if (YReduced<0) YReduced = 0;
WReduced = WReduced + deltaWReduced;
if (WReduced>ReducedSize.width()) WReduced = ReducedSize.width();
HReduced = HReduced + deltaHReduced;
if (HReduced>ReducedSize.height()) HReduced = ReducedSize.height();
ReducedMatROI = new Rect(XReduced, YReduced, WReduced, HReduced);
if (printdebug){
System.out.println("scaleXReduced = "+scaleXReduced+" scaleYReduced = "+scaleYReduced);
System.out.println("ReducedMatROI camera "+cameratitle.getText()+" = "+RectToString(ReducedMatROI));
}
}
}
}
// /**
// * Remap LiveMatROI to BestMatROI and ReducedMatROI Resolution
// * @param scaleX scale factor for width
// * @param scaleY scale factor for height
// */
// public void RemapROI(double scaleX, double scaleY, boolean printdebug){
// BestMatROI = null;
// ReducedMatROI = null;
// if (ValidROI(LiveMatROI)){
// if (ROIInsideUMat(LiveMatROI, LiveMat)){
// if (printdebug) System.out.println("LiveMatROI camera "+cameratitle.getText()+" = "+RectToString(LiveMatROI));
//
// double scaleXBest = 1.0*BestSize.width()/LiveSize.width();
// double scaleYBest = 1.0*BestSize.height()/LiveSize.height();
// int XBest = (int) (LiveMatROI.x()*scaleXBest);
// int YBest = (int) (LiveMatROI.y()*scaleYBest);
// int WBest = (int) (LiveMatROI.width()*scaleXBest);
// int HBest = (int) (LiveMatROI.height()*scaleYBest);
// int deltaWBest = (int) (BestSize.width() * scaleX);
// int deltaHBest = (int) (BestSize.height() * scaleY);
// XBest = XBest - deltaWBest/2;
// if (XBest<0) XBest = 0;
// YBest = YBest - deltaHBest/2;
// if (YBest<0) YBest = 0;
// WBest = WBest + deltaWBest;
// if (WBest>BestSize.width()) WBest = BestSize.width();
// HBest = HBest + deltaHBest;
// if (HBest>BestSize.height()) HBest = BestSize.height();
// BestMatROI = new Rect(XBest, YBest, WBest, HBest);
//
// if (printdebug){
// System.out.println("scaleXBest = "+scaleXBest+" scaleYBest = "+scaleYBest);
// System.out.println("BestMatROI camera "+cameratitle.getText()+" = "+RectToString(BestMatROI));
// }
//
// double scaleXReduced = 1.0*ReducedSize.width()/LiveSize.width();
// double scaleYReduced = 1.0*ReducedSize.height()/LiveSize.height();
// int XReduced = (int) (LiveMatROI.x()*scaleXReduced);
// int YReduced = (int) (LiveMatROI.y()*scaleYReduced);
// int WReduced = (int) (LiveMatROI.width()*scaleXReduced);
// int HReduced = (int) (LiveMatROI.height()*scaleYReduced);
// int deltaWReduced = (int) (ReducedSize.width() * scaleX);
// int deltaHReduced = (int) (ReducedSize.height() * scaleY);
// XReduced = XReduced - deltaWReduced/2;
// if (XReduced<0) XReduced = 0;
// YReduced = YReduced - deltaHReduced/2;
// if (YReduced<0) YReduced = 0;
// WReduced = WReduced + deltaWReduced;
// if (WReduced>ReducedSize.width()) WReduced = ReducedSize.width();
// HReduced = HReduced + deltaHReduced;
// if (HReduced>ReducedSize.height()) HReduced = ReducedSize.height();
// ReducedMatROI = new Rect(XReduced, YReduced, WReduced, HReduced);
// if (printdebug){
// System.out.println("scaleXReduced = "+scaleXReduced+" scaleYReduced = "+scaleYReduced);
// System.out.println("ReducedMatROI camera "+cameratitle.getText()+" = "+RectToString(ReducedMatROI));
// }
// }
// }
//
// }
/**
* Detect QR Code from Mat
* @param graymat Mat in Gray Scale
* @param mat Mat in Gray Scale
* @return QR Code Text, or null if not detected
*/
private String DetectQRFromMat(UMat graymat){
private String DetectQRFromMat(Mat mat){
if (qrreader!=null){
Mat mat = new Mat();
graymat.copyTo(mat); // back to CPU, because zxing only accept BufferedImage
if (mat!=null && !mat.empty()){
BufferedImage bufferedImage = matToBufferedImage(mat);
String title = cameratitle.getText();
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(bufferedImage)));
try{
Result result = qrreader.decode(binaryBitmap);
@@ -1366,6 +1405,8 @@ public class Cameradetail {
}
mat.release();
}
}
return null;
}

View File

@@ -220,7 +220,7 @@ public class CaptureView {
@Override
public PhotoResult call() {
if (image!=null){
image.RemapROI(0.1, 0.3, false);
//image.RemapROI(0.1, 0.3, false);
double sharpness = CalculateSharpness(image.getGrayMat());
image.setSharpness_indicator(sharpness);
PhotoResult p = image.TakePhoto(directory, prefix);
@@ -477,7 +477,7 @@ public class CaptureView {
String[] files = prc.compressed();
if (files.length>0){
AutoCloseAlert.showpictures(prc.compressed(),3, (s)->{
AutoCloseAlert.showpictures(prc.compressedcrop(),3, (s)->{
if (AutoCloseAlert.banner_02!=null) {
AutoCloseAlert.showbanner(AutoCloseAlert.banner_02, 0, null);
@@ -510,7 +510,7 @@ public class CaptureView {
}
private void UploadFiles(PhotoReviewClass prc, String prefix){
String[] files = prc.compressed();
String[] files = prc.compressedcrop();
if (files.length>0){
InsertSQL(prc);
@@ -1096,7 +1096,7 @@ public class CaptureView {
};
image.setCameraStatus("Camera Starting");
if (image.StartLiveView(lce, title, use_qr_detector, use_face_detector)){
Runtime.getRuntime().addShutdownHook(new Thread(image::Release));
//Runtime.getRuntime().addShutdownHook(new Thread(image::Release));
} else image.setCameraStatus("Unable to Set Grabber");
} else image.setCameraStatus("Camera not found, please check setting");
}

View File

@@ -24,8 +24,14 @@ public class DetectorResult {
Eyes.add(eye);
}
// trouble di sini
public void FaceRectangle(UMat mat){
if (mat == null || mat.empty()) return;
if (Face == null || Face.width() <= 0 || Face.height() <= 0) return;
if (Face.x() < 0 || Face.y() < 0) return; // ignore negative coordinates
if (Face.x() + Face.width() > mat.cols() || Face.y() + Face.height() > mat.rows()) return; // ignore out of bounds
if (haveFace()){
try{
rectangle(mat, Face, Scalar.GREEN, linethickness, linetype, lineshift);
@@ -33,9 +39,17 @@ public class DetectorResult {
}
}
// trouble di sini
public void EyesRectangle(UMat mat){
if (mat == null || mat.empty()) return;
if (haveEyes()){
for(Rect eye : Eyes){
if (eye == null || eye.width() <= 0 || eye.height() <= 0) continue;
if (eye.x() < 0 || eye.y() < 0) continue; // ignore negative coordinates
if (eye.x() + eye.width() > mat.cols() || eye.y() + eye.height() > mat.rows()) continue; // ignore out of bounds
try{
rectangle(mat, eye, Scalar.BLUE);

View File

@@ -84,7 +84,7 @@ public class Detectors {
* @param graymat Mat in Gray Scale
* @return List of Rect if face detected, otherwise empty list
*/
public static @NonNull List<DetectorResult> HaveFrontalFace(UMat graymat){
public static @NonNull List<DetectorResult> HaveFrontalFace(Mat graymat){
List<DetectorResult> result = new ArrayList<>();
RectVector faces = DetectFrontalFace(graymat);
if (faces!=null && faces.size()>0){
@@ -106,7 +106,7 @@ public class Detectors {
return result;
}
public static @NonNull List<DetectorResult> HaveLeft45Face(UMat graymat){
public static @NonNull List<DetectorResult> HaveLeft45Face(Mat graymat){
List<DetectorResult> result = new ArrayList<>();
RectVector faces = DetectProfileFace(graymat);
if (faces!=null && faces.size()>0){
@@ -160,7 +160,7 @@ public class Detectors {
}
public static RectVector DetectProfileFace(UMat graymat){
public static RectVector DetectProfileFace(Mat graymat){
return Detect(graymat, profilefaceDetector, scaleFactor, minNeighbors, flags, FaceminSize, FacemaxSize);
}
@@ -169,7 +169,7 @@ public class Detectors {
* @param graymat Mat in Gray Scale
* @return RectVector if face detected, otherwise null
*/
public static RectVector DetectFrontalFace(UMat graymat){
public static RectVector DetectFrontalFace(Mat graymat){
return Detect(graymat, frontalfaceDetector, scaleFactor, minNeighbors, flags, FaceminSize, FacemaxSize);
}
@@ -179,7 +179,7 @@ public class Detectors {
* @param graymat Mat in Gray Scale
* @return RectVector if eye detected, otherwise null
*/
public static RectVector DetectEye(UMat graymat, int facewidth){
public static RectVector DetectEye(Mat graymat, int facewidth){
//return Detect(graymat, eyeDetector);
int minwidth = (int)(facewidth*0.2);
int maxwidth = (int)(facewidth*0.4);
@@ -189,26 +189,26 @@ public class Detectors {
}
@SuppressWarnings("SameParameterValue")
private static RectVector Detect(UMat graymat, CascadeClassifier detector, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize){
if (detector!=null){
if (graymat!=null && graymat.channels()==1){
if (!graymat.empty()){
if (minSize!=null){
if (maxSize!=null){
private static RectVector Detect(Mat graymat, CascadeClassifier detector, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize){
if (detector!=null && !detector.empty()){
if (graymat!=null && graymat.channels()==1 && !graymat.empty()){
if (minSize!=null && maxSize!=null){
if (minSize.width()<= maxSize.width() && minSize.height() <= maxSize.height()){
if (graymat.cols()> minSize.width() && graymat.rows() > minSize.height()) {
try {
RectVector detected = new RectVector();
// try defaulting minSize and maxSize
detector.detectMultiScale(graymat, detected, scaleFactor, minNeighbors, flags, minSize, maxSize);
return detected;
} catch (Exception e) {
System.out.println("Detectors Detect Error, Message : " + e.getMessage());
}
}
}
}
}
}
}
return null;

View File

@@ -15,7 +15,6 @@ import javafx.stage.Stage;
import org.tinylog.Logger;
import java.io.IOException;
import java.util.Map;
import static Config.SomeCodes.ShowAlert;
import static Config.SomeCodes.config;
@@ -50,7 +49,7 @@ public class MainApplication extends Application {
Screen screen = Screen.getPrimary();
Rectangle2D screenbound = screen.getBounds();
Scene scene = new Scene(fxmlLoader.load(), screenbound.getWidth(), screenbound.getHeight());
stage.setTitle("MultiCam Capture App for ERHA 26052025-001");
stage.setTitle("MultiCam Capture App for ERHA 27052025-005");
stage.setScene(scene);
stage.setResizable(true);
stage.setMaximized(true);