Skip to content

Commit dcfe032

Browse files
committed
almost done!
1 parent ff816b8 commit dcfe032

6 files changed

Lines changed: 121 additions & 89 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- [x] basic functions
55
- [x] ask for prefix and suffix when load imglist
66
- [x] shift choose on ellipse -> highlight right table row
7-
- [ ] click on right table row(if static) -> enlarge stroke
7+
- [x] click on right table row(if static) -> enlarge stroke
88
- [x] click on right table row(if non-static) -> set as activated ellipse
99
- [x] load imglist -> disable load img button
1010
- [x] one click after load -> disable load annotation button

src/hk/microos/data/Flags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package hk.microos.data;
22

33
public class Flags {
4-
public static boolean GLOABAL_DEBUG = false;
4+
public static boolean GLOABAL_DEBUG = true;
55
public static boolean FUNC_INVOKE_PRINT = true;
66
public static double minStroke = 2;
77
public static double maxStroke = 5;

src/hk/microos/frames/MainFrame.java

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void run() {
107107
* Create the frame.
108108
*/
109109
public MainFrame() {
110+
setResizable(false);
111+
setTitle("Face Annotation Tool");
110112
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
111113
setBounds(100, 100, 1195, 601);
112114
contentPane = new JPanel();
@@ -124,36 +126,41 @@ public MainFrame() {
124126
JScrollPane rightScrollPanel = new JScrollPane();
125127

126128
GroupLayout gl_contentPane = new GroupLayout(contentPane);
127-
gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane
128-
.createSequentialGroup()
129-
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
130-
.addComponent(toolPanel, GroupLayout.DEFAULT_SIZE, 1173, Short.MAX_VALUE)
131-
.addGroup(gl_contentPane.createSequentialGroup().addGap(3)
132-
.addComponent(leftScrollPanel, GroupLayout.PREFERRED_SIZE, 230,
133-
GroupLayout.PREFERRED_SIZE)
134-
.addPreferredGap(ComponentPlacement.RELATED)
135-
.addComponent(scrollPanel, GroupLayout.PREFERRED_SIZE, 643, GroupLayout.PREFERRED_SIZE)
136-
.addPreferredGap(ComponentPlacement.RELATED).addComponent(rightScrollPanel,
137-
GroupLayout.PREFERRED_SIZE, 286, GroupLayout.PREFERRED_SIZE)))
138-
.addContainerGap()));
139-
gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING).addGroup(gl_contentPane
140-
.createSequentialGroup()
141-
.addComponent(toolPanel, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
142-
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
143-
.addGroup(gl_contentPane.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED)
144-
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
145-
.addComponent(leftScrollPanel, GroupLayout.PREFERRED_SIZE, 516,
146-
GroupLayout.PREFERRED_SIZE)
147-
.addComponent(scrollPanel, GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)))
148-
.addGroup(gl_contentPane.createSequentialGroup().addGap(14).addComponent(rightScrollPanel,
149-
GroupLayout.PREFERRED_SIZE, 505, GroupLayout.PREFERRED_SIZE)))
150-
.addContainerGap()));
129+
gl_contentPane.setHorizontalGroup(
130+
gl_contentPane.createParallelGroup(Alignment.LEADING)
131+
.addGroup(gl_contentPane.createSequentialGroup()
132+
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
133+
.addComponent(toolPanel, GroupLayout.DEFAULT_SIZE, 1174, Short.MAX_VALUE)
134+
.addGroup(gl_contentPane.createSequentialGroup()
135+
.addGap(3)
136+
.addComponent(leftScrollPanel, GroupLayout.PREFERRED_SIZE, 230, GroupLayout.PREFERRED_SIZE)
137+
.addPreferredGap(ComponentPlacement.RELATED)
138+
.addComponent(scrollPanel, GroupLayout.PREFERRED_SIZE, 643, GroupLayout.PREFERRED_SIZE)
139+
.addPreferredGap(ComponentPlacement.RELATED)
140+
.addComponent(rightScrollPanel, GroupLayout.PREFERRED_SIZE, 286, GroupLayout.PREFERRED_SIZE)))
141+
.addContainerGap())
142+
);
143+
gl_contentPane.setVerticalGroup(
144+
gl_contentPane.createParallelGroup(Alignment.TRAILING)
145+
.addGroup(gl_contentPane.createSequentialGroup()
146+
.addComponent(toolPanel, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
147+
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
148+
.addGroup(gl_contentPane.createSequentialGroup()
149+
.addPreferredGap(ComponentPlacement.RELATED)
150+
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
151+
.addComponent(leftScrollPanel, GroupLayout.PREFERRED_SIZE, 516, GroupLayout.PREFERRED_SIZE)
152+
.addComponent(scrollPanel, GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)))
153+
.addGroup(gl_contentPane.createSequentialGroup()
154+
.addGap(14)
155+
.addComponent(rightScrollPanel, GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)))
156+
.addContainerGap())
157+
);
151158

152159
button = new JButton("TEST");
160+
button.setVisible(false);
153161
button.addActionListener(new ActionListener() {
154162
public void actionPerformed(ActionEvent e) {
155-
imgListTH.tm.setRowCount(0);
156-
System.out.println("src = 0");
163+
coordListTH.clearAll();
157164
}
158165
});
159166
toolPanel.add(button);
@@ -207,7 +214,7 @@ public void mouseMoved(MouseEvent e) {
207214
}
208215
});
209216
imagePanel.setForeground(Color.WHITE);
210-
imagePanel.setBackground(Color.ORANGE);
217+
imagePanel.setBackground(new Color(250, 250, 210));
211218

212219
imagePanel.setSize(1, 1);
213220
scrollPanel.setViewportView(imagePanel);
@@ -245,7 +252,9 @@ public void valueChanged(ListSelectionEvent e) {
245252
void rightTableOnClick(ListSelectionEvent e){
246253
if (e.getValueIsAdjusting())
247254
return;
255+
248256
int rowIdx = coordListTH.getSelectedRowIndex();
257+
249258
cm.clickOnRightTable(rowIdx);
250259
}
251260
void leftTableOnClick(ListSelectionEvent e) {
@@ -270,15 +279,14 @@ void setRightPanelCoords(MyImage mim) {
270279
//call this will update right panel with image's staticEllipse/Ellipse
271280
//use null as the arg will use a selectedRow as target image
272281
if (mim == null) {
273-
System.out.println("setRightPanelCoords with null");
274282
if (leftTableSelectedRow == -1) {
275-
System.err.println("bad0 at setRightPanelCoords");
283+
System.err.println("bad-0 at setRightPanelCoords");
276284
return;
277285
}
278286
String p = imgListTH.getBehindRowDataAt(leftTableSelectedRow);
279287
mim = pathImgPair.get(p);
280288
if (mim == null) {
281-
System.err.println("bad1 at setRightPanelCoords");
289+
System.err.println("bad-1 at setRightPanelCoords");
282290
return;
283291
}
284292

@@ -333,6 +341,7 @@ void loadImageList() {
333341

334342
pathImgPair = IOTool.filterImageList(imgList, this);
335343
if(pathImgPair.size() == 0){
344+
pathImgPair = null;
336345
return;
337346
}
338347
fillImageNameTable();
@@ -474,12 +483,6 @@ public void marksUpdatedAtSelectedImage(MyImage mim) {
474483
if (leftTableSelectedRow == -1) {
475484
System.err.println("marking on non-loaded image?");
476485
}
477-
// if(mim == null){
478-
// String p = imgListTH.getBehindRowDataAt(leftTableSelectedRow);
479-
// mim = pathImgPair.get(p);
480-
// if(mim == null) System.err.println("bad at marksUpdatedAtSelected");
481-
// return;
482-
// }
483486
imgListTH.setValueAt(leftTableSelectedRow, 2, mim.getMarkNumString());
484487
setRightPanelCoords(mim);
485488
}

src/hk/microos/frames/MyImagePanel.java

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class MyImagePanel extends JPanel {
4646
private ArrayList<Point_> unfinished = new ArrayList<>();
4747
// closest
4848
private int activedEllipseIdx = -1;
49-
49+
private int highlightedStaticEllipseIdx = -1;
5050
public MyImagePanel(MainFrame mainFrame, JScrollPane fatherPanel) {
5151
this.mainFrame = mainFrame;
5252

@@ -64,6 +64,8 @@ public boolean setCurrentImage(MyImage myImg) {
6464
}
6565
this.mImg = myImg;
6666
this.inited = true;
67+
activedEllipseIdx = -1;
68+
highlightedStaticEllipseIdx = -1;
6769
this.repaint();
6870
return true;
6971
}
@@ -128,8 +130,12 @@ public void drawStaticEllipses(Graphics2D g2d) {
128130
// draw elps
129131

130132
Ellipse2D.Double ed = e.getErectedEllipse2D();
131-
132-
g2d.setColor(Color.black);
133+
if(i == highlightedStaticEllipseIdx){
134+
g2d.setColor(Color.red);
135+
}else{
136+
g2d.setColor(Color.black);
137+
}
138+
133139
g2d.setStroke(bs);
134140
g2d.draw(ed);
135141

@@ -203,8 +209,11 @@ public void drawUnfinishedPoints(Graphics2D g2d) {
203209
}
204210

205211
public void drawElps(Graphics2D g2d, ArrayList<Ellipse> elpses) {
206-
if (!unfinished.isEmpty())
212+
if (!unfinished.isEmpty()){
207213
this.activedEllipseIdx = -1;
214+
mainFrame.coordListTH.deselect();
215+
}
216+
208217
AffineTransform old = g2d.getTransform();
209218
// -----------------------------------------//
210219

@@ -253,24 +262,27 @@ public void updateStatus() {
253262
waitLastPoint = true;
254263
ll = new LinearLine(unfinished.get(0), unfinished.get(1));
255264
}
265+
int idx = -1;
256266
if (unfinishedSize == 3) {
257267
Ellipse e = new Ellipse(unfinished.get(0), unfinished.get(1), this.projPoint);
258268
e.setOffsetForTableDisplay(this.minX, this.minY);
259269
mImg.addElps(e);
260270
Flags.numNewEllipse++;
261271
unfinished = new ArrayList<>();
262272
this.activedEllipseIdx = mImg.getElpses().size() - 1;
263-
264-
}
265-
mainFrame.marksUpdatedAtSelectedImage(this.mImg);
266-
if (unfinishedSize == 3) {
267-
mainFrame.coordListTH.rightPanelSetSelectedLine(this.activedEllipseIdx + getStaticEllipsesCount());
273+
274+
idx = this.activedEllipseIdx + getStaticEllipsesCount();
275+
mainFrame.marksUpdatedAtSelectedImage(this.mImg);
276+
mainFrame.coordListTH.rightPanelSetSelectedLine(idx);
268277
}
278+
279+
269280
repaint();
270281
}
271282

272283
public void addUnfinishedPoint(Point_ p) {
273284
mainFrame.freezeReadAnnotationBtn();
285+
this.highlightedStaticEllipseIdx = -1;
274286
unfinished.add(p);
275287
updateStatus();
276288
}
@@ -283,11 +295,13 @@ public void activateClosest(int x, int y) {
283295
}
284296
Point_ p = new Point_(x, y);
285297
this.activedEllipseIdx = findTheClosestEllipse(p);
298+
this.highlightedStaticEllipseIdx = -1;
286299
mainFrame.coordListTH.rightPanelSetSelectedLine(this.activedEllipseIdx + getStaticEllipsesCount());
287300
this.repaint();
288301
}
289302

290303
public void removeActived() {
304+
291305
if (unfinished.size() != 0) {
292306
// cannot remove any ellipse, just remove unfinished point
293307
unfinished.remove(unfinished.size() - 1);
@@ -302,11 +316,16 @@ public void removeActived() {
302316
unfinished.add(keyPoints.get(1));
303317
}
304318
}
319+
305320
updateStatus();
321+
mainFrame.marksUpdatedAtSelectedImage(mImg);
322+
323+
this.highlightedStaticEllipseIdx = -1;
324+
this.repaint();
306325
}
307326

308327
public int findTheClosestEllipse(Point_ p) {
309-
// return index
328+
// return the closet ellipse's index
310329
double minDis = Double.MAX_VALUE;
311330
int minIdx = -1;
312331
ArrayList<Ellipse> elpses = mImg.getElpses();
@@ -322,35 +341,24 @@ public int findTheClosestEllipse(Point_ p) {
322341
}
323342

324343
public void setActivatedIndex(int rowIdx) {
325-
rowIdx -= getStaticEllipsesCount();
326-
if (rowIdx >= 0 && unfinished.size() == 0) {
327-
activedEllipseIdx = rowIdx;
328-
this.repaint();
344+
if(rowIdx < 0) {
345+
highlightedStaticEllipseIdx =-1;
346+
repaint();
347+
return;
348+
}
349+
highlightedStaticEllipseIdx = -1;
350+
int seCount = getStaticEllipsesCount();
351+
if (rowIdx -seCount >= 0 && unfinished.size() == 0) {
352+
activedEllipseIdx = rowIdx-seCount;
353+
329354
}else{
355+
356+
highlightedStaticEllipseIdx =rowIdx;
330357
activedEllipseIdx = -1;
331358
}
359+
this.repaint();
332360
}
333361

334-
public void reset() {
335-
if (!isInited())
336-
return;
337-
mImg = null;
338-
inited = false;
339-
minX = 0;
340-
minY = 0;
341-
maxX = 0;
342-
maxY = 0;
343-
344-
// used in 2-point live draw
345-
waitLastPoint = false;
346-
LinearLine ll = null;
347-
perpendicularConstrainX = 0;
348-
perpendicularConstrainY = 0;
349-
Point_ projPoint = null;
350-
unfinished = new ArrayList<>();
351-
// closest
352-
activedEllipseIdx = -1;
353-
}
354362

355363
public boolean isInited() {
356364
return inited;

src/hk/microos/tools/IOTool.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,42 @@ public static ArrayList<String> readText(File f) {
5353
public static HashMap filterImageList(ArrayList<String> list, JFrame dialogFatherFrame) {
5454
HashMap<String, MyImage> map = new HashMap<>();
5555
ArrayList<String> failed = new ArrayList<>();
56+
int failedNum = 0;
5657
for (String l : list) {
58+
if(l.trim().equals("")){
59+
continue;
60+
}
5761
if (!new File(l).exists()) {
58-
59-
failed.add(l);
62+
failedNum++;
63+
if (failed.size() < 10) {
64+
failed.add(l);
65+
}
66+
6067
continue;
6168
}
6269
map.put(l, null);
6370
}
64-
71+
if (map.size() == 0) {
72+
JOptionPane.showMessageDialog(dialogFatherFrame,
73+
"None of the images found from paths listed in the seletced file.\nPlease check your file and try again.",
74+
"All failed", JOptionPane.WARNING_MESSAGE);
75+
return map;
76+
}
6577
if (failed.size() != 0) {
66-
String s = String.join("\n", failed);
67-
JOptionPane.showMessageDialog(dialogFatherFrame, String.format("Existing check failed files:\n%s", s),
68-
"Existing check failed files", JOptionPane.WARNING_MESSAGE);
78+
String s = "";
79+
if (failed.size() != failedNum) {
80+
s = String.format("Existence checking failed paths(%d listed, %d in total):\n", failed.size(),
81+
failedNum);
82+
} else {
83+
s = String.format("Existence checking failed paths(total: %d):\n", failed.size());
84+
}
85+
int i = 1;
86+
for (String f : failed) {
87+
s += String.format("%2d [%s]\n", i, f);
88+
i++;
89+
}
90+
JOptionPane.showMessageDialog(dialogFatherFrame, s, "Existence checking failed paths",
91+
JOptionPane.WARNING_MESSAGE);
6992
}
7093
return map;
7194
}
@@ -170,12 +193,13 @@ public static void outputEllipse(HashMap<String, MyImage> pathImgPair, String ou
170193
MyImage mim = UniversalTool.getMyImageFromPathImgPair(p, pathImgPair);
171194
String s = mim.getOutputString(withBoth);
172195
sb.append(s);
173-
if(!s.equals("")){
174-
numImage ++;
175-
numAnnot+= s.split("\n").length-2;
196+
if (!s.equals("")) {
197+
numImage++;
198+
numAnnot += s.split("\n").length - 2;
176199
}
177200
}
178201
writeFile(f, sb.toString());
179-
JOptionPane.showMessageDialog(dialogFatherFrame, String.format("%d annotations from %d images \nhave been written to %s", numAnnot,numImage, f.getAbsolutePath()));
202+
JOptionPane.showMessageDialog(dialogFatherFrame, String.format(
203+
"%d annotations from %d images \nhave been written to %s", numAnnot, numImage, f.getAbsolutePath()));
180204
}
181205
}

0 commit comments

Comments
 (0)