Денис Кузнецов 2 years ago
parent
commit
13024b39e8
  1. 99
      Test_img/Form1.cs
  2. 37
      Test_img/olo1.cs

99
Test_img/Form1.cs

@ -6,6 +6,7 @@ using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Reflection; using System.Reflection;
using System.Security.Cryptography;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Forms.Design; using System.Windows.Forms.Design;
using UTIL; 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, 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.right - g_super_cluster_coords[m].rect.left) * zoomFactor,
(g_super_cluster_coords[m].rect.bottom - g_super_cluster_coords[m].rect.top) * 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])); PointF rct = PointFBmToPb(item);
Point rct = PointBmToPb(r);
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, 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); e.Graphics.DrawLine(new Pen(Color.LimeGreen, 1), rct.X - 20, rct.Y, rct.X + 20, rct.Y);
} }
@ -243,7 +246,7 @@ namespace Test_img
{ {
foreach (var pnt in SearchPixel2(imgsearch)) foreach (var pnt in SearchPixel2(imgsearch))
e.Graphics.DrawEllipse(new Pen(Color.Red), e.Graphics.DrawEllipse(new Pen(Color.Red),
PointBmToPb(pnt).X - 5 * zoomFactor, PointBmToPb(pnt).X - 5 * zoomFactor,
PointBmToPb(pnt).Y - 5 * zoomFactor, PointBmToPb(pnt).Y - 5 * zoomFactor,
10 * zoomFactor, 10 * 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 new Rectangle(p3, new Size(p4.X - p3.X, p2.Y - p3.Y));
return r; return r;
} }
//private void SearchPixel() private void SearchPixel()
//{ {
// List<Point> points = new List<Point>(); List<Point> points = new List<Point>();
// Stopwatch stopwatch = Stopwatch.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew();
// UnsafeBitmap btm = new UnsafeBitmap(bm); UnsafeBitmap btm = new UnsafeBitmap(bm);
// btm.LockBitmap(); btm.LockBitmap();
// for (int y = 0; y < bm.Height; y++) for (int y = 0; y < bm.Height; y++)
// { {
// for (int x = 0; x < bm.Width; x++) for (int x = 0; x < bm.Width; x++)
// { {
// PixelData c = btm.GetPixel(x, y); PixelData c = btm.GetPixel(x, y);
// if (c.blue >= imgsearch) if (c.blue >= imgsearch)
// { {
// points.Add(new Point(x, y)); points.Add(new Point(x, y));
// //Console.WriteLine($"{x} {y}"); //Console.WriteLine($"{x} {y}");
// } }
// } }
// } }
// stopwatch.Stop(); stopwatch.Stop();
// Console.WriteLine(stopwatch.Elapsed.ToString()); Console.WriteLine(stopwatch.Elapsed.ToString());
// btm.Dispose(); btm.Dispose();
// using (Graphics g = Graphics.FromImage(newbm)) using (Graphics g = Graphics.FromImage(newbm))
// { {
// //g.Clear(Color.White); //g.Clear(Color.White);
// for (int i = 0; i < points.Count; i++) for (int i = 0; i < points.Count; i++)
// g.DrawEllipse(new Pen(Color.Red), points[i].X - 5, points[i].Y - 5, 10, 10); 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) private Point CalcCenterMass(Rectangle r)
{ {
Int32 sX = 0; 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)); 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) 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)); 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) private void img_fon_Click(object sender, EventArgs e)
{ {
UnsafeBitmap btm = new UnsafeBitmap(bm); imgfon();
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);
} }
private void imgfon() private void imgfon()
{ {
@ -577,9 +566,9 @@ namespace Test_img
btm.UnlockBitmap(); btm.UnlockBitmap();
btm.Dispose(); btm.Dispose();
fon = sc; fon = sc;
trackbar1.Value = (int)fon + 1; trackbar1.Value = (int)fon + 10;
imgsearch = (int)fon; imgsearch = (int)fon + 10;
StaticData.Fon?.Invoke(sc); //StaticData.Fon?.Invoke(sc);
} }
private void img_timer_Click(object sender, EventArgs e) private void img_timer_Click(object sender, EventArgs e)

37
Test_img/olo1.cs

@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using UTIL; using UTIL;
using static Test_img.Form1;
namespace Test_img 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); return new Rectangle(c.rect.left, c.rect.top, c.rect.right - c.rect.left, c.rect.bottom - c.rect.top);
} }
private List<PointF> CalculateMassCentre()
{
UInt16 i, j, c = 0;
float fx = 0, fy = 0;
List<PointF> points = new List<PointF>();
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;
}
} }
} }

Loading…
Cancel
Save