-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetCross.cs
More file actions
124 lines (117 loc) · 4.31 KB
/
Copy pathGetCross.cs
File metadata and controls
124 lines (117 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
namespace AutoPickingSys
{
class GetCross
{
public void getCrossPoint(Bitmap b, out Point CrossPoint)
{
int width = b.Width;
int height = b.Height;
Point _crossPoint = new Point(0, 0);
bool getCrossP = false;
try
{
if (b != null)
{
BitmapData srcData = b.LockBits(new Rectangle(0, 0, width, height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
unsafe
{
byte* src = (byte*)srcData.Scan0;
byte* nsrc;
int stride = srcData.Stride;
int offset = stride - width * 4;
byte* aimx; byte* aimy; byte* aimr;
nsrc = src;//保存左上角当前指针
for (int i = 1; i < width / 2; i++)
{
for (int j = 1; j < height / 2; j++)
{
int sum = 0;
src = nsrc + i * 4 + j * stride;
for (int m = 0; m < 20; m++)
{
aimx = src + m * 4;
aimy = src + m * stride;
aimr = src + (m + 1) * 4 + (m + 1) * stride;
if (aimx[0] == 0 && aimy[0] == 0 && aimr[0] == 255)
{
sum++;
}
if (sum == 20)
{
getCrossP = true;
_crossPoint = new Point(i, j);
break;
}
}
}
if (getCrossP)
break;
}
b.UnlockBits(srcData);
b.Dispose();
}
}
}
catch (Exception ex)
{
GC.Collect();
}
CrossPoint = _crossPoint;
}
public void getStandardRatio(Bitmap b, Point CrossPoint,out float StandardRatio)
{
int width = b.Width;
int height = b.Height;
Point _crossPoint = new Point(0, 0);
_crossPoint = CrossPoint;
int x; int y;
x = CrossPoint.X; y = CrossPoint.Y;
int sum = 0;
try
{
if (b != null)
{
BitmapData srcData = b.LockBits(new Rectangle(0, 0, width, height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
unsafe
{
byte* src = (byte*)srcData.Scan0;
byte* nsrc;
int stride = srcData.Stride;
int offset = stride - width * 4;
nsrc = src;//保存左上角当前指针
for (int i = x; i < width / 2; i++)
{
//for (int j = y; j < height / 2; j++)
//{
src = nsrc + i * 4 + y * stride;
if (src[0] == 0)
{
sum++;
}
else
{
break;
}
}
}
b.UnlockBits(srcData);
b.Dispose();
}
}
catch (Exception ex)
{
GC.Collect();
}
StandardRatio =(float) 1000 / (float)sum ;
}
//getStandardRatio
}
}