3 changed files with 177 additions and 2 deletions
@ -0,0 +1,172 @@
@@ -0,0 +1,172 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
using System.Windows.Forms; |
||||
using UTIL; |
||||
|
||||
namespace Test_img |
||||
{ |
||||
public partial class Form1 : Form |
||||
{ |
||||
public struct FIFO_ITEM |
||||
{ |
||||
public UInt16 x; |
||||
public UInt16 y; |
||||
} |
||||
unsafe public struct THE_POINT |
||||
{ |
||||
public FIFO_ITEM* pi; |
||||
public Byte* pm; |
||||
} |
||||
public struct CLUSTER_COORD |
||||
{ |
||||
public UInt16 count; // number of points (pixels) in cluster |
||||
public Byte excluded; // flag, cluster should be ignored if TRUE |
||||
public Byte marker; // cluster identicator |
||||
public ARM_RECT rect; // rectangular area of cluster (in pixels) |
||||
} |
||||
public struct ARM_RECT |
||||
{ |
||||
public UInt16 left; |
||||
public UInt16 top; |
||||
public UInt16 right; |
||||
public UInt16 bottom; |
||||
} |
||||
List<FIFO_ITEM> v = new List<FIFO_ITEM>(); |
||||
List<PointF> FIFO_ITEM_f = new List<PointF>(); |
||||
static UInt16 IMAGE_CX = (320 - 1); |
||||
static UInt16 IMAGE_CY = (256 - 1); |
||||
static UInt16 CELL_SIZE = 8; // cluster cell size, in pix |
||||
UInt16 IMAGE_CELL_CX = (UInt16)((IMAGE_CX + CELL_SIZE - 1) / CELL_SIZE); |
||||
UInt16 IMAGE_CELL_CY = (UInt16)((IMAGE_CY + CELL_SIZE - 1) / CELL_SIZE); |
||||
private void GetPix() |
||||
{ |
||||
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) |
||||
{ |
||||
FIFO_ITEM t = new FIFO_ITEM(); |
||||
t.x = (UInt16)x; |
||||
t.y = (UInt16)y; |
||||
v.Add(t); |
||||
} |
||||
} |
||||
} |
||||
btm.UnlockBitmap(); |
||||
btm.Dispose(); |
||||
} |
||||
unsafe private void BuildClustersArray() |
||||
{ |
||||
Byte marker; |
||||
UInt16 i, j, k, count; |
||||
UInt16 l, t, r, b; |
||||
|
||||
for (i = 0; i < g_shot_count1; i++) |
||||
{ |
||||
FIFO_ITEM* fi = &g_shot_array1[i]; |
||||
UInt16 x = fi->x / CELL_SIZE; |
||||
UInt16 y = fi->y / CELL_SIZE; |
||||
CLUSTER_COORD* pcc = &g_cluster_coords1[y * IMAGE_CELL_CX + x]; |
||||
|
||||
pcc->count++; |
||||
pcc->excluded = __FALSE; |
||||
pcc->marker = NO_MARKER; |
||||
pcc->rect.left = (x) * CELL_SIZE; |
||||
pcc->rect.top = (y) * CELL_SIZE; |
||||
pcc->rect.right = (x + 1) * CELL_SIZE; |
||||
pcc->rect.bottom = (y + 1) * CELL_SIZE; |
||||
} |
||||
|
||||
memset(g_cluster_ptrs1, 0, sizeof(g_cluster_ptrs1)); |
||||
g_cluster_count1 = 0; |
||||
for (i = 0; i < IMAGE_CELL_CX * IMAGE_CELL_CY; i++) |
||||
{ |
||||
if (g_cluster_coords1[i].count > 0) |
||||
g_cluster_ptrs1[g_cluster_count1++] = &g_cluster_coords1[i]; |
||||
} |
||||
|
||||
marker = NO_MARKER; |
||||
for (i = 0; i < g_cluster_count1; i++) |
||||
{ |
||||
CLUSTER_COORD* pcc1 = g_cluster_ptrs1[i]; |
||||
S16 x1 = (pcc1->rect.left + pcc1->rect.right) / 2; |
||||
S16 y1 = (pcc1->rect.top + pcc1->rect.bottom) / 2; |
||||
|
||||
if (pcc1->marker == NO_MARKER) |
||||
pcc1->marker = (++marker); |
||||
|
||||
for (j = i + 1; j < g_cluster_count1; j++) |
||||
{ |
||||
CLUSTER_COORD* pcc2 = g_cluster_ptrs1[j]; |
||||
S16 x2 = (pcc2->rect.left + pcc2->rect.right) / 2; |
||||
S16 y2 = (pcc2->rect.top + pcc2->rect.bottom) / 2; |
||||
|
||||
if (abs(x1 - x2) <= CELL_SIZE && abs(y1 - y2) <= CELL_SIZE) |
||||
{ |
||||
if (pcc2->marker == NO_MARKER) |
||||
{ |
||||
pcc2->marker = pcc1->marker; |
||||
} |
||||
else |
||||
{ |
||||
for (k = 0; k < g_cluster_count1; k++) |
||||
{ |
||||
CLUSTER_COORD* pcc3 = g_cluster_ptrs1[k]; |
||||
|
||||
if (pcc3->marker == pcc2->marker) |
||||
pcc3->marker = pcc1->marker; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
memset(g_super_cluster_coords1, 0, sizeof(g_super_cluster_coords1)); |
||||
|
||||
g_super_cluster_count1 = 0; |
||||
for (i = 1; i <= marker; i++) |
||||
{ |
||||
count = 0; |
||||
l = 0x7fff, t = 0x7fff, r = 0, b = 0; |
||||
|
||||
for (j = 0; j < g_cluster_count1; j++) |
||||
{ |
||||
CLUSTER_COORD* pcc = g_cluster_ptrs1[j]; |
||||
|
||||
if (pcc->marker == i) |
||||
{ |
||||
if (pcc->rect.left < l) l = pcc->rect.left; |
||||
if (pcc->rect.top < t) t = pcc->rect.top; |
||||
if (pcc->rect.right > r) r = pcc->rect.right; |
||||
if (pcc->rect.bottom > b) b = pcc->rect.bottom; |
||||
|
||||
count += pcc->count; |
||||
} |
||||
} |
||||
|
||||
if (count > 0) |
||||
{ |
||||
printf("marker %d l %d t %d r %d b %d\r\n", i, l, t, r, b); |
||||
g_super_cluster_coords1[g_super_cluster_count1].count = count; |
||||
g_super_cluster_coords1[g_super_cluster_count1].excluded = __FALSE; |
||||
g_super_cluster_coords1[g_super_cluster_count1].marker = NO_MARKER; |
||||
g_super_cluster_coords1[g_super_cluster_count1].rect.left = l; |
||||
g_super_cluster_coords1[g_super_cluster_count1].rect.top = t; |
||||
g_super_cluster_coords1[g_super_cluster_count1].rect.right = r; |
||||
g_super_cluster_coords1[g_super_cluster_count1].rect.bottom = b; |
||||
g_super_cluster_count1++; |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue