From 2e908355ef6bd8279d6d70aa2c4b467c5d6cd5ea Mon Sep 17 00:00:00 2001 From: YiLiangXie Date: Sun, 9 Apr 2017 10:46:39 +0800 Subject: [PATCH] bug fix, more dialogs --- src/hk/microos/data/Ellipse.java | 5 +- src/hk/microos/data/Flags.java | 1 - src/hk/microos/data/MyImage.java | 1 - src/hk/microos/frames/MainFrame.java | 61 ++++++++++++++----------- src/hk/microos/frames/MyImagePanel.java | 2 +- src/hk/microos/tools/IOTool.java | 9 ++-- 6 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/hk/microos/data/Ellipse.java b/src/hk/microos/data/Ellipse.java index 35e6cb3..ef4ace8 100644 --- a/src/hk/microos/data/Ellipse.java +++ b/src/hk/microos/data/Ellipse.java @@ -48,7 +48,8 @@ public Ellipse(Point_ mjA, Point_ mjB, Point_ miC) { keyPts.add(miC); keyPts.add(new Point_(this.x, this.y)); } - public void setOffsetForTableDisplay(double ofx, double ofy){ + public void setOffsetForTableDisplayAndOutput(double ofx, double ofy){ + //only new added ellipse will need this this.offsetX = ofx; this.offsetY = ofy; } @@ -96,7 +97,7 @@ public String toRowFormatString() { public String toOutputFormatString(){ //major minor angle x y 1 String fmt = "%.6f %.6f %.6f %.6f %.6f 1"; - return String.format(fmt,this.major, this.minor, this.angle, this.x, this.y); + return String.format(fmt,this.major, this.minor, this.angle, this.x-offsetX, this.y-offsetY); } } diff --git a/src/hk/microos/data/Flags.java b/src/hk/microos/data/Flags.java index 8cfa30f..842e134 100644 --- a/src/hk/microos/data/Flags.java +++ b/src/hk/microos/data/Flags.java @@ -2,7 +2,6 @@ public class Flags { public static boolean GLOABAL_DEBUG = false; - public static boolean FUNC_INVOKE_PRINT = true; public static double minStroke = 2; public static double maxStroke = 5; public static int numNewEllipse = 0; diff --git a/src/hk/microos/data/MyImage.java b/src/hk/microos/data/MyImage.java index 03b8881..0734a9d 100644 --- a/src/hk/microos/data/MyImage.java +++ b/src/hk/microos/data/MyImage.java @@ -105,7 +105,6 @@ public String getOutputString(boolean withBoth){ sb.append(elpse4Output.size()+"\n"); double[] offset = UniversalTool.getOffset(this); for(Ellipse e : elpse4Output){ - e = e.offset(-offset[0], -offset[1]); sb.append(e.toOutputFormatString()+"\n"); } return sb.toString(); diff --git a/src/hk/microos/frames/MainFrame.java b/src/hk/microos/frames/MainFrame.java index 4787943..ea3c678 100644 --- a/src/hk/microos/frames/MainFrame.java +++ b/src/hk/microos/frames/MainFrame.java @@ -37,6 +37,8 @@ import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; public class MainFrame extends JFrame { @@ -55,10 +57,10 @@ public class MainFrame extends JFrame { private JTable coordTable; public TableHelper imgListTH; public TableHelper coordListTH; - private String recordedImgPath = "/home/rick/Space/work/FDDB/data/Annotations"; + private String recordedImgPath = ""; - private String recordedAnnotPath = "/home/rick/Space/work/FDDB/data/Annotations"; - private String recordedSavePath = "/home/rick/Space/work/FDDB/data/Annotations"; + private String recordedAnnotPath = ""; + private String recordedSavePath = ""; private JButton btnReadImageList; private int leftTableSelectedRow = -1; @@ -79,15 +81,16 @@ public static void main(String[] args) { public void run() { try { MainFrame frame = new MainFrame(); - // frame.recordedOpenPath = - // System.getProperty("user.home")+"/Desktop"; - // frame.recordedImgPath = - // "/Users/microos/Downloads/originalPics/imgPath.txt"; + frame.recordedImgPath = System.getProperty("user.home")+"/Desktop"; +// frame.recordedImgPath = +// "/Users/microos/Downloads/originalPics/imgPath.txt"; - // frame.recordedAnnotPath = System.getProperty("user.home") - // + "/Desktop"; + frame.recordedAnnotPath = System.getProperty("user.home") + "/Desktop"; // frame.recordedAnnotPath = // "/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt"; + + frame.recordedSavePath = System.getProperty("user.home") + "/Desktop"; + frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); @@ -101,9 +104,22 @@ public void run() { * Create the frame. */ public MainFrame() { + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + if(Flags.numNewEllipse != 0){ + int op = JOptionPane.showConfirmDialog(MainFrame.this, "Do you want to exit?", "Exiting", JOptionPane.YES_NO_OPTION); + if(op == JOptionPane.YES_OPTION){ + System.exit(0); + } + }else{ + System.exit(0); + } + } + }); setResizable(false); setTitle("Face Annotation Tool"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setBounds(100, 100, 1195, 601); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); @@ -308,7 +324,6 @@ void updateImagePanelSize(MyImage mim) { void loadImageList() { JFileChooser fc = new JFileChooser(recordedImgPath); - // fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int res = fc.showOpenDialog(this); if (res == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); @@ -369,7 +384,6 @@ void loadAnnotList() { annotContentSuffix = s == null ? "" : s; } JFileChooser fc = new JFileChooser(recordedAnnotPath); - // fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int res = fc.showOpenDialog(this); if (res == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); @@ -429,37 +443,37 @@ void loadAnnotList() { // all failed - String m = "Did not found any matched images for the annotation file you selected.\n"; + String m = "Did not find any matching images for the annotation file you selected.\n"; m += "Please check the paths in your annotation file.\n"; m += "To match an annotation with a loaded image,\n"; - m += "make sure two paths are identical to each other.\n"; - m += "Maybe a carefully-set prefix and suffix will help."; + m += " make sure two paths are identical to each other.\n"; + m += "Maybe a carefully-set prefix and suffix will help.\n\n"; String p = annotContentPrefix == null ? "" : annotContentPrefix; String s = annotContentSuffix == null ? "" : annotContentSuffix; if (pathStaticElpsesPair != null && pathStaticElpsesPair.size() != 0) { - m += "\n\nCurrent path concatenated with prefix and sufix:\n"; + m += "Current path concatenated with prefix and sufix:\n"; m += String.format("Prefix = \"%s\"\n", p); m += String.format("Suffix = \"%s\"\n", s); m += ("Concatenated: "+pathStaticElpsesPair.keySet().iterator().next()); } else { - m += "\n\nYour current prefix and sufix:\n"; + m += "Your current prefix and suffix:\n"; m += String.format("Prefix = \"%s\"\n", p); m += String.format("Suffix = \"%s\"\n", s); } - JOptionPane.showMessageDialog(this, m, "Not found any matched annotations", + JOptionPane.showMessageDialog(this, m, "No matching annotations found", JOptionPane.WARNING_MESSAGE); annotContentPrefix = annotContentSuffix = null; pathStaticElpsesPair = null; return; } if(failedNum != 0){ - String m = "Did not found any match annotations for the following loaded images:\n"; + String m = "Did not find any matching annotations for the following loaded images:\n"; if(failed.size() < failedNum){ m += String.format("(%d listed, %d in total)\n", failed.size(), failedNum); }else{ - m += String.format("(num of images has no annotations: %d)\n", failed.size() ); + m += String.format("(num of images: %d)\n", failed.size() ); } int i = 1; for (String fal : failed) { @@ -474,10 +488,6 @@ void loadAnnotList() { imagePanel.repaint(); freezeReadAnnotationBtn(); JOptionPane.showMessageDialog(this, String.format("Load annotations for %d images.", foundNum)); - // // reset - // pathImgPair = null; - // leftTableSelectedRow = -1; - // imagePanel.reset(); } } @@ -492,8 +502,6 @@ void setImgPanelSize(int w, int h) { Dimension d = new Dimension(w, h); imagePanel.setSize(d); imagePanel.setPreferredSize(d); - // imagePanel.setMaximumSize(d); - // imagePanel.setMinimumSize(d); } void testSetBackgroundImage() { @@ -559,7 +567,6 @@ void outputAnnotations() { // ask: output only the new Ellipse or both new and static JFileChooser fc = new JFileChooser(recordedSavePath); - // fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int res = fc.showOpenDialog(this); if (res == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); diff --git a/src/hk/microos/frames/MyImagePanel.java b/src/hk/microos/frames/MyImagePanel.java index 548ecef..0009ae5 100644 --- a/src/hk/microos/frames/MyImagePanel.java +++ b/src/hk/microos/frames/MyImagePanel.java @@ -262,7 +262,7 @@ public void updateStatus() { int idx = -1; if (unfinishedSize == 3) { Ellipse e = new Ellipse(unfinished.get(0), unfinished.get(1), this.projPoint); - e.setOffsetForTableDisplay(this.minX, this.minY); + e.setOffsetForTableDisplayAndOutput(this.minX, this.minY); mImg.addElps(e); Flags.numNewEllipse++; unfinished = new ArrayList<>(); diff --git a/src/hk/microos/tools/IOTool.java b/src/hk/microos/tools/IOTool.java index b9bea74..0b57291 100644 --- a/src/hk/microos/tools/IOTool.java +++ b/src/hk/microos/tools/IOTool.java @@ -140,7 +140,7 @@ public static HashMap> readAnnotationFile(File f, Str ArrayList elpses = null; try { - elpses = readNEllipse(lines, at, detNum); + elpses = readEllipse(lines, at, detNum); } catch (Exception e) { throw new Exception(e.getMessage()); @@ -156,7 +156,7 @@ public static HashMap> readAnnotationFile(File f, Str return map; } - private static ArrayList readNEllipse(ArrayList lines, int start, int num) throws Exception { + private static ArrayList readEllipse(ArrayList lines, int start, int num) throws Exception { ArrayList elps = new ArrayList<>(); for (int i = 0; i < num; i++) { int at = start + i; @@ -183,7 +183,7 @@ public static void outputEllipse(HashMap pathImgPair, String ou int res = JOptionPane.showConfirmDialog(dialogFatherFrame, String.format("File %s exists, do you want to overwrite it?", f.getAbsolutePath()), "File exists", JOptionPane.YES_NO_OPTION); - if (res == JOptionPane.NO_OPTION) + if (res == JOptionPane.NO_OPTION || res == -1) return; } boolean withBoth = false; @@ -193,6 +193,8 @@ public static void outputEllipse(HashMap pathImgPair, String ou + "(Noted that a image without any annotation will not be included in the output file)", "", JOptionPane.NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] { "both loaded and marked annotations", "only annotations marked by me" }, 0); + if(res == -1) + return; if (res == 0) withBoth = true; if (res == 1) @@ -201,6 +203,7 @@ public static void outputEllipse(HashMap pathImgPair, String ou int numImage = 0; int numAnnot = 0; StringBuffer sb = new StringBuffer(); + for (String p : pathImgPair.keySet()) { MyImage mim = UniversalTool.getMyImageFromPathImgPair(p, pathImgPair); String s = mim.getOutputString(withBoth);