EyemLib.cs
108.6 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
namespace eyemLib_Sharp
{
#region 结构体
// 图像信息
[StructLayout(LayoutKind.Sequential)]
public struct EyemImage
{
public IntPtr vpImage; // 地址
public int iWidth; // 图像内存 x 方向大小
public int iHeight; // 图像内存 y 方向大小
public int iDepth; // 图像位深度(详见说明)
public int iChannels; // 图像通道数
}
// 矩形定义
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect2
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iXe; // 端点(右下) x 坐标
public int iYe; // 端点(右下) y 坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect3
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
public double dVar; // 某种可能会使用的值
}
[StructLayout(LayoutKind.Sequential)]
public struct BboxContainer
{
//最多支持100个目标
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
public EyemRect[] bboxes;
}
///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System
/////////////////////
// int type
//
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXY
{
public int iX; // X坐标
public int iY; // Y坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYZ
{
public int iX; // X坐标
public int iY; // Y坐标
public int iZ; // Z坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYQ
{
public int iX; // X坐标
public int iY; // Y坐标
public int iQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYR // 用于表示圆
{
public int iX; // X坐标
public int iY; // Y坐标
public int iR; // 半径
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIABC // 用于表示直线(一般形式)
{
public int iA; // a
public int iB; // b
public int iC; // c
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIRQ // 用于表示直线(黑森标准形式)或矢量
{
public int iR; // ρ
public int iQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsIXYQS
{
public int iX; // X坐标(单位:像素)
public int iY; // Y坐标(单位:像素)
public int iQ; // 斜率(単位:rad)
public int iS; // 刻度
}
/////////////////////
// float type
//
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXY
{
public float fX; // X坐标
public float fY; // Y坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYZ
{
public float fX; // X坐标
public float fY; // Y坐标
public float fZ; // Z坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYQ
{
public float fX; // X坐标
public float fY; // Y坐标
public float fQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYR // 用于表示圆
{
public float fX; // X坐标
public float fY; // Y坐标
public float fR; // 半径
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFABC // 用于表示直线(一般形式)
{
public float fA; // a
public float fB; // b
public float fC; // c
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFRQ // 用于表示直线(黑森标准形式)或矢量
{
public float fR; // ρ
public float fQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsFXYQS
{
public float fX; // X坐标(単位:像素)
public float fY; // Y坐标(単位:像素)
public float fQ; // 斜率(単位:rad)
public float fS; // 刻度
}
/////////////////////
// double type
//
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXY
{
public double dX; // X坐标
public double dY; // Y坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYZ
{
public double dX; // X坐标
public double dY; // Y坐标
public double dZ; // Z坐标
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYQ
{
public double dX; // X坐标
public double dY; // Y坐标
public double dQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYR // 用于表示圆
{
public double dX; // 中心的X坐标
public double dY; // 中心的Y坐标
public double dR; // 半径
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDABC // 直线(一般形)的表现形式
{
public double dA; // a
public double dB; // b
public double dC; // c
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDRQ // 用于表示直线(黑森标准形状)和矢量
{
public double dR; // ρ
public double dQ; // θ
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYQS
{
public double dX; // X坐标
public double dY; // Y坐标
public double dQ; // 旋转角度(単位:rad)
public double dS; // 规模
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDABCD // 用于表示平面(一般形式)
{
public double dA; // a
public double dB; // b
public double dC; // c
public double dD; // d
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDXYLSQ // 用于表示椭圆
{
public double dXo; // 中心X坐标
public double dYo; // 中心Y坐标
public double dL; // 长轴半径
public double dS; // 短轴半径
public double dQ; // 长轴倾斜角(単位:rad)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDPV // 用于表示三维空间中的直线
{
public EyemOcsDXYZ tP; // 直线上一点的坐标
public EyemOcsDXYZ tV; // 直线方向矢量
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemOcsDCRUVW // 用于表示椭圆体
{
public EyemOcsDXYZ tC; // 椭圆体中心
public EyemOcsDXYZ tR; // 轴半径(dX:长轴、dY:中轴、dZ:短轴)
public double dU; // 长轴投影到 XY 平面与 X 轴的角(单位:rad)
public double dV; // 长轴与XY平面之角(单位:rad)
public double dW; // 绕长轴旋转角度(单位:rad)
}
// Blob 分析结果
[StructLayout(LayoutKind.Sequential)]
public struct EyemBinBlob
{
public int iLabel; // 标签
public int iArea; // 面积
public double dCenterX; // 重心x坐标
public double dCenterY; // 重心y坐标
public int iXs, iYs, iXe, iYe; // 外接矩形(始点,终点)
public int iWidth, iHeight; // 外接矩形(x 方向大小(宽度),y 方向大小(高度))
public double dTheta; // 主轴倾斜角(rad)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemChainCode
{
public int iLabel; // 标签
public double dX; // x坐标
public double dY; // y坐标
public double dVx, dVy; // 向量
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemBlobParams
{
// public bool isLight;
public bool filterByArea; //斑点大小限制
public int minArea, maxArea; //最小面积/最大面积
public bool filterByCircularity; //斑点圆度限制
public float minCircularity, maxCircularity; //圆度最小/大限制
public bool filterByInertia; //斑点的惯性率限制
public float minInertiaRatio, maxInertiaRatio; //惯性率最小/大限制
public bool filterByConvexity; //斑点凸度限制
public float minConvexity, maxConvexity; //凸度最小/大限制
}
// 条码 解码结果
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode
{
public double dAngle; // 角度
public int iCenterX; // x坐标
public int iCenterY; // y坐标
public IntPtr hType; // 码类型
public IntPtr hText; // 码内容
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemModelID
{
public IntPtr vpImage; // 地址
public int iXs; // 图像X坐标
public int iYs; // 图像Y坐标
public int iWidth; // 图像内存X方向大小
public int iHeight; // 图像内存Y方向大小
public double dMatchDeg; // 匹配度
public IntPtr lpszName; // 名称
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRigidMatrix
{
public double a00; // a00
public double a01; // a01
public double b00; // b00
public double a10; // a10
public double a11; // a11
public double b10; // b10
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemHSVModel
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] dpRangeL, dpRangeU; // 提取下限,提取上限[H S V]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public double[] dpRangeLExt, dpRangeUExt; // 额外提取下限,额外提取上限(针对处于跨模型颜色,比如红色)[H S V]
}// 用于HSV颜色模型分割(H(0-180)、S(0-255)、V(0-255))
[StructLayout(LayoutKind.Sequential)]
public struct EyemTargetMatch
{
public float fCenterX;
public float fCenterY;
public float fMatchScore;
public float fMatchAngle;
}
#endregion
public unsafe class EyemLib
{
#region 枚举
//稳健估计方法
public enum ROBUST_METHOD
{
EYEM_DIST_USER = -1,
EYEM_DIST_L1 = 1,
EYEM_DIST_L12 = 2,
EYEM_DIST_FAIR = 3,
EYEM_DIST_WELSCH = 4,
EYEM_DIST_HUBER = 5,
EYEM_DIST_BISQUARE = 6,
EYEM_DIST_CAUCHY = 7,
EYEM_DIST_LOGISTIC = 8,
EYEM_DIST_ANDREWS = 9,
EYEM_DIST_ATLWORTH = 10
}
//图像格式信息
enum ColorConversionCodes
{
COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image
COLOR_RGB2RGBA = COLOR_BGR2BGRA,
COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image
COLOR_RGBA2RGB = COLOR_BGRA2BGR,
COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel)
COLOR_RGB2BGRA = COLOR_BGR2RGBA,
COLOR_RGBA2BGR = 3,
COLOR_BGRA2RGB = COLOR_RGBA2BGR,
COLOR_BGR2RGB = 4,
COLOR_RGB2BGR = COLOR_BGR2RGB,
COLOR_BGRA2RGBA = 5,
COLOR_RGBA2BGRA = COLOR_BGRA2RGBA,
COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"
COLOR_RGB2GRAY = 7,
COLOR_GRAY2BGR = 8,
COLOR_GRAY2RGB = COLOR_GRAY2BGR,
COLOR_GRAY2BGRA = 9,
COLOR_GRAY2RGBA = COLOR_GRAY2BGRA,
COLOR_BGRA2GRAY = 10,
COLOR_RGBA2GRAY = 11,
COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"
COLOR_RGB2XYZ = 33,
COLOR_XYZ2BGR = 34,
COLOR_XYZ2RGB = 35,
COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
COLOR_RGB2HSV = 41,
COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
COLOR_RGB2Lab = 45,
COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
COLOR_RGB2Luv = 51,
COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
COLOR_RGB2HLS = 53,
COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR
COLOR_HSV2RGB = 55,
COLOR_Lab2BGR = 56,
COLOR_Lab2RGB = 57,
COLOR_Luv2BGR = 58,
COLOR_Luv2RGB = 59,
COLOR_HLS2BGR = 60,
COLOR_HLS2RGB = 61,
COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV
COLOR_RGB2YUV = 83,
COLOR_YUV2BGR = 84,
COLOR_YUV2RGB = 85,
};
#endregion
#region 通用
/// <summary>
/// Win32 memory copy function
/// </summary>
/// <param name="dst">目标地址</param>
/// <param name="src">源地址</param>
/// <param name="count">长度</param>
/// <returns></returns>
[DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern byte* memcpy(byte* dst, byte* src, int count);
/// <summary>
/// 动态加载dll
/// </summary>
/// <param name="lpLibFileName">dll文件名</param>
/// <returns></returns>
[DllImport("kernel32.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr LoadLibrary(string lpLibFileName);
/// <summary>
/// 从进程中的非托管内存分配指定长度的内存
/// </summary>
/// <param name="cb">长度</param>
/// <returns>指向新分配的内存指针</returns>
[DllImport("eyemLib.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr eyemMallocMemBlock(int cb);
/// <summary>
/// 释放以前从非托管内存中分配的内存
/// </summary>
/// <param name="block">地址</param>
[DllImport("eyemLib.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemFreeMemBlock(IntPtr block);
/// <summary>
/// 读取图像文件
/// </summary>
/// <param name="filename">文件名</param>
/// <param name="iFlags">读取标志,-1:按照原样加载图像 0:始终将图像转化成单通道灰度图像 1:如果设置,请始终将图像转换为3通道BGR彩色图像
/// 2:在输入具有相应深度时返回16位/32位图像,否则将其转换为8位 4:以任何可能的颜色格式读取图像 </param>
/// <param name="tpImage">图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageRead(string filename, int iFlags, out EyemImage tpImage);
/// <summary>
/// 从指针创建图像
/// </summary>
/// <param name="vpScan0">数据地址</param>
/// <param name="iWidth">数据宽度</param>
/// <param name="iHeight">数据高度</param>
/// <param name="iDepth">数据深度</param>
/// <param name="iChannels">通道数</param>
/// <param name="tpImage">图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageFromBitmap(IntPtr vpScan0, int iWidth, int iHeight, int iDepth, int iChannels, out EyemImage tpImage);
/// <summary>
/// 读取视频,支持彩色
/// </summary>
/// <param name="filename">视频文件名</param>
/// <param name="hObject">返回句柄</param>
/// <param name="tpImages">返回图像</param>
/// <param name="ipNum">图像数量</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemVideoCapture(string filename, out VideoHandle hObject, out EyemImage* tpImages, out int ipNum);
/// <summary>
/// 释放视频资源
/// </summary>
/// <param name="hObject">句柄</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemVideoCaptureFree(IntPtr hObject);
/// <summary>
/// 读取Raw格式图像,仅支持8/16位
/// </summary>
/// <param name="filename">文件名(.raw)</param>
/// <param name="iWidth">图像宽度</param>
/// <param name="iHeight">图像高度</param>
/// <param name="iDepth">图像深度</param>
/// <param name="tpImage">图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageReadRaw(string filename, int iWidth, int iHeight, int iDepth, out EyemImage tpImage);
/// <summary>
/// 释放图像资源
/// </summary>
/// <param name="tpImage">图像</param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImageFree(ref EyemImage tpImage);
// 设定日志回调
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void setLogCallback(TCallBack cb);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemDrawHistogramImage(EyemImage tpImage, out EyemImage tpDstImg, [MarshalAs(UnmanagedType.LPArray)] int[] color, [MarshalAs(UnmanagedType.LPArray)] int[] mean_color, bool isDrawGrid, bool isDrawStats, int normValue);
#endregion
#region 滤波
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemShockFilter(EyemImage tpImage, int kSize, double dSigma, double dBlend, int iIter, out EyemImage tpDstImg);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, double dH, double dSigma);
#endregion
#region 2 值 blob 分析
/// <summary>
/// 自适应二值化图像
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="dSigma">sigma</param>
/// <param name="iLightDark">二值化形式</param>
/// <param name="binMethod">二值化方法</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinAutoThreshold(EyemImage tpImage, double dSigma, int iLightDark, int binMethod, out EyemImage tpDstImg);
/// <summary>
/// 全局二值化
/// </summary>
/// <param name="tpSrcImg">原图</param>
/// <param name="iLightDark">黑白</param>
/// <param name="dThresh">阈值</param>
/// <param name="dMaxVal">最大值</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double dMaxVal, out EyemImage tpDstImg);
/// <summary>
/// 彩色图像分割
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="ipRangeL">下限[0,0,0]</param>
/// <param name="ipRangeU">上限[255,255,255]</param>
/// <param name="tpDstImg">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinThresholdC(EyemImage tpImage, EyemHSVModel tpHSVModel, out EyemImage tpDstImg);
/// <summary>
/// 局部自适应二值化
/// </summary>
/// <param name="tpSrcImg">图像</param>
/// <param name="iLightDark">二值化类型</param>
/// <param name="iWinSize">窗口大小</param>
/// <param name="dK">补偿</param>
/// <param name="binarizationMethod">二值化方法</param>
/// <param name="dR">半径</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinNiBlack(EyemImage tpSrcImg, int iLightDark, int iWinSize, double dK, int binarizationMethod, double dR, out EyemImage tpDstImg);
/// <summary>
/// 动态阈值
/// </summary>
/// <param name="tpSrcImg">图像</param>
/// <param name="tpThresholdImg">处理后图像(一般为滤波后图像)</param>
/// <param name="iOffset">补偿</param>
/// <param name="iLightDark">二值化形式</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, double iOffset, int iLightDark, out EyemImage tpDstImg);
/// <summary>
/// 二值Blob分析
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="hObject">结果句柄</param>
/// <param name="iAreaThrs">面积过滤</param>
/// <param name="tpResult">结果</param>
/// <param name="ipNum">结果数量</param>
/// <param name="tpDstImage">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBinBlob(EyemImage tpImage, out BlobHandle hObject, EyemBlobParams tpParams, out EyemBinBlob* tpResult, out int ipNum, out EyemImage tpDstImage);
/// <summary>
/// 释放Blob资源
/// </summary>
/// <param name="hObject">结果句柄</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemBinFree(IntPtr hObject);
#endregion
#region 矩阵运算
/// <summary>
/// 创建图像
/// </summary>
/// <param name="iWidth">图像宽度</param>
/// <param name="iHeight">图像高度</param>
/// <param name="iChannels">通道数</param>
/// <param name="ccSubType">数据类型(uint8_t、int8_t、uint16_t、int16_t、int32_t、float_t、double_t)</param>
/// <param name="tpImage">图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatMalloc(int iWidth, int iHeight, int iChannels, string ccSubType, out EyemImage tpImage);
/// <summary>
/// 拷贝图像
/// </summary>
/// <param name="tpDstImg">目标图像</param>
/// <param name="tpImage">源图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatCopy(ref EyemImage tpDstImg, EyemImage tpImage);
/// <summary>
/// 图像加运算
/// </summary>
/// <param name="tpImage1">图像</param>
/// <param name="tpImage2">图像</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatAdd(EyemImage tpImage1, EyemImage tpImage2, ref EyemImage tpDstImg);
/// <summary>
/// 图像减运算
/// </summary>
/// <param name="tpImageMinuend">减</param>
/// <param name="tpImageSubtrahend">被减</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, ref EyemImage tpDstImg);
/// <summary>
/// 图像绝对值
/// </summary>
/// <param name="tpImage">图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatAbs(ref EyemImage tpImage);
/// <summary>
/// 图像颜色空间转换
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="iCCodes">转换代码</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCvtImageColor(EyemImage tpImage, ColorConversionCodes iCCodes, ref EyemImage tpDstImg);
/// <summary>
/// 图像数据格式转换
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="ccSubType">转换类型(uint8_t、int8_t、uint16_t、int16_t、int32_t、float_t、double_t)</param>
/// <param name="alpha">乘值</param>
/// <param name="beta">加值</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCvtImageType(EyemImage tpImage, string ccSubType, double alpha, double beta, ref EyemImage tpDstImg);
/// <summary>
/// 图像除运算
/// </summary>
/// <param name="tpImage1">除</param>
/// <param name="tpImage2">被除</param>
/// <param name="tpDstImg">结果图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatDiv(EyemImage tpImage1, EyemImage tpImage2, ref EyemImage tpDstImg);
//图像归一化
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemNormalize(ref EyemImage tpImage);
//通道分离
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDecompose(EyemImage tpImage, out EyemImage tpDstImgR, out EyemImage tpDstImgG, out EyemImage tpDstImgB);
//图像反转
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBitwiseNot(ref EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAffineTransform(EyemImage tpImage, double tAngle, EyemOcsDXY tpCenter, out EyemImage tpDstImg);
//图像偏移
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, out EyemImage tpDstImg, int iInterMethod = 1);
//拷贝指定位置的图像
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCopyRegion(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//统计非零像素数量
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountNonZero(EyemImage tpImage);
#endregion
#region 一维边缘测量
//边缘测量
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, string strSubType, int iTransition, double dSigma, double dAmpThresh, out MeasureHandle hObject);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
//边缘查找
private static extern int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, out MeasureHandle hObject);
/// <summary>
/// 边缘查找工具
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="tpLineSt">卡尺起点</param>
/// <param name="tpLineEd">卡尺终点</param>
/// <param name="iCapLength">卡尺长度</param>
/// <param name="iCapWidth">卡尺宽度</param>
/// <param name="nCalipers">卡尺数量</param>
/// <param name="nFilterSize">滤波尺寸(默认为2,如果边缘较窄可以设置为1,建议范围[1,5])</param>
/// <param name="iSearchDirec">搜索方向</param>
/// <param name="dAmpThreshold">边缘阈值</param>
/// <param name="ccTransition">提取模式("all","positive","negative")</param>
/// <param name="hObject">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, string ccTransition, out MeasureHandle hObject);
/// <summary>
/// 圆形边缘查找工具
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="tpPoint">位置坐标</param>
/// <param name="iRadius">半径</param>
/// <param name="iCapLength">卡尺长度</param>
/// <param name="iCapWidth">卡尺宽度</param>
/// <param name="nCalipers">卡尺数量</param>
/// <param name="nFilterSize">滤波尺寸</param>
/// <param name="iSearchDirec">交换搜索方向</param>
/// <param name="dAmpThreshold">边缘阈值</param>
/// <param name="ccTransition">提取模式("all","positive","negative")</param>
/// <param name="hObject">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, string ccTransition, out MeasureHandle hObject);
//边缘
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemEdgesPixel(EyemImage tpImage, double dThreshold, out IntPtr hObject, out int ipNum, out EyemOcsDXY* hResults);
//释放工具所使用句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemEdge1dGenMeasureFree(IntPtr hObject);
#endregion
#region 稳健估计
/// <summary>
/// 鲁棒直线拟合
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPoint">点</param>
/// <param name="iCalcMode">计算方式</param>
/// <param name="dRobustCoef">鲁棒系数,如果采用预设定的值则设置为0</param>
/// <param name="tpLine">直线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemRobustFitLine(int iPtnNum, IntPtr taPoint, int iCalcMode, double dRobustCoef, ref EyemOcsDABC tpLine);
/// <summary>
/// 直线拟合
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPoint">点</param>
/// <param name="numToIgnore">忽略的点</param>
/// <param name="tpLine">直线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFitLine(int iPtnNum, IntPtr taPoint, int numToIgnore, ref EyemOcsDABC tpLine);
/// <summary>
/// RANSAC拟合圆
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPoint">点</param>
/// <param name="dClippingFactor">消除异常值因子</param>
/// <param name="tpLine">线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFitLineRANSAC(int iPtnNum, IntPtr taPoint, double dClippingFactor, ref EyemOcsDABC tpLine);
/// <summary>
/// 鲁棒圆拟合
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPoint">点</param>
/// <param name="iCalcMode">计算方式</param>
/// <param name="dRobustCoef">鲁棒系数,如果采用预设定的值则设置为0</param>
/// <param name="tpCircle">圆</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemRobustFitCircle(int iPtnNum, IntPtr taPoint, int iCalcMode, double dRobustCoef, ref EyemOcsDXYR tpCircle);
/// <summary>
/// 圆拟合
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPoint">点</param>
/// <param name="iCalcMode">计算方式</param>
/// <param name="numToIgnore">忽略的点</param>
/// <param name="RMS">rms误差</param>
/// <param name="tpCircle">圆</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFitCircle(int iPtnNum, IntPtr taPoint, int numToIgnore, ref double dRMS, ref EyemOcsDXYR tpCircle);
/// <summary>
/// 鲁棒平面拟合
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPoint">点</param>
/// <param name="iCalcMode">计算模式</param>
/// <param name="dRobustCoef">鲁棒系数,如果采用预设定的值则设置为0</param>
/// <param name="tpPlane">平面</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemRobustFitPlane(int iPtnNum, IntPtr taPoint, int iCalcMode, double dRobustCoef, ref EyemOcsDABCD tpPlane);
/// <summary>
/// 刚性变换
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPointA">A坐标系中的点</param>
/// <param name="taPointB">B坐标系中的点</param>
/// <param name="tpResult">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFitRTMatrix(int iPtnNum, bool bFullAffine, IntPtr taPointA, IntPtr taPointB, ref EyemRigidMatrix tpResult);
/// <summary>
/// 鲁棒椭圆拟合
/// </summary>
/// <param name="iPtnNum">点数量</param>
/// <param name="taPoint">点</param>
/// <param name="iCalcMode">计算方式</param>
/// <param name="dRobustCoef">鲁棒系数,如果采用预设定的值则设置为0</param>
/// <param name="tpEllipse">椭圆</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemRobustFitEllipse(int iPtnNum, IntPtr taPoint, int iCalcMode, double dRobustCoef, ref EyemOcsDXYLSQ tpEllipse);
#endregion
#region 二维几何计算
/// <summary>
/// 根据两个点计算直线
/// </summary>
/// <param name="tpPoint1">点一</param>
/// <param name="tpPoint2">点二</param>
/// <param name="tpLine">直线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, ref EyemOcsDABC tpLine);
/// <summary>
/// 计算两直线交点
/// </summary>
/// <param name="tpLine1">线一</param>
/// <param name="tpLine2">线二</param>
/// <param name="taPoint">交点</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, ref EyemOcsDXY tpPoint);
/// <summary>
/// 计算两点的垂直平分线
/// </summary>
/// <param name="tpPoint1">点一</param>
/// <param name="tpPoint2">点二</param>
/// <param name="tpLine">线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, ref EyemOcsDABC tpLine);
/// <summary>
/// 过一点作已知直线的垂线
/// </summary>
/// <param name="tpPoint"></param>
/// <param name="tpLine"></param>
/// <param name="tpVertical"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, ref EyemOcsDABC tpVertical);
/// <summary>
/// 指定点和斜率计算直线
/// </summary>
/// <param name="tpPoint">点</param>
/// <param name="dSlope">斜率(角度)</param>
/// <param name="tpLine">直线</param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, ref EyemOcsDABC tpLine);
/// <summary>
/// 计算两直线角度(锐角)
/// </summary>
/// <param name="tpLine1">直线一</param>
/// <param name="tpLine2">直线二</param>
/// <param name="dpAngle">角度</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, ref double dpAngle);
/// <summary>
/// 两条直线的角平分线
/// </summary>
/// <param name="tpLine1">直线一</param>
/// <param name="tpLine2">直线二</param>
/// <param name="tpLineC">直线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dCenterLineOfTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, ref EyemOcsDABC tpLineC);
/// <summary>
/// 计算点到直线距离
/// </summary>
/// <param name="tpPoint">点</param>
/// <param name="tpLine">直线</param>
/// <param name="dpDist">距离</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dDistancePointToLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, ref double dpDist);
/// <summary>
/// 直线平移
/// </summary>
/// <param name="tpSrcL">直线</param>
/// <param name="tpTrans">点</param>
/// <param name="tpDstL">移动后的直线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dTranslationOfLine(EyemOcsDABC tpSrcL, EyemOcsDXY tpTrans, ref EyemOcsDABC tpDstL);
/// <summary>
/// 计算三角形面积
/// </summary>
/// <param name="tpPoint1">点1</param>
/// <param name="tpPoint2">点2</param>
/// <param name="tpPoint3">点3</param>
/// <param name="dpArea">面积</param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemClp2dAreaTriangle(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, ref double dpArea);
/// <summary>
/// 根据三个点计算圆
/// </summary>
/// <param name="tpPoint1">点1</param>
/// <param name="tpPoint2">点2</param>
/// <param name="tpPoint3">点3</param>
/// <param name="tpCircle">圆</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dCircleThreePoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, ref EyemOcsDXYR tpCircle);
/// <summary>
/// 直线与圆交点
/// </summary>
/// <param name="tpLine"></param>
/// <param name="tpCircle"></param>
/// <param name="tpPoint1"></param>
/// <param name="tpPoint2"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dIntersectionLineAndCircle(EyemOcsDABC tpLine, EyemOcsDXYR tpCircle, ref EyemOcsDXY tpPoint1, ref EyemOcsDXY tpPoint2);
/// <summary>
/// 点到圆的切线及切点
/// </summary>
/// <param name="tpPoint">点</param>
/// <param name="tpCircle">圆</param>
/// <param name="tpTangent1">切线一</param>
/// <param name="tpContact1">切点一</param>
/// <param name="tpTangent2">切线二</param>
/// <param name="tpContact2">切点二</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dTangentPointToCircle(EyemOcsDXY tpPoint, EyemOcsDXYR tpCircle, ref EyemOcsDABC tpTangent1, ref EyemOcsDXY tpContact1, ref EyemOcsDABC tpTangent2, ref EyemOcsDXY tpContact2);
#endregion
#region 深度学习目标检测器
/// <summary>
/// 初始化检测器
/// </summary>
/// <param name="detectorConfigPath">配置文件</param>
/// <param name="detectorModelPath">模型文件</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitNNDetector(string detectorConfigPath, string detectorModelPath, int iNetSizew, int iNetSizeh);
/// <summary>
/// 设置检测参数
/// </summary>
/// <param name="fConfidence">置信度</param>
/// <param name="fNMSThreshold">非极大值抑制阈值</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemNNDetectorParams(float fConfidence, float fNMSThreshold);
/// <summary>
/// 目标检测器
/// </summary>
/// <param name="tpImage">输入图像</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemNNDetector(EyemImage tpImage, out int ipNum, ref BboxContainer container, out EyemImage tpDstImg);
/// <summary>
/// 初始化darknet分类器
/// </summary>
/// <param name="classifierConfigPath">配置地址</param>
/// <param name="classifierModelPath">模型地址</param>
/// <param name="ntype">0 检测网络,1 分类网络</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitClassifier(string classifierConfigPath, string classifierModelPath, int ntype);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClassifier(EyemImage tpImage);
/// <summary>
/// 初始化ONNX模型(10.0)
/// </summary>
/// <param name="extractorModelPath">模型路径</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitONNXModel(string extractorModelPath);
/// <summary>
/// 特征提取器
/// </summary>
/// <param name="tpImage">图像(128X128)</param>
/// <param name="fFeatures">特征</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemExtractWithONNX(EyemImage tpImage, [MarshalAs(UnmanagedType.LPArray)] float[] fFeatures);
#endregion
#region 模板匹配
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMakeShapeModel(EyemImage tpImage, double dContrast, double dMinContrast, int iApertureSize = 3, bool bL2gradient = false);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFindShapeModel(EyemImage tpImage, int iNumLevels, double dAngleStart, double dAngleExtent, double dAngleStep, double dMinContrast, double dContrast, double dGreediness, double dMinScore, bool bOptimization = true);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMakeNCCModel(EyemImage tpImage, int iiMinReduceArea);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemFindNCCModel(EyemImage tpImage, double dToleranceAngle, int iNumMatches, double dMaxOverlap, double dScore, bool bDrawResult, IntPtr tpResults, out EyemImage tpDstImg);
#endregion
#region 项目
//初始化计数器
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitCounter(string extractorModelPath);
//普通器件(仍采用旧的算法)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//异型器件(新版本新算法)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, string fileName, string strType, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//普通器件(新版本新算法)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//异型器件(新版本模板匹配)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, string fileName, string ccTplName, IntPtr hModelID, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//多选项异型件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int[] iOptions, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//普通器件(深度学习分割)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectUseNN(EyemImage tpImage, EyemRect tpRoi, string fileName, [MarshalAs(UnmanagedType.LPArray)] int[] ipReelNum, out EyemImage tpDstImg);
//匹配元件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//创建模板匹配模型
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, string ccTplName);
//获取模板图像
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//选取最匹配模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatchTemplateModel(EyemImage tpImage, IntPtr hModelID, ref string lpszTplName);
//加载模板到内存
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitModel(string ccTplName, out IntPtr hModelID);
//通过名称获取模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAchvModelByName(string ccTplName, IntPtr hModelID, ref EyemModelID tpModelID);
//插入模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInsertModel(IntPtr hModelID, string ccTplName);
//通过名称移除模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemRemoveModelByName(IntPtr hModelID, string ccTplName);
//释放模板内存
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemReleaseModel(ref IntPtr hModelID);
//读码程序
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
//释放解码句柄
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
//基于深度学习读码程序(仅支持QR、DataMatrix)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, out EyemImage tpDstImg);
//基于深度学习一维码读码程序()
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecodeBarcodeUseNN(EyemImage tpImage, EyemRect tpRoi, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, out EyemImage tpDstImg);
//加载模型配置文件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitNNDataCodeModel(string detectorConfigPath, string detectorModelPath, string superResolutionConfigPath, string superResolutionModelPath);
//背景变化跟踪
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemTrackFeature(EyemImage tpImage, EyemImage tpMask, EyemRect tpRoi, IntPtr tpRois, int ipRoiNum, EyemHSVModel tpHSVModel, [MarshalAs(UnmanagedType.LPArray)] int[] ipResults, out EyemImage tpDstImg);
//插件机
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAOIPreprocessingForTSAV(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//跳过程序执行
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setSkipProcessID(int pid);
//圆形mark点定位
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, ref EyemOcsFXYR tpCircle, out EyemImage tpDstImg, bool bHighAccuracy = false);
//多功能工具
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, string funcName, double dThreshold, int iNumToIgnore, ref EyemOcsFXYR tpCircle, out EyemImage tpDstImg);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectCircleUseHough(EyemImage tpImage, EyemRect tpRoi, EyemRect limRoi, out EyemOcsDXYR tpCircle, out EyemImage tpDstImg, double dp, double dMinDist, double dParam1, double dParam2, double dMinRadius, double dMaxRadius, int iMethod = 3, bool useValLimit = false);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void loadImage2Mem(string key, EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setProcessLevel(double pl);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setFineTuning(double ft);
/// <summary>
/// 对图像进行采样生成训练样本
/// </summary>
/// <param name="tpImage">图像</param>
/// <param name="iSize">尺寸128(最大224)</param>
/// <param name="ccClassName">类名</param>
/// <param name="ccToPath">保存路径</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemTrainImageSampler(EyemImage tpImage, int iSize, string ccClassName, string ccToPath, out EyemImage tpMatchImg, out EyemImage tpDstImg);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBuildTrainFile(string filePath, string fileName, bool shuffle = true);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern float calcSimilarity([MarshalAs(UnmanagedType.LPArray)] float[] lhs, [MarshalAs(UnmanagedType.LPArray)] float[] rhs);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemSIFTBasedMatch(EyemImage tpImage, EyemImage tpTargetImg, EyemImage tpMask, double dMinScore, out EyemImage tpDstImg);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCalcReelTHK(EyemImage tpImage, EyemImage tpMask, IntPtr ptResults, ref double dThickness);
#endregion
#region 测试专用接口
//测试接口
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemLibImpl(EyemImage tpImage, out EyemImage tpDstImg);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemEdge1dRidgeDetection(EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAchvMaskImage(EyemImage tpImage, out EyemImage tpDstImg, out EyemImage tpPrevImg);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemSplitMask(EyemImage tpImage, EyemImage tpMask, string toPath, string className);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemNamedWindow(string winName);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImshow(string winName, EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemWaitkey();
#endregion
#region 日志功能
// 日志回调
public delegate void TCallBack(string msg);
public static TCallBack sld = new TCallBack(TLogCallback);
public static event TCallBack OnNewLogCallback;
public static void TLogCallback(string msg)
{
OnNewLogCallback?.Invoke(msg);
}
public static log4cpp.LogManager logcpp = null;
public static void Init()
{
logcpp = new log4cpp.LogManager("D:\\日志\\", "_运行日志", log4cpp.GenerateMode.ByEveryDay);
setLogCallback(sld);
OnNewLogCallback += new TCallBack(EyemLib_OnNewLogCallback);
//EyemImage image_back = new EyemImage();
//eyemImageRead("D:\\Img20211028142015.png", -1, out image_back);
//loadImage2Mem("back", image_back);
//eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", ".\\darknet\\sr.prototxt", ".\\darknet\\sr.caffemodel");
//eyemInitClassifier("D:\\detect-tiny-tray.cfg", "D:\\detect-tiny-tray.weights", 0);
//eyemInitONNXModel("D:\\训练数据集\\Parts-11\\backup\\ec_model.onnx");
//eyemInitCounter("D://pre_segmentation.onnx");
}
public static void Free()
{
setLogCallback(null); sld = null;
}
//记录日志
private static void EyemLib_OnNewLogCallback(string msg)
{
//算法里输出的一切日志都会在这里
logcpp.WriteLog("[" + Thread.CurrentThread.ManagedThreadId.ToString("X16") + "]" + msg);
}
//设置跳过程序执行
public static void setSkipProcess(int pid)
{
setSkipProcessID(pid);
}
#endregion
public static void eyemReadImageTool(string fileName)
{
EyemImage image = new EyemImage();
EyemImage tpDstImg = new EyemImage();
int flag = eyemImageRead(fileName, -1, out image);
if (flag != 0)
{
Console.WriteLine("读图失败!");
return;
}
Stopwatch sw = new Stopwatch();
sw.Restart();
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//_ = eyemBinThreshold(image, 1, 45, 255, out tpDstImg);
////eyemNamedWindow("test");
////eyemImshow("test", image);
////eyemWaitkey();
//return;
//flag = eyemInitNNDetector(".\\darknet\\cifar_resnet50.cfg", ".\\darknet\\cifar_resnet50.weights", 640, 640);
//flag = eyemInitNNDetector("", "d://tray_detectv7.onnx", 640, 640);
//if (flag == 0)
//{
// eyemNNDetectorParams(0.35f, 0.45f);
// int ipNum;
// sw.Restart();
// BboxContainer bboxes = new BboxContainer();
// eyemNNDetector(image, out ipNum, ref bboxes, out tpDstImg);
// Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
// if (bitmap != null)
// {
// bitmap.Save("D:\\ResOut\\" + file);
// }
// eyemImageFree(ref tpDstImg);
//}
//sw.Stop();
//Console.WriteLine(sw.ElapsedMilliseconds.ToString());
//eyemImageFree(ref image);
//return;
//flag = eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", "", "") & eyemInitNNDetector(".\\darknet\\detect-tiny-label.cfg", ".\\darknet\\detect-tiny-label.weights");
////红色分割
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 0, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 10, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 156, 43, 46 }; tpHsvModel.dpRangeUExt = new double[] { 180, 255, 255 };
////绿色分割模型
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 55, 10, 35 }; tpHsvModel.dpRangeU = new double[] { 100, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
////绿色分割模型
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 55, 10, 35 }; tpHsvModel.dpRangeU = new double[] { 100, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//EyemRect tpRoi0 = new EyemRect();
//tpRoi0.iXs = 0; tpRoi0.iYs = 0;
//tpRoi0.iWidth = image.iWidth;
//tpRoi0.iHeight = image.iHeight;
////sw.Restart();
//List<EyemRect> tpRois = new List<EyemRect>();
//EyemRect roi1 = new EyemRect();
//roi1.iXs = 470; roi1.iYs = 143; roi1.iWidth = 411; roi1.iHeight = 387;
//EyemRect roi2 = new EyemRect();
//roi2.iXs = 882; roi2.iYs = 84; roi2.iWidth = 317; roi2.iHeight = 251;
////添加需要监控的位置信息
//tpRois.Add(roi1); tpRois.Add(roi2);
////结构体转内存指针
//IntPtr hGlobal = eyemStructArray2IntPtr(tpRois.ToArray());
////加载mask
//EyemImage mask;
//eyemImageRead("mask.png", -1, out mask);
////
//int[] ipResults = new int[tpRois.Count];
//eyemTrackFeature(image, mask, tpRoi0, hGlobal, ipResults.Length, tpHsvModel, ipResults, out tpDstImg);
//for (int i = 0; i < ipResults.Length; i++)
//{
// if (ipResults[i] == 1)
// {
// Console.WriteLine("检测到{0}位置有料盘", i);
// }
//}
//sw.Stop();
//Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
////蓝色分割
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 100, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 124, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//分类器
//eyemClassifier(image);
//sw.Restart();
////遍历所有文件
//string[] fileImages = Directory.GetFiles(@"D:\ResOut\Image2\", "*.*", SearchOption.AllDirectories);
//string[] fileMasks = Directory.GetFiles(@"D:\ResOut\Mask2\", "*.*", SearchOption.AllDirectories);
//for (int i = 0; i < fileMasks.Length; i++)
//{
// string className = Path.GetFileNameWithoutExtension(fileMasks[i]);
// //创建文件夹
// string targetPath = "D:\\ResOut\\SplitImage2\\" + className;
// if (!Directory.Exists(targetPath))
// {
// Directory.CreateDirectory(targetPath);
// }
// string targetPath2 = "D:\\ResOut\\SplitMask2\\" + className;
// if (!Directory.Exists(targetPath2))
// {
// Directory.CreateDirectory(targetPath2);
// }
// //
// EyemImage tpImage, tpMask;
// eyemImageRead(fileMasks[i], -1, out tpMask);
// eyemImageRead(fileImages[i], -1, out tpImage);
// eyemSplitMask(tpImage, tpMask, "D:\\ResOut\\", className);
// //释放资源
// eyemImageFree(ref tpImage);
// eyemImageFree(ref tpMask);
//}
//index++;
//EyemImage tpPrevImg = new EyemImage();
//flag = eyemAchvMaskImage(image, out tpDstImg, out tpPrevImg);
//sw.Restart();
//eyemAffineTransform(image, 90, new EyemOcsDXY(), out image);
//彩色图像预处理
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 35, 60, 20 }; tpHsvModel.dpRangeU = new double[] { 100, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//tpHsvModel.dpRangeL = new double[] { 60, 56, 50 }; tpHsvModel.dpRangeU = new double[] { 80, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//tpHsvModel.dpRangeL = new double[] { 0, 130, 46 }; tpHsvModel.dpRangeU = new double[] { 10, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
//EyemImage tpMask;
//eyemBinThresholdC(image, tpHsvModel, out tpMask);
//EyemRect tpRoi0 = new EyemRect();
//tpRoi0.iXs = 4420; tpRoi0.iYs = 2206;
//tpRoi0.iWidth = 639;
//tpRoi0.iHeight = 1373;
//////预处理提取出PCB板
//flag = eyemAOIPreprocessingForTSAV(image, tpRoi0, out tpDstImg);
//sw.Stop();
//Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
flag = eyemLibImpl(image, out tpDstImg);
return;
//
//eyemImageRead("D:/mask.png", 0, out tpMask);
//Bitmap bitmap = eyemCvtToBitmap(image);
//eyemBinThresholdC(image, tpHsvModel, out image);
//eyemNamedWindow("image");
//eyemImshow("image", image);
//eyemWaitkey();
//EyemOcsIXY[] tpResults = new EyemOcsIXY[4];
//var hHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(EyemOcsIXY)) * tpResults.Length);
//double dThickness = 0;
//eyemCalcReelTHK(image, tpMask, hHandle, ref dThickness);
//tpResults = eyemIntPtr2StructArray<EyemOcsIXY>(hHandle, tpResults.Length).ToArray();
//using (var g = Graphics.FromImage(bitmap))
//{
// for (int i = 0; i < 4; i++)
// {
// g.DrawLine(new Pen(Brushes.LimeGreen, 12), new Point(tpResults[i].iX, tpResults[i].iY), new Point(tpResults[(i + 1) % 4].iX, tpResults[(i + 1) % 4].iY));
// }
//}
//if (bitmap != null)
//{
// bitmap.Save("D:\\ResOut\\" + file);
//}
//eyemImageFree(ref image);
////eyemImageFree(ref tpMask);
//eyemImageFree(ref tpDstImg);
//Marshal.FreeHGlobal(hHandle);
//return;
//flag = eyemAffineTransform(image, 2.2965, out tpDstImg);
//sw.Stop();
//Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
//float[] fFeatures = new float[512];
//eyemExtractWithONNX(image, fFeatures);
//string ftrs = string.Join(" ", fFeatures).Trim();
//using (FileStream fs = new FileStream("D:\\Resout\\" + file.Replace("png", "txt"), FileMode.Create))
//{
// using (StreamWriter pr = new StreamWriter(fs))
// {
// pr.WriteLine(ftrs);
// pr.Flush();
// }
//}
//EyemImage tpMatchImg;
//eyemTrainImageSampler(image, 128, "PID012", "D:\\ResOut", out tpMatchImg, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save("D:\\ResOut\\Mask2\\" + index.ToString().PadLeft(5, '0') + ".png");
//}
//Bitmap bitmap2 = eyemCvtToBitmap(tpPrevImg);
//if (bitmap2 != null)
//{
// bitmap2.Save("D:\\ResOut\\Image2\\" + index.ToString().PadLeft(5, '0') + ".png");
//}
////释放资源
//Marshal.FreeHGlobal(hGlobal);
//每运行检测一次释放一次
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//////////mask可以在程序启动与关闭时加载/释放
//eyemImageFree(ref tpMask);
//eyemImageFree(ref tpDstImg);
//////eyemImageFree(ref tpPrevImg);
//return;
#region 插件机AOI流程
//EyemImage search, templ, template;
////每次运行检测获取的待检测图像
////flag = eyemImageRead("D://search.png", -1, out search);
////if (flag != 0)
////{
//// Console.WriteLine("读图失败!");
//// return;
////}
//////一开始获取的模板图像,保存用来划定检测区域
////flag = eyemImageRead("D://template.png", -1, out template);
////if (flag != 0)
////{
//// Console.WriteLine("读图失败!");
//// return;
////}
//search = eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://search1.bmp"));
//template = eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://template1.bmp"));
////制作模板时元件位置
//List<EyemRect> tpRois = new List<EyemRect>();
//EyemRect roi1 = new EyemRect();
//roi1.iXs = 151; roi1.iYs = 273; roi1.iWidth = 330; roi1.iHeight = 119;
//EyemRect roi2 = new EyemRect();
//roi2.iXs = 119; roi2.iYs = 589; roi2.iWidth = 70; roi2.iHeight = 155;
//tpRois.Add(roi1); tpRois.Add(roi2);
//int iNumMatches = 10;
//double dToleranceAngle = 180.0;
//double dMaxOverlap = 0.0;
//double dScore = 0.8;
//EyemOcsDXY dXY = new EyemOcsDXY();
//List<EyemOcsDXY> dXiesA = new List<EyemOcsDXY>() { };//测试图中的点
//List<EyemOcsDXY> dXiesB = new List<EyemOcsDXY>() { };//基准图中的点
////模板匹配
//EyemTargetMatch[] tpResults = new EyemTargetMatch[iNumMatches];
//var ResultHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(EyemTargetMatch)) * tpResults.Length);
//flag = eyemMakeNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//search1.jpg")), 256);//614 152
//if (flag != 0)
// return;
//flag = eyemFindNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//search1.bmp")), dToleranceAngle, iNumMatches, dMaxOverlap, dScore, true, ResultHandle, out tpDstImg);
//if (flag != 0)
// return;
//tpResults = eyemIntPtr2StructArray<EyemTargetMatch>(ResultHandle, tpResults.Length).ToArray();
//eyemCvtToBitmap(tpDstImg).Save("D:\\ResOut\\" + "x.png");
//return;
//eyemNamedWindow("dst");
//eyemImshow("dst", tpDstImg);
//eyemWaitkey();
//eyemImageFree(ref tpDstImg);
//dXY.dX = 614 + Image.FromFile("D://批量测试图像//top.png").Width / 2;
//dXY.dY = 152 + Image.FromFile("D://批量测试图像//top.png").Height / 2;
//dXiesB.Add(dXY);
//dXY.dX = tpResults[0].fCenterX;
//dXY.dY = tpResults[0].fCenterY;
//dXiesA.Add(dXY);
////eyemCvtToBitmap(tpDstImg).Save("D:\\ResOut\\" + "x.png");
////框选模板匹配位置
//EyemRect tpRoiTemplate = new EyemRect();
//tpRoiTemplate.iXs = tpRoiTemplate.iYs = 15;
//tpRoiTemplate.iWidth = 109;
//tpRoiTemplate.iHeight = 259;
//eyemCopyRegion(search, tpRoiTemplate, out templ);
//eyemNamedWindow("templ");
//eyemImshow("templ", templ);
//eyemWaitkey();
//flag = eyemMakeNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//bot.png")), 256);//1052 1156
//if (flag != 0)
// return;
//flag = eyemFindNCCModel(eyemCvtToEyemImage2((Bitmap)Image.FromFile("D://批量测试图像//search.bmp")), dToleranceAngle, iNumMatches, dMaxOverlap, dScore, true, ResultHandle, out tpDstImg);
//if (flag != 0)
// return;
//tpResults = eyemIntPtr2StructArray<EyemTargetMatch>(ResultHandle, tpResults.Length).ToArray();
//eyemNamedWindow("dst");
//eyemImshow("dst", tpDstImg);
//eyemWaitkey();
//eyemImageFree(ref tpDstImg);
//dXY.dX = 1052 + Image.FromFile("D://批量测试图像//bot.png").Width / 2;
//dXY.dY = 1156 + Image.FromFile("D://批量测试图像//bot.png").Height / 2;
//dXiesB.Add(dXY);
//dXY.dX = tpResults[0].fCenterX;
//dXY.dY = tpResults[0].fCenterY;
//dXiesA.Add(dXY);
//var mtx = new EyemRigidMatrix();
//eyemFitRTMatrix(dXiesA.Count, false, eyemStructArray2IntPtr(dXiesA.ToArray()), eyemStructArray2IntPtr(dXiesB.ToArray()), ref mtx);
//return;
////flag = eyemMakeShapeModel(templ, 100, 10);
////flag = eyemFindShapeModel(search, 10, 0, 90, 1, 10, 100, 0.7, 0.7);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// for (int i = 0; i < tpRois.Count; i++)
// {
// using (Graphics g = Graphics.FromImage(bitmap))
// {
// g.DrawRectangle(Pens.Red, new Rectangle(tpRois[i].iXs, tpRois[i].iYs, tpRois[i].iWidth, tpRois[i].iHeight));
// }
// }
// bitmap.Save("D:\\ResOut\\" + "old.png");
//}
//for (int i = 0; i < tpResults.Length; i++)
//{
// if (tpResults[i].fMatchScore > 0)
// {
// Console.WriteLine(string.Format("目标{0},位置({1},{2}),匹配分数{3}",
// i, tpResults[i].fCenterX.ToString("F3"), tpResults[i].fCenterY.ToString("F3"), tpResults[i].fMatchScore.ToString("F3")));
// }
//}
////根据模板匹配重新确定候选框位置
//EyemRect rect = new EyemRect();
//for (int i = 0; i < tpRois.Count; i++)
//{
// int offsetX = tpRois[i].iXs - (int)(Math.Round(tpResults[0].fCenterX - templ.iWidth / 2.0)) + tpRoiTemplate.iXs;
// int offsetY = tpRois[i].iYs - (int)(Math.Round(tpResults[0].fCenterY - templ.iHeight / 2.0)) + tpRoiTemplate.iYs;
// rect.iXs = offsetX;
// rect.iYs = offsetY;
// rect.iWidth = tpRois[i].iWidth; rect.iHeight = tpRois[i].iHeight;
// tpRois[i] = rect;
//}
//Bitmap bitmap1 = new Bitmap("D://search1.bmp");
//for (int i = 0; i < tpRois.Count; i++)
//{
// using (Graphics g = Graphics.FromImage(bitmap1))
// {
// g.DrawRectangle(Pens.Red, new Rectangle(tpRois[i].iXs, tpRois[i].iYs, tpRois[i].iWidth, tpRois[i].iHeight));
// }
//}
//using (Graphics g = Graphics.FromImage(bitmap1))
//{
// g.DrawRectangle(Pens.Green, new Rectangle(tpRoiTemplate.iXs, tpRoiTemplate.iYs, tpRoiTemplate.iWidth, tpRoiTemplate.iHeight));
//}
//bitmap1.Save("D:\\ResOut\\new.png");
//sw.Stop();
//Console.WriteLine("时间花费" + sw.ElapsedMilliseconds.ToString());
//eyemImageFree(ref templ);
//eyemImageFree(ref search);
//eyemImageFree(ref template);
//Marshal.FreeHGlobal(ResultHandle);
//return;
#endregion
//return;
//EyemImage image1 = new EyemImage(); EyemImage image2 = new EyemImage(); EyemImage image3 = new EyemImage();
//eyemDecompose(image, out image1, out image2, out image3);
//flag = eyemBinThresholdC(image, tpHsvModel, out tpDstImg);
//sw.Restart();
//EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//flag = eyemMarkerTracing(image, tpHsvModel, ref tpCircle, out tpDstImg, false);
//eyemImageFree(ref tpDstImg);
//sw.Stop();
//Console.WriteLine("时间:" + sw.ElapsedMilliseconds.ToString());
//flag = eyemShockFilter(image, 9, 1.5, 0.5, 10, out tpDstImg);
//flag = eyemNonLocalMeansFilter(image, 7, 21, 3.0, -1);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save(/*System.Windows.Forms.Application.StartupPath +*/ "D:\\ResOut\\" + file);
//}
//eyemImageFree(ref image);
//eyemImageFree(ref tpDstImg);
//return;
#region Test Blob
//sw.Restart();
//EyemBlobParams tpParams = new EyemBlobParams();
////tpParams.isLight = true;
//tpParams.filterByArea = true; tpParams.minArea = 25; tpParams.maxArea = int.MaxValue;
//tpParams.filterByCircularity = false; tpParams.minCircularity = 0.8F; tpParams.maxCircularity = float.MaxValue;
//tpParams.filterByConvexity = false; tpParams.minConvexity = 0.95F; tpParams.maxConvexity = float.MaxValue;
//tpParams.filterByInertia = false; tpParams.minInertiaRatio = 0.8F; tpParams.maxInertiaRatio = float.MaxValue;
//int ipNum;
//BlobHandle hObject;
//EyemBinBlob* tpResults;
//eyemBinBlob(image, out hObject, tpParams, out tpResults, out ipNum, out tpDstImg);
//sw.Stop();
//for (int i = 0; i < ipNum; i++)
//{
// Console.WriteLine(tpResults[i].iArea);
//}
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//hObject.Dispose();
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//Console.WriteLine("时间-:" + sw.ElapsedMilliseconds.ToString());
//return;
#endregion
#region Test 1DEdge
//EyemOcsDXY tpLineSt = new EyemOcsDXY();
//tpLineSt.dX = 62;
//tpLineSt.dY = 62;
//EyemOcsDXY tpLineEd = new EyemOcsDXY();
//tpLineEd.dX = 23.5;
//tpLineEd.dY = 40.5;
//MeasureHandle hObject;
////eyemEdge1dGenMeasureRect(image, tpLineSt, tpLineEd, 10, "all", 0, 0.9, 30, out hObject);
////eyemEdge1dGenPosRect(image, tpLineSt, tpLineEd, 50, 0, 0.9, 30, out hObject);
//sw.Restart();
////eyemEdge1dFindLine(image, tpLineSt, tpLineEd, 15, 5, 10, 2, 1, 35, "all", out hObject);
////eyemEdge1dFindCircle(image, tpLineSt, 21, 12, 3, 10, 1, -1, 35, "negative", out hObject);
//sw.Stop();
//Console.WriteLine("时间:" + sw.ElapsedMilliseconds.ToString());
//eyemEdge1dGenMeasureRect(image, tpLineSt, tpLineEd, 1, "", 1, 0, 0, out hObject);
//eyemEdge1dGenPosRect(image, tpLineSt, tpLineEd, 1, 1, 1, 1, out hObject);
//return;
#endregion
#region Test Matrix
//double[] dpData = new double[9] { 1, 0, 1, 2, 2, 2, 3, 3, 3 };
//IntPtr vpA = eyemMatMallocMatrix(3, 3, dpData);
//eyemMatZero(vpA);
//double[] dpData2 = new double[9] { 1, 0, 1, 2, 0, 2, 3, 0, 3 };
//IntPtr vpB = eyemMatMallocMatrix(3, 3, dpData);
//IntPtr vpC = IntPtr.Zero;
//eyemMatAdd(vpA, vpB, vpC);
//eyemMatFreeMatrix(vpA);
//eyemMatFreeMatrix(vpB);
#endregion
#region Test Binary
//eyemBinThreshold(image, 0, 130, 255, out tpDstImg);
//eyemBinAutoThreshold(ucpImage, 1.8, 1, 6, out tpDstImg);
//eyemSkeleton(ucpImage);
//eyemBinBinaryImage(ucpImage, 0, 3, out tpDtImg);
//eyemBinDynThreshold(image, image, 2.5, 1, out tpDstImg);
//eyemBinNiBlack(image, 0, 5, 0.5, 3, 11, out tpDstImg);
#endregion
#region Test Sauvola
//eyemBinNiBlack(ucpImage, out tpDstImg, 0, 5, 0.001, 3, 5);
#endregion
#region Test Edge
//int iCount; IntPtr hHandle; EyemOcsDXY* hResults;
//eyemEdgesPixel(image, 45, out hHandle, out iCount, out hResults);
#endregion
#region Test RobustFitLine
//EyemOcsDXY taPoint = new EyemOcsDXY();
//List<EyemOcsDXY> taPoints = new List<EyemOcsDXY>();
//EyemOcsDABCD tpPlane = new EyemOcsDABCD();
//IntPtr tpPoint = eyemStructArray2IntPtr(taPoints.ToArray());
////eyemRobustFitPlane(taPoints.Count, tpPoint, 6, 0, ref tpPlane);
//EyemOcsDXYLSQ tpEllipse = new EyemOcsDXYLSQ();
//eyemRobustFitEllipse(taPoints.Count, tpPoint, 6, 0, ref tpEllipse);
//return;
//eyemFitLine(taPoints.Count, tpPoint, 10, ref tpLine);
//eyemRobustFitLine(taPoints.Count, tpPoint, 2, 0, ref tpLine);
//eyemFitLineRANSAC(taPoints.Count, tpPoint, 5, ref tpLine);
//EyemOcsDXYR tpCircle = new EyemOcsDXYR(); double dRMS = 0.0;
//eyemRobustFitCircle(taPoints.Count, tpPoint, 6, 0, ref tpCircle);
//eyemFitCircle(taPoints.Count, tpPoint, 15, ref dRMS, ref tpCircle);
//EyemOcsDABC tpLine2 = new EyemOcsDABC();
//EyemOcsDXY tpPoint1 = new EyemOcsDXY();
//tpPoint1.dX = -2; tpPoint1.dY = 0;
//EyemOcsDXY tpPoint2 = new EyemOcsDXY();
//tpPoint2.dX = 2; tpPoint2.dY = 0;
//eyemClp2dLineTwoPoints(tpPoint1, tpPoint2, ref tpLine2);
//EyemOcsDXY taPointx = new EyemOcsDXY();
//taPointx.dX = -4; taPointx.dY = 4;
//EyemOcsDABC tpVertic = new EyemOcsDABC();
//eyemClp2dLinePointAndSlope(taPointx, 45, ref tpVertic);
//EyemOcsDXY tpPoint1 = new EyemOcsDXY(); EyemOcsDXY tpPoint2 = new EyemOcsDXY(); EyemOcsDXYR tpCircle2 = new EyemOcsDXYR();
//EyemOcsDABC tpTangent1 = new EyemOcsDABC(); EyemOcsDABC tpTangent2 = new EyemOcsDABC();
//tpCircle2.dX = 2; tpCircle2.dY = -5; tpCircle2.dR = 3;
//eyemClp2dTangentPointToCircle(taPointx, tpCircle2, ref tpTangent1, ref tpPoint1, ref tpTangent2, ref tpPoint2);
//eyemClp2dIntersectionLineAndCircle(tpVertic, tpCircle2, ref tpPoint1, ref tpPoint2);
//EyemOcsDABC tpVertic2 = new EyemOcsDABC();
//eyemClp2dLinePointAndSlope(taPointx, 45.0, ref tpVertic2);
//EyemOcsDABC tpVerticC = new EyemOcsDABC();
//eyemClp2dCenterLineOfTwoLines(tpVertic, tpVertic2, ref tpVerticC);
//EyemOcsDXY taPointy = new EyemOcsDXY();
//eyemClp2dIntersectionTwoLines(tpLine, tpVertic2, ref taPointy);
//Marshal.FreeHGlobal(tpPoint);
//return;
#endregion
#region Test WriteImage
//eyemImageWrite("D:\\Matlab测试图像\\xxx.bmp", tpDstImg);
#endregion
#region Test NNDetector
//eyemInitNNDetector(".\\darknet\\detect-tiny-label.cfg", ".\\darknet\\detect-tiny-label.weights");
//int ipNum = 0;
//BboxContainer container = new BboxContainer();
//eyemNNDetector(image, out ipNum, ref container);
#endregion
EyemRect tpRoi = new EyemRect();
tpRoi.iXs = 50; tpRoi.iYs = 50;
tpRoi.iWidth = image.iWidth - 100;
tpRoi.iHeight = image.iHeight - 100;
//flag = eyemAchvMatchMat(image, tpRoi, out tpDstImg);
//EyemOcsDXYR tpCircle = new EyemOcsDXYR();
//EyemRect limRoi = new EyemRect();
//limRoi.iXs = 222; limRoi.iYs = 222;
//limRoi.iWidth = 214;
//limRoi.iHeight = 214;
//flag = eyemDetectCircleUseHough(image, tpRoi, limRoi, out tpCircle, out tpDstImg, 1.0, 80, 100, 50, 28, 43, 3, true);
//////flag = eyemMulFuncTool(image, tpRoi, "__func1__", 65, 75, ref tpCircle, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//return;
//获取用于制作模板的图像
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//return;
////创建模板匹配模型
//EyemRect tpRoi2 = new EyemRect();
//tpRoi2.iXs = 0; tpRoi2.iYs = 0;
//tpRoi2.iWidth = image.iWidth;
//tpRoi2.iHeight = image.iHeight;
//double matchDeg = 0.85;
//flag = eyemCreateTemplateModel(image, tpRoi2, matchDeg, "D:\\模板文件\\" + file.Replace(".png", ".tpl"));
//return;
//加载模板到内存
//IntPtr hModelID = IntPtr.Zero;
//flag = eyemInitModel("D:\\模板文件", out hModelID);
//string selectModel = "";
//flag = eyemMatchTemplateModel(tpDstImg, hModelID, ref selectModel);
////插入模板
//flag = eyemInsertModel(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//string[] tpModels = selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
//if (tpModels.Length <= 0)
//{
// logcpp.WriteLog("选择模板少于0");
// return;
//}
////根据名称获取模板
//EyemModelID tpModelID = new EyemModelID();
//eyemAchvModelByName(tpModels[0], hModelID, ref tpModelID);
//EyemImage tpModeImg = new EyemImage();
//tpModeImg.iChannels = 1; tpModeImg.iDepth = 0;
//tpModeImg.iWidth = tpModelID.iWidth; tpModeImg.iHeight = tpModelID.iHeight; tpModeImg.vpImage = tpModelID.vpImage;
//Bitmap bitmap = eyemCvtToBitmap(tpModeImg);
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//如果对象供其他接口使用要先释放
//eyemImageFree(ref tpDstImg);
//点料参数微调
//setProcessLevel(4.0);
//setFineTuning(0.6);
int[] ipReelNum = new int[4];
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_SQUARE_PARTS","IP_DYNAMIC_PARTS","","IP_DYNAMIC_SP1","IP_DYNAMIC_SP2"
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LARGE_PARTS", ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg);
//算法选项
//std::string sOptions[8] = { "IP_DEFAULT_PARTS","IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_SQUARE_PARTS","","IP_DYNAMIC_SP1","IP_DYNAMIC_SP2" };
//eyemCountObjectIrregularPartsMultiopt(image, tpRoi, new int[] { 0, 0, 0, 0 }, ipReelNum, out tpDstImg);
//eyemCountObjectUseNN(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//移除模板
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
////< 解码测试
//int ipNum; EyemBarCode* tpResults;
//DataCodeHandle hObject;
//int iRes = eyemDetectAndDecode(image, tpRoi, file.Replace(".png", ""), "QR_CODE|DATA_MATRIX", out hObject, out tpResults, out ipNum, false, 11, 5, 128, 256);
//for (int i = 0; i < ipNum; i++)
//{
// Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";角度:" + tpResults[i].dAngle.ToString("F4") + "," + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + "");
// Marshal.FreeCoTaskMem(tpResults[i].hText); Marshal.FreeCoTaskMem(tpResults[i].hType);
//}
//hObject.Dispose();
//flag = eyemDetectAndDecodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
//flag = eyemDetectAndDecodeBarcodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
//return;
string strReelNum = "";
for (int i = 0; i < 4; i++)
{
strReelNum += ipReelNum[i].ToString() + ",";
}
sw.Stop();
Console.WriteLine(file + "--->" + "耗时:" + sw.ElapsedMilliseconds.ToString() + "ms" + ",结果:" + strReelNum);
Bitmap bitmapE = eyemCvtToBitmap(tpDstImg);
if (bitmapE != null)
{
bitmapE.Save("D:\\ResOut\\" + file);
}
////计数失败
//if (flag != 0 || (ipReelNum[0] + ipReelNum[1] + ipReelNum[2] + ipReelNum[3]) == 0)
// File.Copy(fileName, "D:\\ResOut\\" + file, true);
//for (int i = 0; i < ipNum; i++)
//{
// Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";角度:" + tpResults[i].dAngle.ToString("F4") + "," + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + "");
// Marshal.FreeCoTaskMem(tpResults[i].hText); Marshal.FreeCoTaskMem(tpResults[i].hType);
//}
//hObject.Dispose();
//在关闭程序时释放
//eyemReleaseModel(ref hModelID);
//free image
//eyemImageFree(ref tpDstImg);
eyemImageFree(ref image);
}
public static int eyemInitModelE(out IntPtr hModelID)
{
return eyemInitModel("D:\\模板文件", out hModelID);
}
public static int eyemReleaseModelE(ref IntPtr hModelID)
{
return eyemReleaseModel(ref hModelID);
}
public static void eyemTestVideoCapture(string fileName)
{
//List<EyemRect3> tpRois = new List<EyemRect3>();
//EyemRect3 roi1 = new EyemRect3();
//roi1.iXs = 0; roi1.iYs = 400; roi1.iWidth = 100; roi1.iHeight = 100; roi1.dVar = 0.35;
//EyemRect3 roi2 = new EyemRect3();
//roi2.iXs = 101; roi2.iYs = 400; roi2.iWidth = 100; roi2.iHeight = 100; roi2.dVar = 0.35;
//EyemRect3 roi3 = new EyemRect3();
//roi3.iXs = 202; roi3.iYs = 400; roi3.iWidth = 100; roi3.iHeight = 100; roi3.dVar = 0.35;
//EyemRect3 roi4 = new EyemRect3();
//roi4.iXs = 303; roi4.iYs = 400; roi4.iWidth = 100; roi4.iHeight = 100; roi4.dVar = 0.35;
////需要监控的位置信息
//tpRois.Add(roi1); tpRois.Add(roi2); tpRois.Add(roi3); tpRois.Add(roi4);
////结构体转内存指针
//IntPtr hGlobal = eyemStructArray2IntPtr(tpRois.ToArray());
////信号值,用于后续处理
//int[] bitSingle = new int[tpRois.Count];
//EyemImage tpDstImg, tpRefImg, tpNextImg;
//eyemImageRead(fileName + "\\右侧BOX_12 2021-06-22-10-33-06-Original.png", -1, out tpRefImg);
//eyemImageRead(fileName + "\\右侧BOX_12 2021-06-22-08-35-38-Comp.png", -1, out tpNextImg);
////存放结果
//int[] iArrRes = new int[tpRois.Count];
////int iRet = eyemAOIForTSAV(tpImages[0], tpImages[i], hGlobal, tpRois.Count);
//int iRet = eyemTrackFeature(tpRefImg, tpNextImg, hGlobal, tpRois.Count, Marshal.UnsafeAddrOfPinnedArrayElement(iArrRes, 0), out tpDstImg);
//eyemImageFree(ref tpDstImg);
////释放资源
//Marshal.FreeHGlobal(hGlobal);
}
#region EyemImage与Bitmap相互转换
public static Bitmap eyemCvtToBitmap(EyemImage tpImage)
{
if (tpImage.vpImage == IntPtr.Zero || tpImage.iDepth != 0)
return null;
PixelFormat format;
switch (tpImage.iChannels)
{
case 1:
format = PixelFormat.Format8bppIndexed;
break;
case 3:
format = PixelFormat.Format24bppRgb;
break;
case 4:
format = PixelFormat.Format32bppArgb;
break;
default:
return null;
}
Bitmap bitmap = new Bitmap(tpImage.iWidth, tpImage.iHeight, format);
//对于输出灰度图像
if (format == PixelFormat.Format8bppIndexed)
{
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < 256; i++)
{
palette.Entries[i] = Color.FromArgb(i, i, i);
}
bitmap.Palette = palette;
}
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, tpImage.iWidth, tpImage.iHeight),
ImageLockMode.WriteOnly, format);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = (y * tpImage.iWidth * tpImage.iChannels);
long offsetDst = (y * pd);
Buffer.MemoryCopy((byte*)(tpImage.vpImage.ToPointer()) + offsetSrc, (byte*)(bd.Scan0.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return bitmap;
}
public static EyemImage eyemCvtToEyemImage(Bitmap bitmap)
{
EyemImage tpImage = new EyemImage();
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
switch (bitmap.PixelFormat)
{
case PixelFormat.Format8bppIndexed:
tpImage.iChannels = 1;
break;
case PixelFormat.Format24bppRgb:
tpImage.iChannels = 3;
break;
case PixelFormat.Format32bppArgb:
tpImage.iChannels = 4;
break;
default:
throw new Exception("Image formats are not supported");
}
//仅支持8位
tpImage.iDepth = 0;
//图像尺寸
tpImage.iWidth = bitmap.Width; tpImage.iHeight = bitmap.Height;
//分配内存(释放不是用eyemImageFree,用Marshal.FreeHGlobal(tpImage.vpImage)),谁分配谁释放
tpImage.vpImage = Marshal.AllocHGlobal(bd.Stride * bd.Height);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = y * pd;
long offsetDst = y * tpImage.iWidth * tpImage.iChannels;
Buffer.MemoryCopy((byte*)(bd.Scan0.ToPointer()) + offsetSrc, (byte*)(tpImage.vpImage.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return tpImage;
}
public static void eyemCvtToEyemImage(Bitmap bitmap, out EyemImage tpImage)
{
int channels = 0;
switch (bitmap.PixelFormat)
{
case PixelFormat.Format8bppIndexed:
channels = 1;
break;
case PixelFormat.Format24bppRgb:
channels = 3;
break;
case PixelFormat.Format32bppArgb:
channels = 4;
break;
default:
break;
}
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
try
{
eyemImageFromBitmap(bd.Scan0, bd.Width, bd.Height, 0, channels, out tpImage);
}
finally
{
bitmap.UnlockBits(bd);
}
}
public static EyemImage eyemCvtToEyemImage2(Bitmap bitmap)
{
EyemImage tpImage = new EyemImage();
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
switch (bitmap.PixelFormat)
{
case PixelFormat.Format8bppIndexed:
tpImage.iChannels = 1;
break;
case PixelFormat.Format24bppRgb:
tpImage.iChannels = 3;
break;
case PixelFormat.Format32bppArgb:
tpImage.iChannels = 4;
break;
default:
throw new Exception("Image formats are not supported");
}
//仅支持8位
tpImage.iDepth = 0;
//图像尺寸
tpImage.iWidth = bitmap.Width; tpImage.iHeight = bitmap.Height;
//分配内存
tpImage.vpImage = eyemMallocMemBlock(bd.Stride * bd.Height);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = y * pd;
long offsetDst = y * tpImage.iWidth * tpImage.iChannels;
Buffer.MemoryCopy((byte*)(bd.Scan0.ToPointer()) + offsetSrc, (byte*)(tpImage.vpImage.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return tpImage;
}
#endregion
#region 结构体数组与内存指针相互转换
public static IntPtr eyemStructArray2IntPtr<T>(T[] tpArray)
{
if (tpArray == null)
throw new ArgumentNullException(typeof(T).Name.ToString());
//分配结构体需要的内存,需要释放
IntPtr hGlobal = Marshal.AllocHGlobal(checked(Marshal.SizeOf(typeof(T)) * tpArray.Length));
for (int index = 0; index < tpArray.Length; index++)
{
Marshal.StructureToPtr(tpArray[index], (IntPtr)(checked((long)hGlobal + index * Marshal.SizeOf(typeof(T)))), false);
}
return hGlobal;
}
public static List<T> eyemIntPtr2StructArray<T>(IntPtr hGlobal, int Size)
{
if (hGlobal == IntPtr.Zero)
throw new ArgumentNullException(typeof(IntPtr).Name.ToString());
//
List<T> tpArray = new List<T>();
for (int index = 0; index < Size; index++)
{
IntPtr lpArray = new IntPtr(checked(hGlobal.ToInt64() + index * Marshal.SizeOf(typeof(T))));
var structure = Marshal.PtrToStructure<T>(lpArray);
tpArray.Add(structure);
}
return tpArray;
}
#endregion
#region 释放句柄
//释放Blob句柄
public class BlobHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public BlobHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemBinFree(handle);
}
}
//释放测量句柄
public class MeasureHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public MeasureHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemEdge1dGenMeasureFree(handle);
}
}
//释放解码句柄
public class DataCodeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public DataCodeHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemDetectAndDecodeFree(handle);
}
}
//释放视频句柄
public class VideoHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public VideoHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemVideoCaptureFree(handle);
}
}
#endregion
}
}