1 using System;
2 using System.IO;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Data;
6 using System.Drawing;
7 using System.Linq;
8 using System.Text;
9 using System.Threading.Tasks;
10 using System.Windows.Forms;
11 using System.Xml;
12
13 namespace Image_mark
14 {
15
16 public partial class Form1 : Form
17 {
18 // 我设置的全局变量
19 private List<string> all_picture_path = new List<string>();
20 private List<string> all_picture_name = new List<string>();
21 private string current_picture_path;
22 private int current_picture_index = 0; // 从1开始
23
24 private List<string> all_type_picture_path = new List<string>();
25 private string current_type_picture_path = "";
26
27 private List<string> all_join_picture_path = new List<string>();
28
29 private ImageList join_image_list = new ImageList();
30 private List<string> join_image_list_name = new List<string>();
31 private List<string> join_image_list_path = new List<string>();
32 private const int show_join_image_num = 4;
33 private Button[] show_join_image_button = new Button[show_join_image_num];
34
35 private int function_select = 0;
36 private const int BROW = 1;
37 private const int EYE = 2;
38 private const int NOSE = 3;
39 private const int MOUTH = 4;
40
41 private int xml_node_num = 0;
42 private bool load_xml_ok = false;
43
44 private string brow_tpye_path = @".\brow\";
45 private string eye_tpye_path = @".\eye\";
46 private string nose_tpye_path = @".\nose\";
47 private string mouth_tpye_path = @".\mouth\";
48
49 private Button[] type_button = new Button[20];
50 private const int type_button_WIDTH = 100;
51 private const int type_button_HEIGHT = 50;
52 private const int type_button_1_location_x = 450;
53 private const int type_button_1_location_y = 70;
54
55 Keys[] key_type = new Keys[9];
56
57
58 private Auto_size_form auto_size_form = new Auto_size_form();
59
60
61 #region 构造函数,初始化
62 public Form1()
63 {
64 InitializeComponent();
65
66 Init();
67
68 }
69 #endregion
70
71 private void Init()
72 {// 一些初始化
73
74 /*
75 // 显示方式
76 listView1.View = View.LargeIcon;
77 listView1.LabelEdit = false;
78 listView1.AllowColumnReorder = false;
79 listView1.CheckBoxes = false;
80 listView1.FullRowSelect = false;
81 listView1.GridLines = false;
82 //listView1.BorderStyle = BorderStyle.None;
83 listView1.Sorting = SortOrder.None;
84
85 // 最大值 256x256
86 join_image_list.ImageSize = new Size(listView1.Width/4, listView1.Height);
87 */
88
89 key_type[0] = Keys.NumPad7;
90 key_type[1] = Keys.NumPad8;
91 key_type[2] = Keys.NumPad9;
92 key_type[3] = Keys.NumPad4;
93 key_type[4] = Keys.NumPad5;
94 key_type[5] = Keys.NumPad6;
95 key_type[6] = Keys.NumPad1;
96 key_type[7] = Keys.NumPad2;
97 key_type[8] = Keys.NumPad3;
98
99 Set_show_join_image_button();
100
101
102 Using_select_picture_button(false);
103
104
105 }
106
107 private void Set_show_join_image_button()
108 {
109 int x = 10, y = 10;
110 int per_x_add = (this.groupBox2.Width - 10) / 4;
111 for (int i = 0; i < show_join_image_num; i++)
112 {
113 show_join_image_button[i] = new Button();
114 show_join_image_button[i].Location = new Point(x, y);
115 show_join_image_button[i].Size = new Size(per_x_add - 10, this.groupBox2.Height - 20);
116 show_join_image_button[i].BackgroundImageLayout = ImageLayout.Stretch;
117 show_join_image_button[i].Name = ("joinButton" + i.ToString());
118 //show_join_image_button[i].BackgroundImage = Image.FromFile(all_type_picture_path[i]);
119 show_join_image_button[i].Click += new System.EventHandler(this.join_image_button_Click);
120
121 this.groupBox2.Controls.Add(show_join_image_button[i]);
122
123 x += per_x_add;
124 }
125
126 }
127
128
129 #region 根据标记功能加载相应的 XML 文件 设置按钮
130 private void Load_xml_set_button()
131 {
132 XmlDocument xmlDoc = new XmlDocument();
133 XmlReaderSettings settings = new XmlReaderSettings();
134 settings.IgnoreComments = true;
135
136 OpenFileDialog openFileDialog1 = new OpenFileDialog();
137
138 openFileDialog1.InitialDirectory = @"E:\";
139 openFileDialog1.Filter = "xml files (*.xml)|*.xml";
140 openFileDialog1.RestoreDirectory = true;
141
142 // 先把之前的功能按钮释放
143 if(xml_node_num != 0)
144 {
145 for (int i = 0; i < xml_node_num; i++)
146 type_button[i].Dispose();
147 }
148
149 string xml_type = "";
150 switch(function_select)
151 {
152 case BROW:
153 {
154 xml_type = "brow";
155 current_type_picture_path = brow_tpye_path;
156 } break;
157 case EYE:
158 {
159 xml_type = "eye";
160 current_type_picture_path = eye_tpye_path;
161 } break;
162 case NOSE:
163 {
164 xml_type = "nose";
165 current_type_picture_path = nose_tpye_path;
166 } break;
167 case MOUTH:
168 {
169 xml_type = "mouth";
170 current_type_picture_path = mouth_tpye_path;
171 } break;
172 }
173
174 if ((openFileDialog1.ShowDialog() == DialogResult.OK) && (openFileDialog1.FileName != ""))
175 {
176 string xml_path = openFileDialog1.FileName;
177
178 XmlReader reader = XmlReader.Create(xml_path, settings);
179 xmlDoc.Load(reader);
180
181 if (xmlDoc.DocumentElement.ChildNodes.Count <= 0)
182 {
183 MessageBox.Show("该 xml 无配置信息,请重新选择");
184 return;
185 }
186 if (xmlDoc.DocumentElement.ChildNodes[0].Name != xml_type)
187 {
188 MessageBox.Show("该 xml 与标记功能不对应,请重新选择");
189 return;
190 }
191 }
192 else
193 {
194 return;
195 }
196
197 // 标记类型样本数量
198 xml_node_num = xmlDoc.DocumentElement.ChildNodes.Count;
199 load_xml_ok = true;
200
201 for (int i = 0; i < xml_node_num; i++)
202 {
203 switch (function_select)
204 {
205 case BROW:
206 {
207 all_type_picture_path.Add( brow_tpye_path +
208 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() +
209 ".jpg");
210
211 }
212 break;
213 case EYE:
214 {
215 all_type_picture_path.Add( eye_tpye_path +
216 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() +
217 ".jpg");
218 }
219 break;
220 case NOSE:
221 {
222 all_type_picture_path.Add( nose_tpye_path +
223 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() +
224 ".jpg");
225 }
226 break;
227 case MOUTH:
228 {
229 all_type_picture_path.Add( mouth_tpye_path +
230 ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString() +
231 ".jpg");
232 }
233 break;
234 default: break;
235 }
236 }
237
238 int x = 10, y = 20;
239 int per_x_add = (this.groupBox1.Width - 10) / 3;
240 int per_y_add = (this.groupBox1.Height - 20) / 3;
241 int x_button_num = 0;
242
243 for (int i = 0; i < xml_node_num; i++)
244 {
245 type_button[i] = new Button();
246 type_button[i].Location = new Point(x, y);
247 type_button[i].Size = new Size(per_x_add - 10, per_y_add - 10);
248 type_button[i].BackgroundImageLayout = ImageLayout.Stretch;
249 //type_button[i].Name = ("B" + i.ToString());
250 type_button[i].Name = ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString();
251 //type_button[i].Text = ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString();
252 type_button[i].BackgroundImage = Image.FromFile(all_type_picture_path[i]);
253 type_button[i].Click += new System.EventHandler(this.type_button_Click);
254
255 this.groupBox1.Controls.Add(type_button[i]);
256
257 x += per_x_add;
258 ++x_button_num;
259 if (x_button_num == 3)
260 {
261 x = 10;
262 x_button_num = 0;
263 y += per_y_add;
264 }
265
266 }
267
268 }
269 #endregion
270
271
272
273
274 #region 标记选项按钮消息
275 private void type_button_Click(object sender, EventArgs e)
276 {
277 //MessageBox.Show(((Button)sender).Text + " was clicked !");
278
279 //Select_one_type_button(sender);
280
281 if (Write_output_xml(sender) == 1)
282 {
283 for (int i = 0; i < xml_node_num; i++)
284 {
285 int len = all_type_picture_path[i].Length - current_type_picture_path.Length;
286 if (all_type_picture_path[i].Substring(all_type_picture_path[i].Length - len, len) ==
287 (((Button)sender).Name + ".jpg"))
288 {
289 // 拼接图片
290 Join_image(sender, all_picture_path[current_picture_index - 1], all_type_picture_path[i]);
291
292
293 Show_join_image_in_button();
294 }
295
296 }
297 }
298
299 Next_picture();
300
301 }
302 #endregion
303
304 #region 写图片信息到 xml 输出文件
305 // 返回 0 表示已经标记过
306 private int Write_output_xml(object sender)
307 {
308 if (!File.Exists(@"output.xml"))
309 {
310 XmlTextWriter output_xml = new XmlTextWriter("output.xml", Encoding.UTF8);
311 output_xml.Formatting = Formatting.Indented;
312 output_xml.WriteStartDocument(false);
313
314 output_xml.WriteStartElement("图片标记信息");
315
316 output_xml.WriteComment("这是使用软件标记后输出的图片信息");
317
318 output_xml.WriteEndElement();
319
320 output_xml.Flush();
321 output_xml.Close();
322 }
323
324 XmlDocument xmldoc = new XmlDocument();
325 xmldoc.Load("output.xml");
326
327 XmlNode root = xmldoc.SelectSingleNode("图片标记信息");
328
329 switch(function_select)
330 {
331 case BROW:
332 {
333 if(if_mark_the_picture(root, function_select))
334 {
335 MessageBox.Show("该图片此类型已经标记过");
336 return 0;
337 }
338
339 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加
340 XmlNodeList nodelist = root.ChildNodes;
341 if (nodelist.Count > 0)
342 {
343 foreach (XmlNode node1 in nodelist)
344 {
345 if (node1.Name == all_picture_name[current_picture_index - 1])
346 {
347 node1.Attributes["brow_type"].Value = ((Button)sender).Name;
348
349 xmldoc.Save("output.xml");
350
351 return 1;
352 }
353 }
354 }
355
356 //创建一个<Node>节点
357 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]);
358
359 //设置该节点 type 属性
360 xe1.SetAttribute("brow_type", ((Button)sender).Name);
361
362 if (xe1.Attributes["eye_type"] == null)
363 xe1.SetAttribute("eye_type", "");
364 if (xe1.Attributes["nose_type"] == null)
365 xe1.SetAttribute("nose_type", "");
366 if (xe1.Attributes["mouth_type"] == null)
367 xe1.SetAttribute("mouth_type", "");
368
369 //添加到<图片标记信息>节点中
370 root.AppendChild(xe1);
371
372 xmldoc.Save("output.xml");
373
374 }
375 break;
376 case EYE:
377 {
378 if (if_mark_the_picture(root, function_select))
379 {
380 MessageBox.Show("该图片此类型已经标记过");
381 return 0;
382 }
383
384 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加
385 XmlNodeList nodelist = root.ChildNodes;
386 if (nodelist.Count > 0)
387 {
388 foreach (XmlNode node1 in nodelist)
389 {
390 if (node1.Name == all_picture_name[current_picture_index - 1])
391 {
392 node1.Attributes["eye_type"].Value = ((Button)sender).Name;
393
394 xmldoc.Save("output.xml");
395
396 return 1;
397 }
398 }
399 }
400
401 //创建一个<Node>节点
402 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]);
403
404 //设置该节点 type 属性
405 if (xe1.Attributes["brow_type"] == null)
406 xe1.SetAttribute("brow_type", "");
407
408 xe1.SetAttribute("eye_type", ((Button)sender).Name);
409
410 if (xe1.Attributes["nose_type"] == null)
411 xe1.SetAttribute("nose_type", "");
412 if (xe1.Attributes["mouth_type"] == null)
413 xe1.SetAttribute("mouth_type", "");
414
415 //添加到<图片标记信息>节点中
416 root.AppendChild(xe1);
417
418 xmldoc.Save("output.xml");
419
420 }
421 break;
422 case NOSE:
423 {
424 if (if_mark_the_picture(root, function_select))
425 {
426 MessageBox.Show("该图片此类型已经标记过");
427 return 0;
428 }
429
430 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加
431 XmlNodeList nodelist = root.ChildNodes;
432 if (nodelist.Count > 0)
433 {
434 foreach (XmlNode node1 in nodelist)
435 {
436 if (node1.Name == all_picture_name[current_picture_index - 1])
437 {
438 node1.Attributes["nose_type"].Value = ((Button)sender).Name;
439
440 xmldoc.Save("output.xml");
441
442 return 1;
443 }
444 }
445 }
446
447 //创建一个<Node>节点
448 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]);
449
450 //设置该节点 type 属性
451
452 if (xe1.Attributes["brow_type"] == null)
453 xe1.SetAttribute("brow_type", "");
454 if (xe1.Attributes["eye_type"] == null)
455 xe1.SetAttribute("eye_type", "");
456
457 xe1.SetAttribute("nose_type", ((Button)sender).Name);
458
459 if (xe1.Attributes["mouth_type"] == null)
460 xe1.SetAttribute("mouth_type", "");
461
462 //添加到<图片标记信息>节点中
463 root.AppendChild(xe1);
464
465 xmldoc.Save("output.xml");
466
467 }
468 break;
469 case MOUTH:
470 {
471 if (if_mark_the_picture(root, function_select))
472 {
473 MessageBox.Show("该图片此类型已经标记过");
474 return 0;
475 }
476
477 // 查找xml中是否有当前图片信息,有的话不要创建节点,直接添加
478 XmlNodeList nodelist = root.ChildNodes;
479 if (nodelist.Count > 0)
480 {
481 foreach (XmlNode node1 in nodelist)
482 {
483 if (node1.Name == all_picture_name[current_picture_index - 1])
484 {
485 node1.Attributes["mouth_type"].Value = ((Button)sender).Name;
486
487 xmldoc.Save("output.xml");
488
489 return 1;
490 }
491 }
492 }
493
494 //创建一个<Node>节点
495 XmlElement xe1 = xmldoc.CreateElement(all_picture_name[current_picture_index - 1]);
496
497 //设置该节点 type 属性
498
499 if (xe1.Attributes["brow_type"] == null)
500 xe1.SetAttribute("brow_type", "");
501 if (xe1.Attributes["eye_type"] == null)
502 xe1.SetAttribute("eye_type", "");
503 if (xe1.Attributes["nose_type"] == null)
504 xe1.SetAttribute("nose_type", "");
505
506 xe1.SetAttribute("mouth_type", ((Button)sender).Name);
507
508 //添加到<图片标记信息>节点中
509 root.AppendChild(xe1);
510
511 xmldoc.Save("output.xml");
512
513 }
514 break;
515 default: break;
516 }
517 return 1;
518 }
519 #endregion
520
521 #region 此图片该功能类型是否标记过 标记过的返回 true
522 private bool if_mark_the_picture(XmlNode root, int function)
523 {
524 //得到顶层节点列表
525 //XmlNodeList topM = xmld.DocumentElement.ChildNodes;
526
527 XmlNodeList nodelist = root.ChildNodes;
528 if (nodelist.Count > 0)
529 {
530 foreach(XmlNode node1 in nodelist)
531 {
532 if(node1.Name == all_picture_name[current_picture_index - 1])
533 {
534 switch (function)
535 {
536 case BROW:
537 {
538 if (node1.Attributes["brow_type"].Value != "")
539 return true;
540 }
541 break;
542 case EYE:
543 {
544 if (node1.Attributes["eye_type"].Value != "")
545 return true;
546 }
547 break;
548 case NOSE:
549 {
550 if (node1.Attributes["nose_type"].Value != "")
551 return true;
552 }
553 break;
554 case MOUTH:
555 {
556 if (node1.Attributes["mouth_type"].Value != "")
557 return true;
558 }
559 break;
560 default: break;
561
562 }
563 }
564 }
565 }
566 return false;
567
568 }
569 #endregion
570
571 #region 图片和标记样本 拼接 参数为图片绝对路径
572 private void Join_image(object sender, string picture_name1, string picture_name2)
573 {
574 int total_width = 0;
575 int total_height = 0;
576 int next_width = 0;
577
578 total_width = Image.FromFile(picture_name1).Width + Image.FromFile(picture_name2).Width;
579 // 选高度最高的
580 total_height = Image.FromFile(picture_name1).Height > Image.FromFile(picture_name2).Height ?
581 Image.FromFile(picture_name1).Height : Image.FromFile(picture_name2).Height;
582
583 next_width = Image.FromFile(picture_name1).Width;
584
585 Bitmap new_image = new Bitmap(total_width, total_height);
586 Graphics graph = Graphics.FromImage(new_image);
587 //初始化这个大图
588 graph.DrawImage(new_image, total_width, total_height);
589
590 graph.DrawImage(Image.FromFile(picture_name1), 0, 0, Image.FromFile(picture_name1).Width, Image.FromFile(picture_name1).Height);
591 graph.DrawImage(Image.FromFile(picture_name2), next_width, 0, Image.FromFile(picture_name2).Width, Image.FromFile(picture_name2).Height);
592
593 if (!Directory.Exists("join_image"))
594 {
595 Directory.CreateDirectory("join_image");
596 }
597
598 string new_image_name = "join_image\\" + picture_name1.Substring( (picture_name1.Length -
599 (picture_name1.Length - current_picture_path.Length)), picture_name1.Length - current_picture_path.Length) +
600 picture_name2.Substring( (picture_name2.Length -
601 (picture_name2.Length - current_type_picture_path.Length)), (picture_name2.Length - current_type_picture_path.Length));
602 // 保存拼接的图片
603 new_image.Save(new_image_name);
604
605 // 同时保存到 ImageList 中
606 //join_image_list.Images.Add(Image.FromFile(new_image_name));
607 join_image_list_path.Add(new_image_name);
608 join_image_list_name.Add(((Button)sender).Name);
609
610
611 }
612 #endregion
613
614
615 private void Show_join_image_in_button()
616 {
617 if (join_image_list_path.Count <= 0)
618 return;
619
620 else if (join_image_list_path.Count < 4)
621 {
622 int index = 0;
623 for (int i = join_image_list_path.Count - 1; i >= 0; i--)
624 {
625 show_join_image_button[index++].BackgroundImage = Image.FromFile(join_image_list_path[i]);
626
627 }
628 }
629 //else if(join_image_list_path.Count >= 4)
630 else
631 {
632 int index = 0;
633 for (int i = join_image_list_path.Count - 1; i >= join_image_list_path.Count - 4; i--)
634 {
635 show_join_image_button[index++].BackgroundImage = Image.FromFile(join_image_list_path[i]);
636
637 }
638
639 }
640
641 }
642
643 #region 选择某张最近标记的图片重新标记
644 private void join_image_button_Click(object sender, EventArgs e)
645 {
646
647
648
649
650
651 }
652 #endregion
653
654 #region 设置图片路径
655 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
656 {
657 current_picture_path = "";
658 all_picture_path.Clear();
659 all_picture_name.Clear();
660
661 FolderBrowserDialog FolderBrowserDialog1 = new FolderBrowserDialog();
662 FolderBrowserDialog1.Description = "请选择图片路径:";
663
664 if (FolderBrowserDialog1.ShowDialog() == DialogResult.OK)
665 {
666 current_picture_path = FolderBrowserDialog1.SelectedPath;
667
668 DirectoryInfo TheFolder = new DirectoryInfo(current_picture_path);
669 List<string> all = new List<string>();
670
671 foreach (FileInfo NextFile in TheFolder.GetFiles("*.jpg"))
672 {
673 all.Add(NextFile.Name);
674
675 }
676 foreach (FileInfo NextFile in TheFolder.GetFiles("*.bmp"))
677 {
678 all.Add(NextFile.Name);
679
680 }
681 foreach (FileInfo NextFile in TheFolder.GetFiles("*.png"))
682 {
683 all.Add(NextFile.Name);
684
685 }
686
687 if(all.Count > 0)
688 {
689 for (int i = 0; i < all.Count; i++)
690 {
691 all_picture_path.Add(current_picture_path + @"\" + all[i]);
692 all_picture_name.Add(all[i]);
693 }
694
695 current_picture_index = 1;
696
697 // 显示图片
698 pictureBox1.Load(all_picture_path[current_picture_index - 1]);
699
700 Using_select_picture_button(true);
701
702 }
703 else
704 {
705 MessageBox.Show("此路径下无图片,重新设置");
706 }
707
708 }
709 else
710 {
711 return;
712 }
713 }
714 #endregion
715
716 #region 上一张或下一张图片
717 private void buttonLeft_Click(object sender, EventArgs e)
718 {
719
720 if (current_picture_index > 1)
721 {
722 --current_picture_index;
723 }
724 else
725 current_picture_index = all_picture_path.Count;
726
727 pictureBox1.Load(all_picture_path[current_picture_index - 1]);
728
729 switch (function_select)
730 {
731 case BROW:
732 {
733 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片";
734 }
735 break;
736 case EYE:
737 {
738 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片";
739 }
740 break;
741 case NOSE:
742 {
743 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片";
744 }
745 break;
746 case MOUTH:
747 {
748 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片";
749 }
750 break;
751 default:
752 label1.Text = " 第 " + current_picture_index.ToString() + " 张图片";
753 break;
754 }
755
756 }
757
758 private void buttonRight_Click(object sender, EventArgs e)
759 {
760
761 if (current_picture_index < all_picture_path.Count )
762 {
763 ++current_picture_index;
764 }
765 else
766 current_picture_index = 1;
767
768 pictureBox1.Load(all_picture_path[current_picture_index - 1]);
769
770 switch(function_select)
771 {
772 case BROW:
773 {
774 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片";
775 }
776 break;
777 case EYE:
778 {
779 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片";
780 }
781 break;
782 case NOSE:
783 {
784 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片";
785 }
786 break;
787 case MOUTH:
788 {
789 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片";
790 }
791 break;
792 default:
793 label1.Text = " 第 " + current_picture_index.ToString() + " 张图片";
794 break;
795 }
796
797 }
798 #endregion
799
800 #region 下一张图片
801 private void Next_picture()
802 {
803 if (current_picture_index < all_picture_path.Count )
804 {
805 ++current_picture_index;
806 }
807 else
808 current_picture_index = 1;
809
810 pictureBox1.Load(all_picture_path[current_picture_index - 1]);
811
812 switch(function_select)
813 {
814 case BROW:
815 {
816 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片";
817 }
818 break;
819 case EYE:
820 {
821 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片";
822 }
823 break;
824 case NOSE:
825 {
826 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片";
827 }
828 break;
829 case MOUTH:
830 {
831 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片";
832 }
833 break;
834 default: break;
835 }
836
837 }
838 #endregion
839
840
841 #region 标记功能选择
842 private void 标记眉毛ToolStripMenuItem_Click(object sender, EventArgs e)
843 {
844 function_select = BROW;
845
846 if (all_picture_path.Count != 0)
847 {
848 label1.Text = "正在 标记眉毛...第 " + current_picture_index.ToString() + " 张图片";
849
850 }
851 else
852 {
853 MessageBox.Show("先设置图片路径");
854 return;
855 }
856
857 Load_xml_set_button();
858
859 }
860
861 private void 标记眼睛ToolStripMenuItem_Click(object sender, EventArgs e)
862 {
863
864 function_select = EYE;
865
866 if(all_picture_path.Count != 0)
867 {
868 label1.Text = "正在 标记眼睛...第 " + current_picture_index.ToString() + " 张图片";
869
870 }
871 else
872 {
873 MessageBox.Show("先设置图片路径");
874 return;
875 }
876
877 Load_xml_set_button();
878 }
879
880 private void 标记鼻子ToolStripMenuItem_Click(object sender, EventArgs e)
881 {
882 function_select = NOSE;
883
884 if (all_picture_path.Count != 0)
885 {
886 label1.Text = "正在 标记鼻子...第 " + current_picture_index.ToString() + " 张图片";
887
888 }
889 else
890 {
891 MessageBox.Show("先设置图片路径");
892 return;
893 }
894
895 Load_xml_set_button();
896 }
897
898 private void 标记嘴巴ToolStripMenuItem_Click(object sender, EventArgs e)
899 {
900 function_select = MOUTH;
901
902 if (all_picture_path.Count != 0)
903 {
904 label1.Text = "正在 标记嘴巴...第 " + current_picture_index.ToString() + " 张图片";
905
906 }
907 else
908 {
909 MessageBox.Show("先设置图片路径");
910 return;
911 }
912
913 Load_xml_set_button();
914 }
915 #endregion
916
917 #region 是否使图片选择按钮不可见
918 private void Using_select_picture_button(bool if_or_not)
919 {
920 if(if_or_not == true)
921 {
922 buttonLeft.Visible = true;
923 buttonRight.Visible = true;
924 }
925 else
926 {
927 buttonLeft.Visible = false;
928 buttonRight.Visible = false;
929 }
930
931 }
932 #endregion
933
934 #region 选择一种类型后,使该按钮禁用,使其它类型按钮不可见
935 private void Select_one_type_button(object sender)
936 {
937 for(int i=0;i < xml_node_num; i++)
938 {
939 if(type_button[i].Name == ((Button)sender).Name)
940 {
941 type_button[i].Enabled = false;
942
943 }
944 else
945 {
946 type_button[i].Visible = false;
947 }
948 }
949
950 }
951 #endregion
952
953 #region 使所有类型按钮可用可见
954 private void All_type_button_ok()
955 {
956 if (xml_node_num != 0)
957 {
958 for (int i = 0; i < xml_node_num; i++)
959 {
960 type_button[i].Visible = true;
961 type_button[i].Enabled = true;
962 }
963 }
964 else
965 return;
966
967 }
968 #endregion
969
970
971 private void Form1_Load(object sender, EventArgs e)
972 {
973 auto_size_form.Init_control_size(this);
974 }
975
976 private void Form1_SizeChanged(object sender, EventArgs e)
977 {
978 auto_size_form.Auto_control_size(this);
979
980 if(xml_node_num !=0)
981 pictureBox1.Load(all_picture_path[current_picture_index - 1]);
982
983
984 }
985
986 private void Form1_KeyDown(object sender, KeyEventArgs e)
987 {
988 if (xml_node_num > 0)
989 {
990 for (int i = 0; i < xml_node_num; i++)
991 {
992 if (e.KeyCode == key_type[i])
993 {
994 type_button_Click(type_button[i], EventArgs.Empty);
995 }
996
997 }
998
999 }
1000 //else
1001 // MessageBox.Show("先加载 xml 文件");
1002
1003 }
1004
1005 private void 恢复默认设置ToolStripMenuItem_Click(object sender, EventArgs e)
1006 {
1007 key_type[0] = Keys.NumPad7;
1008 key_type[1] = Keys.NumPad8;
1009 key_type[2] = Keys.NumPad9;
1010 key_type[3] = Keys.NumPad4;
1011 key_type[4] = Keys.NumPad5;
1012 key_type[5] = Keys.NumPad6;
1013 key_type[6] = Keys.NumPad1;
1014 key_type[7] = Keys.NumPad2;
1015 key_type[8] = Keys.NumPad3;
1016 }
1017
1018 private void 自定义ToolStripMenuItem_Click(object sender, EventArgs e)
1019 {
1020 Form f2 = new Form2Hotkeys();
1021 f2.ShowDialog();
1022 }
1023
1024 }
1025
1026
1027
1028
1029
1030 /*
1031 #region 根据标记功能设置 ListView 显示样例
1032 void Set_example_picture()
1033 {
1034 marker_type_list.Images.Clear();
1035 listView1.Items.Clear();
1036
1037 switch(function_select)
1038 {
1039 case BROW:
1040 {
1041 #region 显示眉毛的样例
1042 DirectoryInfo TheFolder = new DirectoryInfo(brow_tpye_path);
1043 List<string> brow_type_name = new List<string>();
1044
1045 foreach (FileInfo NextFile in TheFolder.GetFiles("*.jpg"))
1046 {
1047 marker_type_list.Images.Add(Image.FromFile(brow_tpye_path + @"\" + NextFile.Name));
1048 brow_type_name.Add(NextFile.Name);
1049
1050 }
1051
1052 listView1.LargeImageList = marker_type_list;
1053 for (int i = 0; i < marker_type_list.Images.Count; i++)
1054 {
1055 listView1.Items.Add(brow_type_name[i]);
1056 listView1.Items[i].ImageIndex = i;
1057 }
1058 #endregion
1059 }
1060 break;
1061 case EYE:
1062 {
1063 #region 显示眼睛的样例
1064 DirectoryInfo TheFolder = new DirectoryInfo(eye_tpye_path);
1065 List<string> eye_type_name = new List<string>();
1066
1067 foreach (FileInfo NextFile in TheFolder.GetFiles("*.jpg"))
1068 {
1069 marker_type_list.Images.Add(Image.FromFile(eye_tpye_path + @"\" + NextFile.Name));
1070 eye_type_name.Add(NextFile.Name);
1071
1072 }
1073
1074 listView1.LargeImageList = marker_type_list;
1075 for (int i = 0; i < marker_type_list.Images.Count; i++)
1076 {
1077 listView1.Items.Add(eye_type_name[i]);
1078 listView1.Items[i].ImageIndex = i;
1079 }
1080 #endregion
1081 }
1082 break;
1083 case NOSE:
1084 {
1085 #region 显示鼻子的样例
1086 DirectoryInfo TheFolder = new DirectoryInfo(nose_tpye_path);
1087 List<string> nose_type_name = new List<string>();
1088
1089 foreach (FileInfo NextFile in TheFolder.GetFiles("*.jpg"))
1090 {
1091 marker_type_list.Images.Add(Image.FromFile(nose_tpye_path + @"\" + NextFile.Name));
1092 nose_type_name.Add(NextFile.Name);
1093
1094 }
1095
1096 listView1.LargeImageList = marker_type_list;
1097 for (int i = 0; i < marker_type_list.Images.Count; i++)
1098 {
1099 listView1.Items.Add(nose_type_name[i]);
1100 listView1.Items[i].ImageIndex = i;
1101 }
1102 #endregion
1103 }
1104 break;
1105 case MOUTH:
1106 {
1107 #region 显示嘴巴的样例
1108 DirectoryInfo TheFolder = new DirectoryInfo(mouth_tpye_path);
1109 List<string> mouth_type_name = new List<string>();
1110
1111 foreach (FileInfo NextFile in TheFolder.GetFiles("*.jpg"))
1112 {
1113 marker_type_list.Images.Add(Image.FromFile(mouth_tpye_path + @"\" + NextFile.Name));
1114 mouth_type_name.Add(NextFile.Name);
1115
1116 }
1117
1118 listView1.LargeImageList = marker_type_list;
1119 for (int i = 0; i < marker_type_list.Images.Count; i++)
1120 {
1121 listView1.Items.Add(mouth_type_name[i]);
1122 listView1.Items[i].ImageIndex = i;
1123 }
1124 #endregion
1125 }
1126 break;
1127 default: break;
1128 }
1129
1130
1131 }
1132 #endregion
1133 */
1134
1135
1136
1137 #region 在 listView1 中显示拼接后图片
1138 /*
1139 private void Show_join_image_in_listview()
1140 {
1141 listView1.Items.Clear();
1142
1143 if(join_image_list.Images.Count > 0)
1144 {
1145 listView1.LargeImageList = join_image_list;
1146 for (int i = 0; i < join_image_list.Images.Count; i++)
1147 {
1148 listView1.Items.Add(join_image_list_name[i]);
1149 listView1.Items[i].ImageIndex = i;
1150 }
1151 }
1152
1153 }
1154 */
1155 #endregion
1156
1157
1158 /*
1159 #region 设置按钮 当改变窗口大小时重绘用
1160 void Set_button()
1161 {
1162 // 先把之前的功能按钮释放
1163 if (xml_node_num != 0)
1164 {
1165 for (int i = 0; i < xml_node_num; i++)
1166 type_button[i].Dispose();
1167 }
1168
1169 int x = 10, y = 20;
1170 int per_x_add = (this.groupBox1.Width - 10) / 3;
1171 int per_y_add = (this.groupBox1.Height - 20) / 3;
1172 int x_button_num = 0;
1173
1174 for (int i = 0; i < xml_node_num; i++)
1175 {
1176 type_button[i] = new Button();
1177 type_button[i].Location = new Point(x, y);
1178 type_button[i].Size = new Size(per_x_add - 10, per_y_add - 10);
1179 //type_button[i].Name = ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("ID").ToString();
1180 type_button[i].Name = ("B" + i.ToString());
1181 //type_button[i].Text = ((XmlElement)xmlDoc.DocumentElement.ChildNodes[i]).GetAttribute("type").ToString();
1182 type_button[i].Click += new System.EventHandler(this.type_button_Click);
1183
1184 this.groupBox1.Controls.Add(type_button[i]);
1185
1186 x += per_x_add;
1187 ++x_button_num;
1188 if (x_button_num == 3)
1189 {
1190 x = 10;
1191 x_button_num = 0;
1192 y += per_y_add;
1193 }
1194
1195 }
1196
1197
1198 }
1199 #endregion
1200 */
1201 }