Skip to content

Commit

Permalink
bug fix, more dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Microos committed Apr 9, 2017
1 parent fa1495e commit 2e90835
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/hk/microos/data/Ellipse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

}
1 change: 0 additions & 1 deletion src/hk/microos/data/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/hk/microos/data/MyImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
61 changes: 34 additions & 27 deletions src/hk/microos/frames/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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();

}
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/hk/microos/frames/MyImagePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down
9 changes: 6 additions & 3 deletions src/hk/microos/tools/IOTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static HashMap<String, ArrayList<Ellipse>> readAnnotationFile(File f, Str

ArrayList<Ellipse> elpses = null;
try {
elpses = readNEllipse(lines, at, detNum);
elpses = readEllipse(lines, at, detNum);

} catch (Exception e) {
throw new Exception(e.getMessage());
Expand All @@ -156,7 +156,7 @@ public static HashMap<String, ArrayList<Ellipse>> readAnnotationFile(File f, Str
return map;
}

private static ArrayList<Ellipse> readNEllipse(ArrayList<String> lines, int start, int num) throws Exception {
private static ArrayList<Ellipse> readEllipse(ArrayList<String> lines, int start, int num) throws Exception {
ArrayList<Ellipse> elps = new ArrayList<>();
for (int i = 0; i < num; i++) {
int at = start + i;
Expand All @@ -183,7 +183,7 @@ public static void outputEllipse(HashMap<String, MyImage> 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;
Expand All @@ -193,6 +193,8 @@ public static void outputEllipse(HashMap<String, MyImage> 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)
Expand All @@ -201,6 +203,7 @@ public static void outputEllipse(HashMap<String, MyImage> 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);
Expand Down

0 comments on commit 2e90835

Please sign in to comment.