diff --git a/Test_img/Form1.cs b/Test_img/Form1.cs index 64ea6f5..db421ca 100644 --- a/Test_img/Form1.cs +++ b/Test_img/Form1.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Reflection; +using System.Security.Cryptography; using System.Windows.Forms; using System.Windows.Forms.Design; using UTIL; @@ -230,10 +231,12 @@ namespace Test_img PointBmToPb(new Point(g_super_cluster_coords[m].rect.left, g_super_cluster_coords[m].rect.top)).Y, (g_super_cluster_coords[m].rect.right - g_super_cluster_coords[m].rect.left) * zoomFactor, (g_super_cluster_coords[m].rect.bottom - g_super_cluster_coords[m].rect.top) * zoomFactor); - if (show_mass_center.Checked) + } + if (show_mass_center.Checked) + { + foreach (var item in CalculateMassCentre()) { - Point r = CalcCenterMass(CLUSTER_COORD2Rect(g_super_cluster_coords[m])); - Point rct = PointBmToPb(r); + PointF rct = PointFBmToPb(item); e.Graphics.DrawLine(new Pen(Color.LimeGreen, 1), rct.X, rct.Y - 20, rct.X, rct.Y + 20); e.Graphics.DrawLine(new Pen(Color.LimeGreen, 1), rct.X - 20, rct.Y, rct.X + 20, rct.Y); } @@ -242,8 +245,8 @@ namespace Test_img if (img_search.Checked) { foreach (var pnt in SearchPixel2(imgsearch)) - e.Graphics.DrawEllipse(new Pen(Color.Red), - PointBmToPb(pnt).X - 5 * zoomFactor, + e.Graphics.DrawEllipse(new Pen(Color.Red), + PointBmToPb(pnt).X - 5 * zoomFactor, PointBmToPb(pnt).Y - 5 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor); @@ -302,36 +305,36 @@ namespace Test_img return new Rectangle(p3, new Size(p4.X - p3.X, p2.Y - p3.Y)); return r; } - //private void SearchPixel() - //{ - // List points = new List(); - // Stopwatch stopwatch = Stopwatch.StartNew(); - // UnsafeBitmap btm = new UnsafeBitmap(bm); - // btm.LockBitmap(); - // for (int y = 0; y < bm.Height; y++) - // { - // for (int x = 0; x < bm.Width; x++) - // { - // PixelData c = btm.GetPixel(x, y); - // if (c.blue >= imgsearch) - // { - // points.Add(new Point(x, y)); - // //Console.WriteLine($"{x} {y}"); - // } - // } - // } - // stopwatch.Stop(); - // Console.WriteLine(stopwatch.Elapsed.ToString()); - // btm.Dispose(); - // using (Graphics g = Graphics.FromImage(newbm)) - // { - // //g.Clear(Color.White); - // for (int i = 0; i < points.Count; i++) - // g.DrawEllipse(new Pen(Color.Red), points[i].X - 5, points[i].Y - 5, 10, 10); + private void SearchPixel() + { + List points = new List(); + Stopwatch stopwatch = Stopwatch.StartNew(); + UnsafeBitmap btm = new UnsafeBitmap(bm); + btm.LockBitmap(); + for (int y = 0; y < bm.Height; y++) + { + for (int x = 0; x < bm.Width; x++) + { + PixelData c = btm.GetPixel(x, y); + if (c.blue >= imgsearch) + { + points.Add(new Point(x, y)); + //Console.WriteLine($"{x} {y}"); + } + } + } + stopwatch.Stop(); + Console.WriteLine(stopwatch.Elapsed.ToString()); + btm.Dispose(); + using (Graphics g = Graphics.FromImage(newbm)) + { + //g.Clear(Color.White); + for (int i = 0; i < points.Count; i++) + g.DrawEllipse(new Pen(Color.Red), points[i].X - 5, points[i].Y - 5, 10, 10); - // } - // pictureBox1.Invalidate(); - //} + } + pictureBox1.Invalidate(); + } private Point CalcCenterMass(Rectangle r) { Int32 sX = 0; @@ -379,6 +382,10 @@ namespace Test_img { return new Point((int)(p.X * zoomFactor + movingPoint.X), (int)(p.Y * zoomFactor + movingPoint.Y)); } + private PointF PointFBmToPb(PointF p) + { + return new PointF(p.X * zoomFactor + movingPoint.X, p.Y * zoomFactor + movingPoint.Y); + } private Rectangle RectBmToPb(Rectangle p) { return new Rectangle((int)(p.X * zoomFactor + movingPoint.X), (int)(p.Y * zoomFactor + movingPoint.Y), (int)(p.Width * zoomFactor), (int)(p.Height * zoomFactor)); @@ -537,25 +544,7 @@ namespace Test_img private void img_fon_Click(object sender, EventArgs e) { - UnsafeBitmap btm = new UnsafeBitmap(bm); - btm.LockBitmap(); - UInt32 sc = 0; - for (int y = 0; y < bm.Height; y++) - { - PixelData c = btm.GetPixel(y, y); - sc += (UInt32)(c.blue * c.blue); - c = btm.GetPixel(bm.Width - 1 - y, y); - sc += (UInt32)(c.blue * c.blue); - } - Console.WriteLine(sc.ToString()); - sc = (UInt32)Math.Sqrt(sc / bm.Height / 2); - Console.WriteLine(sc.ToString()); - - img_srch.Text = $"Фон: {sc}"; - btm.UnlockBitmap(); - btm.Dispose(); - fon = sc; - StaticData.Fon?.Invoke(sc); + imgfon(); } private void imgfon() { @@ -577,9 +566,9 @@ namespace Test_img btm.UnlockBitmap(); btm.Dispose(); fon = sc; - trackbar1.Value = (int)fon + 1; - imgsearch = (int)fon; - StaticData.Fon?.Invoke(sc); + trackbar1.Value = (int)fon + 10; + imgsearch = (int)fon + 10; + //StaticData.Fon?.Invoke(sc); } private void img_timer_Click(object sender, EventArgs e) diff --git a/Test_img/olo1.cs b/Test_img/olo1.cs index 6e0ea41..7fa4968 100644 --- a/Test_img/olo1.cs +++ b/Test_img/olo1.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using UTIL; +using static Test_img.Form1; namespace Test_img { @@ -253,5 +254,41 @@ namespace Test_img { return new Rectangle(c.rect.left, c.rect.top, c.rect.right - c.rect.left, c.rect.bottom - c.rect.top); } + private List CalculateMassCentre() + { + UInt16 i, j, c = 0; + float fx = 0, fy = 0; + List points = new List(); + + for (i = 0; i < g_super_cluster_count; i++) + { + CLUSTER_COORD pcc = g_super_cluster_coords[i]; + if (g_super_cluster_coords[i].excluded == __FALSE) + { + for (j = 0; j < g_shot_count; j++) + { + UInt16 x = g_shot_array[j].x; + UInt16 y = g_shot_array[j].y; + + if (x >= g_super_cluster_coords[i].rect.left && x < g_super_cluster_coords[i].rect.right && + y >= g_super_cluster_coords[i].rect.top && y < g_super_cluster_coords[i].rect.bottom) + { + fx += x; + fy += y; + c++; + } + } + } + if (c > 0) + { + points.Add(new PointF(fx / (float)c, fy / (float)c)); + c = 0; + fx = 0; + fy = 0; + } + } + return points; + } + } }