private void TimeInit() { c = new car("1128"); image img = new image(p.Scan(carid.SelectedText + @"\0"), DateTime.Now); c.list.Add(img); list.Add(c); }
private void TimeInit() { c = new car("1128"); image img = new image(p.Scan("t1"), DateTime.Now); c.list.Add(img); list.Add(c); }
public image DeltaCalculationsave(List <Bitmap> a, List <Bitmap> b, string path, string id) { try { string pathchanges = path + @"\changes"; List <Bitmap> newdeltalist = new List <Bitmap>(); image nl = new image(newdeltalist, DateTime.Now); try { path += @"\deltas"; System.IO.Directory.CreateDirectory(path); System.IO.Directory.CreateDirectory(pathchanges); } catch { } for (int i = 0; i < a.Count; i++) { Bitmap temp = alg(a[i], b[i], nl); Bitmap temp2 = alg2(a[i], b[i], nl, pathchanges + @"\p(" + (i + 1) + ").txt", id); try { temp2.Save(pathchanges + @"\p(" + (i + 1) + ").png"); temp.Save(path + @"\p(" + (i + 1) + ").png"); } catch (Exception) { } try { db.CreateMyOleDbDataReader("insert into shot ([id car],[id shot round],[num of hits]) values (" + id + "," + shot + "," + hitsize + ");", db.con); } catch (Exception v) { } newdeltalist.Add(temp); } return(nl); } catch (Exception) { return(null); } }
public image DeltaCalculationi(List <Bitmap> a, List <Bitmap> b) { try { List <Bitmap> newdeltalist = new List <Bitmap>(); image nl = new image(newdeltalist, DateTime.Now); for (int i = 0; i < a.Count; i++) { newdeltalist.Add(alg(a[i], b[i], nl)); } return(nl); } catch (Exception) { return(null); } }
public Bitmap alg(Bitmap bm1, Bitmap bm2, image c) { List <dpoint> deltagroup = new List <dpoint>(); int group = 1; int wid = Math.Min(bm1.Width, bm2.Width); int hgt = Math.Min(bm1.Height, bm2.Height); // Get the differences. int[,] diffs = new int[wid, hgt]; int max_diff = 0; for (int x = 0; x < wid; x++) { for (int y = 0; y < hgt; y++) { // Calculate the pixels' difference. Color color1 = bm1.GetPixel(x, y); Color color2 = bm2.GetPixel(x, y); diffs[x, y] = (int)( Math.Abs(color1.R - color2.R) + Math.Abs(color1.G - color2.G) + Math.Abs(color1.B - color2.B)); if (diffs[x, y] > max_diff) { max_diff = diffs[x, y]; } } } //max_diff = 255; dpoint p; Boolean added = false; // Create the difference image. Bitmap bm3 = new Bitmap(wid, hgt); for (int x = 0; x < wid; x++) { for (int y = 0; y < hgt; y++) { if (diffs[x, y] != 0) { p = new dpoint(); p.p.X = x; p.p.Y = y; p.value = diffs[x, y]; added = false; if (deltagroup.Count == 0) { p.group = group; deltagroup.Add(p); added = true; } foreach (dpoint dd in deltagroup) { if (canGroupingEdges(p.p.X, dd.p.X) && canGroupingEdges(dd.p.Y, p.p.Y)) { p.group = dd.group; deltagroup.Add(p); added = true; break; } } if (added == false) { p.group = ++group; deltagroup.Add(p); } } int clr = 255; if (diffs[x, y] != 0) { clr = 255 - (int)(255.0 / max_diff * diffs[x, y]); } bm3.SetPixel(x, y, Color.FromArgb(clr, clr, clr)); } } Graphics g = Graphics.FromImage(bm3); Font f = new Font("Times New Roman", 6); for (int i = 1; i <= group; ++i) { foreach (dpoint dd in deltagroup) { if (dd.group == i) { g.DrawString("hit(" + dd.p.X + "," + dd.p.Y + ") v" + dd.value + "|" + dd.group, f, Brushes.Red, dd.p); //listBox1.Items.Add("hit num(" + dd.group + ") in(" + dd.p.X + ", " + dd.p.Y + ") value: " + dd.value + ". "); i++; } } } new pictureshow(bm1, bm3, bm2).Show(); c.dplist.Add(deltagroup); return(bm3); }
public Bitmap alg2(Bitmap bm1, Bitmap bm2, image c, string path, string id) { List <dpoint> deltagroup = new List <dpoint>(); int group = 1; int wid = Math.Min(bm1.Width, bm2.Width); int hgt = Math.Min(bm1.Height, bm2.Height); // Get the differences. int[,] diffs = new int[wid, hgt]; int max_diff = 0; for (int x = 0; x < wid; x++) { for (int y = 0; y < hgt; y++) { // Calculate the pixels' difference. Color color1 = bm1.GetPixel(x, y); Color color2 = bm2.GetPixel(x, y); diffs[x, y] = (int)( Math.Abs(color1.R - color2.R) + Math.Abs(color1.G - color2.G) + Math.Abs(color1.B - color2.B)); if (diffs[x, y] != 0 && diffs[x, y] < dif__) { diffs[x, y] = 0; } if (diffs[x, y] > max_diff) { max_diff = diffs[x, y]; } } } //max_diff = 255; dpoint p; Boolean added = false; // Create the difference image. int delta = 2; Bitmap bm3 = new Bitmap(wid, hgt); for (int x = 0; x < wid - delta; x += delta) { for (int y = 0; y < hgt - delta; y += delta) { //if(diffs[x, y] != 0 ) if (diffs[x, y] != 0) { p = new dpoint(); p.p.X = x; p.p.Y = y; p.value = diffs[x, y]; added = false; if (deltagroup.Count == 0) { p.group = group; deltagroup.Add(p); added = true; } foreach (dpoint dd in deltagroup) { if (canGroupingEdges(p.p.X, dd.p.X) && canGroupingEdges(dd.p.Y, p.p.Y)) { p.group = dd.group; deltagroup.Add(p); added = true; break; } } if (added == false) { p.group = ++group; deltagroup.Add(p); } } hitsize = deltagroup.Count; int clr = 255; if (diffs[x, y] != 0) { clr = 255 - (int)(255.0 / max_diff * diffs[x, y]); } bm3.SetPixel(x, y, Color.FromArgb(clr, clr, clr)); } } Graphics g = Graphics.FromImage(bm2); string st = ""; Font f = new Font("Times New Roman", 24); for (int i = 1; i <= group; ++i) { foreach (dpoint dd in deltagroup) { if (dd.group == i) { if (dd.p.Y > 80 && dd.p.Y < 200) { g.DrawString("*", f, Brushes.Blue, dd.p); } else { g.DrawString("*", f, Brushes.Green, dd.p); } st += "hit num(" + dd.group + ") in(" + dd.p.X + ", " + dd.p.Y + ") value: " + dd.value + ". " + Environment.NewLine; i++; //try //{ // //db.CreateMyOleDbDataReader("insert into hits ([id shot],[num of hits],[size of],[avarge]) values (" + this.GetcarFolderCounter(id) + "," + dd.p.Y + "," + dd.value + "," + dd.group + ");", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/asafl/Source/Repos/Final/comparlize/sqlouk.accdb"); //} //catch (Exception v) //{ // continue; //} } } } // new pictureshow(bm1, bm3, bm2).Show(); c.dplist.Add(deltagroup); try { System.IO.File.WriteAllText(@"" + path, contents: "" + st + Environment.NewLine + DateTime.Now + Environment.NewLine); } catch (Exception) { return(bm2); } return(bm2); }