Commit b2897ce8 authored by Bruce's avatar Bruce

mapping, saving, bndboxes -v 0.2

parent 12be3f70
...@@ -11,17 +11,31 @@ namespace ETC_App1 ...@@ -11,17 +11,31 @@ namespace ETC_App1
public class BndBox : Panel public class BndBox : Panel
{ {
int dotSize = 10; //需要被 2 整除 int dotSize = 10; //需要被 2 整除
public BndBox(Point location, Size size) List <Color> colors=new List<Color> { Color.Red,Color.Orange,Color.Yellow,Color.Green,Color.Blue,Color.Brown,Color.Purple};
int Color_ind;
public int Num;
public BndBox(Point location, Size size , int color)
{ {
InitializeComponent(); InitializeComponent();
this.DoubleBuffered = true;
this.Location = location; this.Location = location;
this.Size = size; this.Size = size;
this.Num = color;
if (colors.Count <= color)
{
Random rnd = new Random();
colors.Add(Color.FromArgb(255, rnd.Next(100, 255), rnd.Next(100, 255), rnd.Next(100, 255)));
this.Color_ind = 7;
}
else
this.Color_ind = color;
} }
private void panel1_Paint(object sender, PaintEventArgs e) private void panel1_Paint(object sender, PaintEventArgs e)
{ {
Panel pl = (Panel)sender; Panel pl = (Panel)sender;
e.Graphics.DrawRectangle(new Pen(Color.Red, 2), dotSize / 2, dotSize / 2, pl.Width - dotSize, pl.Height - dotSize);
e.Graphics.DrawRectangle(new Pen(colors[Color_ind], 2), dotSize / 2, dotSize / 2, pl.Width - dotSize, pl.Height - dotSize);
Point x1 = new Point(0, 0); Point x1 = new Point(0, 0);
Point y1 = new Point(0, pl.Height); Point y1 = new Point(0, pl.Height);
...@@ -115,16 +129,16 @@ namespace ETC_App1 ...@@ -115,16 +129,16 @@ namespace ETC_App1
// //
this.BackColor = System.Drawing.Color.Transparent; this.BackColor = System.Drawing.Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); this.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.BndBox_MouseClick);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
this.MouseLeave += new System.EventHandler(this.BndBox_MouseLeave);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
private void BndBox_MouseLeave(object sender, EventArgs e) private void BndBox_MouseClick(object sender, MouseEventArgs e)
{ {
//this.BringToFront();
} }
} }
} }
This diff is collapsed.
...@@ -5,6 +5,7 @@ using System.Data; ...@@ -5,6 +5,7 @@ using System.Data;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
...@@ -17,6 +18,7 @@ namespace ETC_App1 ...@@ -17,6 +18,7 @@ namespace ETC_App1
private string Imgs_path = ""; private string Imgs_path = "";
private string Xmls_path = ""; private string Xmls_path = "";
private XmlLable xmlLable = new XmlLable(); private XmlLable xmlLable = new XmlLable();
private List<BndBox> bndBoxes= new List<BndBox>();
//private Form ROI { get; set; } //private Form ROI { get; set; }
public Form2() public Form2()
...@@ -72,6 +74,12 @@ namespace ETC_App1 ...@@ -72,6 +74,12 @@ namespace ETC_App1
string img = listBox1.SelectedItem.ToString().Remove(0,3); string img = listBox1.SelectedItem.ToString().Remove(0,3);
Bitmap bitmap = new Bitmap(img); Bitmap bitmap = new Bitmap(img);
pictureBox1.Image = bitmap; pictureBox1.Image = bitmap;
FreshImg();
string xml = img.Replace(".jpg", ".xml").Replace(".png", ".xml");
if (File.Exists(xml))
{
Console.WriteLine(xml);
}
} }
} }
} }
...@@ -80,26 +88,36 @@ namespace ETC_App1 ...@@ -80,26 +88,36 @@ namespace ETC_App1
FolderBrowserDialog path = new FolderBrowserDialog(); FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog(); path.ShowDialog();
Xmls_path = path.SelectedPath; Xmls_path = path.SelectedPath;
}
XmlLableObject obj1 = new XmlLableObject("A", "11", "12", "13", "14");
XmlLableObject obj2 = new XmlLableObject("B", "15", "16", "17", "18");
XmlLableObject obj3 = new XmlLableObject("C", "19", "20", "21", "22");
xmlLable.Object.Add(obj1); double rate;
xmlLable.Object.Add(obj2); int black_left_width;
xmlLable.Object.Add(obj3); int black_top_height;
private void FreshImg()
{
Now_selected = -1;
//int originalWidth = this.pictureBox1.Image.Width;
int originalHeight = this.pictureBox1.Image.Height;
ProcessCombobox(); PropertyInfo rectangleProperty = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(this.pictureBox1, null);
CreateXmlTree(@"C:\Users\Bruce\source\repos\e-eye\ETC_App1\bin\Debug\form2_config\Eample.xml", Xmls_path+@"\Eample2.xml"); int currentWidth = rectangle.Width;
} int currentHeight = rectangle.Height;
private void Form2_KeyPress(object sender, KeyPressEventArgs e) rate = (double)currentHeight / (double)originalHeight;
{
black_left_width = (currentWidth == this.pictureBox1.Width) ? 0 : (this.pictureBox1.Width - currentWidth) / 2;
} black_top_height = (currentHeight == this.pictureBox1.Height) ? 0 : (this.pictureBox1.Height - currentHeight) / 2;
this.xmlLable = new XmlLable();
foreach(BndBox box in bndBoxes)
{
box.Dispose();
}
this.bndBoxes = new List<BndBox>();
checkedListBox1.Items.Clear();
}
private void Form2_KeyDown(object sender, KeyEventArgs e) private void Form2_KeyDown(object sender, KeyEventArgs e)
{ {
if (e.KeyCode == Keys.D) //下一張按鈕 if (e.KeyCode == Keys.D) //下一張按鈕
...@@ -112,9 +130,7 @@ namespace ETC_App1 ...@@ -112,9 +130,7 @@ namespace ETC_App1
string img = listBox1.SelectedItem.ToString().Remove(0, 3); string img = listBox1.SelectedItem.ToString().Remove(0, 3);
Bitmap bitmap = new Bitmap(img); Bitmap bitmap = new Bitmap(img);
pictureBox1.Image = bitmap; pictureBox1.Image = bitmap;
FreshImg();
this.xmlLable = new XmlLable();
checkedListBox1.Items.Clear();
string xml = img.Replace(".jpg", ".xml").Replace(".png",".xml"); string xml = img.Replace(".jpg", ".xml").Replace(".png",".xml");
if (File.Exists(xml)) if (File.Exists(xml))
...@@ -134,30 +150,46 @@ namespace ETC_App1 ...@@ -134,30 +150,46 @@ namespace ETC_App1
string img = listBox1.SelectedItem.ToString().Remove(0, 3); string img = listBox1.SelectedItem.ToString().Remove(0, 3);
Bitmap bitmap = new Bitmap(img); Bitmap bitmap = new Bitmap(img);
pictureBox1.Image = bitmap; pictureBox1.Image = bitmap;
this.xmlLable = new XmlLable();
checkedListBox1.Items.Clear(); FreshImg();
string xml = img.Replace(".jpg", ".xml").Replace(".png", ".xml");
if (File.Exists(xml))
{
Console.WriteLine(xml);
}
} }
} }
} }
if (e.Control && e.KeyCode == Keys.S) //儲存按鈕 if (e.Control && e.KeyCode == Keys.S) //儲存按鈕
{ {
string path =Application.StartupPath;
CreateXmlTree(path+@"\form2_config\Eample.xml", Xmls_path + @"\Eample2.xml");
} }
if (e.Control && e.KeyCode == Keys.W) //創建區塊 按鈕 if (e.Control && e.KeyCode == Keys.W) //創建區塊 按鈕
{ {
Point pp = new Point(300, 300); newBndbox();
Size ss = new Size(50, 50);
BndBox box = new BndBox(pp,ss);
Controls.Add(box);
box.Parent = pictureBox1;
box.Refresh();
box.Show();
box.BringToFront();
} }
if (e.Control && e.KeyCode == Keys.E) //儲存按鈕 if (e.Control && e.KeyCode == Keys.E) //沿用區塊 按鈕
{ {
} }
if (e.KeyCode == Keys.Delete)
{
if (Now_selected >= 0)
{
for (int i= Now_selected+1;i < bndBoxes.Count;i++)
{
bndBoxes[i].Num=i-1;
}
bndBoxes[Now_selected].Dispose();
bndBoxes.RemoveAt(Now_selected);
xmlLable.Object.RemoveAt(Now_selected);
ProcessCombobox(-1);
}
Now_selected = -1;
}
} }
public void CreateXmlTree(string src_path,string save_path) public void CreateXmlTree(string src_path,string save_path)
{ {
...@@ -210,23 +242,74 @@ namespace ETC_App1 ...@@ -210,23 +242,74 @@ namespace ETC_App1
} }
doc.Save(save_path); doc.Save(save_path);
} }
public void ProcessCombobox() public void ProcessCombobox(int index)
{ {
List<XmlLableObject> objs = xmlLable.Object; List<XmlLableObject> objs = xmlLable.Object;
foreach (XmlLableObject obj in objs) if (index < 0)
{ {
string temp = String.Format("{0}: {1},{2},{3},{4}", obj.Name, obj.X1, obj.Y1, obj.X2, obj.Y2); checkedListBox1.Items.Clear();
foreach (XmlLableObject obj in objs)
if (checkedListBox1.Items.IndexOf(temp) < 0 || true)
{ {
string temp = String.Format("{0}: {1},{2},{3},{4}", obj.Name, obj.X1, obj.Y1, obj.X2, obj.Y2);
checkedListBox1.Items.Add(temp); checkedListBox1.Items.Add(temp);
checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(temp), true); checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(temp), true);
} }
} }
else
{
XmlLableObject obj=objs[index];
string temp = String.Format("{0}: {1},{2},{3},{4}", obj.Name, obj.X1, obj.Y1, obj.X2, obj.Y2);
checkedListBox1.Items[index] = temp;
checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(temp), true);
}
}
public void newBndbox()
{
int move = xmlLable.Object.Count - 1 >= 0 ? xmlLable.Object.Count : 0;
int mapping_x=(int)Math.Round(((300+move*10) * rate) + black_left_width, 0, MidpointRounding.AwayFromZero);
int mapping_y = (int)Math.Round((156 * rate) + black_top_height, 0, MidpointRounding.AwayFromZero);
int mapping_w = (int)Math.Round((300 * rate) , 0, MidpointRounding.AwayFromZero);
int mapping_h= (int)Math.Round((208 * rate), 0, MidpointRounding.AwayFromZero);
Point pp = new Point(mapping_x, mapping_y);
Size ss = new Size(mapping_w, mapping_h);
BndBox box = new BndBox(pp, ss, xmlLable.Object.Count-1 >=0 ? xmlLable.Object.Count : 0);
box.Paint += Bndbox_GotFocus;
box.MouseClick += Box_MouseClick;
Controls.Add(box);
box.Parent = pictureBox1;
bndBoxes.Add(box);
box.BringToFront();
string x1 = Math.Round((box.Left - black_left_width) / rate, 0, MidpointRounding.AwayFromZero).ToString();
string y1 = Math.Round((box.Top - black_top_height) / rate, 0, MidpointRounding.AwayFromZero).ToString();
string x2 = Math.Round((box.Left - black_left_width + box.Width) / rate, 0, MidpointRounding.AwayFromZero).ToString();
string y2 = Math.Round((box.Top - black_top_height + box.Height) / rate, 0, MidpointRounding.AwayFromZero).ToString();
XmlLableObject obj = new XmlLableObject("A", x1, y1, x2, y2);
xmlLable.Object.Add(obj);
ProcessCombobox(-1);
} }
int Now_selected=-1;
private void Box_MouseClick(object sender, MouseEventArgs e)
{
BndBox box = (BndBox)sender;
Now_selected= box.Num;
checkedListBox1.SetSelected(Now_selected,true);
}
private void Bndbox_GotFocus(Object sender , EventArgs e)
{
BndBox box = (BndBox)sender;
string x1 = Math.Round((box.Left - black_left_width) / rate, 0, MidpointRounding.AwayFromZero).ToString();
string y1 = Math.Round((box.Top - black_top_height) / rate, 0, MidpointRounding.AwayFromZero).ToString();
string x2 = Math.Round((box.Left - black_left_width + box.Width) / rate, 0, MidpointRounding.AwayFromZero).ToString();
string y2 = Math.Round((box.Top - black_top_height + box.Height) / rate, 0, MidpointRounding.AwayFromZero).ToString();
xmlLable.Object[box.Num].modifie(x1, y1, x2, y2);
ProcessCombobox(box.Num);
}
} }
} }
...@@ -123,4 +123,7 @@ ...@@ -123,4 +123,7 @@
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>195, 17</value> <value>195, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root> </root>
\ No newline at end of file
...@@ -24,5 +24,13 @@ namespace ETC_App1 ...@@ -24,5 +24,13 @@ namespace ETC_App1
this.Y2 = y2; this.Y2 = y2;
} }
public void modifie(string x1, string y1, string x2, string y2)
{
this.X1 = x1;
this.X2 = x2;
this.Y1 = y1;
this.Y2 = y2;
}
} }
} }
e0043c7e390cd0b592b3be354e86de0f9dd09bd3 787279dc622ca0322d891fa421c6a5217f3b4855
...@@ -487,3 +487,68 @@ C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.exe ...@@ -487,3 +487,68 @@ C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.exe
C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.pdb C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.pdb
C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.UserControl1.resources C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.UserControl1.resources
C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.BndBox.resources C:\Users\ivan\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.BndBox.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x64\concrt140.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x64\cvextern.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x64\msvcp140.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x64\opencv_ffmpeg401_64.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x64\vcruntime140.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x86\concrt140.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x86\cvextern.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x86\msvcp140.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x86\opencv_ffmpeg401.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\x86\vcruntime140.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ETC_App1.exe.config
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ETC_App1.exe
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ETC_App1.pdb
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Aspose.BarCode.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\DuoVia.FuzzyStrings.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Emgu.CV.UI.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Emgu.CV.World.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ICSharpCode.SharpZipLib.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\MySql.Data.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Newtonsoft.Json.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\NPOI.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\NPOI.OOXML.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\NPOI.OpenXml4Net.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\NPOI.OpenXmlFormats.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\RestSharp.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ZedGraph.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Aspose.BarCode.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Emgu.CV.UI.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Emgu.CV.World.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ICSharpCode.SharpZipLib.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\MySql.Data.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\Newtonsoft.Json.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\RestSharp.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ZedGraph.xml
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\de\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\es\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\fr\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\hu\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\it\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ja\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\pt\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\ru\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\sk\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\sv\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\tr\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\zh-cn\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\bin\Debug\zh-tw\ZedGraph.resources.dll
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.csprojAssemblyReference.cache
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.BndBox.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.ETCBackgroundWorker1.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.ETCBackgroundWorker2.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.ETCBackgroundWorker3.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.ETCPictureBox.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.ETCPictureCheckBox.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.ETCStatusStrip.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.ETCToolStrip.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.Form1.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.Form2.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.Properties.Resources.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.UserControl1.resources
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.csproj.GenerateResource.cache
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.csproj.CoreCompileInputs.cache
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.csproj.CopyComplete
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.exe
C:\Users\aa349\source\repos\e-eye\ETC_App1\obj\Debug\ETC_App1.pdb
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment