-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCuentas.cs
1222 lines (946 loc) · 45.5 KB
/
Cuentas.cs
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
using System;
using System.Drawing;
using System.Net;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Net.Http;
using System.Globalization;
using System.Drawing.Drawing2D;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Emgu.CV;
using Emgu.CV.Structure;
namespace Horus
{
public partial class Cuentas : Form
{
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("gdi32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT {
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public enum TernaryRasterOperations : uint {
SRCCOPY = 0x00CC0020,
SRCPAINT = 0x00EE0086,
SRCAND = 0x008800C6,
SRCINVERT = 0x00660046,
SRCERASE = 0x00440328,
NOTSRCCOPY = 0x00330008,
NOTSRCERASE = 0x001100A6,
MERGECOPY = 0x00C000CA,
MERGEPAINT = 0x00BB0226,
PATCOPY = 0x00F00021,
PATPAINT = 0x00FB0A09,
PATINVERT = 0x005A0049,
DSTINVERT = 0x00550009,
BLACKNESS = 0x00000042,
WHITENESS = 0x00FF0062,
CAPTUREBLT = 0x40000000
}
IntPtr hwnd = IntPtr.Zero;
String ServerAPIURL = "" + Program.Server;
Panel SubPanel;
String uuid;
String user;
String EndPoint = "";
String ServerUser = Program.User;
String ServerPassword = Program.Password;
String Profile = "";
String token = "";
String Recivedtmp = "";
Boolean Ready = true;
Int32 AreaTop = 0;
Int32 AreaLeft = 0;
Int32 AreaHeight = 0;
Int32 AreaWidth = 0;
Int32 ProgramMode = 0;
Image Preview;
Bitmap captureBitmap;
MiniVisor MiniVisor_Window;
String MediaFile = "";
PluginServices PluginsService = new PluginServices();
AvailablePlugin selectedPlugin = new AvailablePlugin();
Image<Bgr, Byte> currentFrame;
Capture grabber;
Int32 SlotsIndex = 0;
struct ProfileVars
{
public Int32 Type;
public String UUDI;
public String Name;
}
struct EstadisticasVars
{
public String Name;
public Double Value;
}
ProfileVars[] Profiler;
EstadisticasVars[] Statistics;
private Int32 GetSlots() {
Int32 Count = 0;
foreach (Boolean Slot in Program.Slots) {
if (Slot == false)
return Count;
Count++;
}
return 0;
}
private void LoadProfiles()
{
try {
WebClient webClient = new WebClient();
webClient.Headers.Add("Authorization", "Bearer " + Program.LogInToken.Trim());
String response = webClient.DownloadString(ServerAPIURL + "/api/v2/admin/accounts/users=" + uuid + "/profiles");
String[] RecivedMatrix = response.Split('|');
if (RecivedMatrix[0] == "200")
{
String[] ProfilesList = response.Split('\n');
Profiler = new ProfileVars[ProfilesList.Length];
this.Perfiles.Items.Clear();
Int32 Counter = 0;
foreach (String Profile in ProfilesList)
{
if (Profile != "")
{
RecivedMatrix = Profile.Split('|');
String code = RecivedMatrix[0];
if (code == "200")
{
Profiler[Counter].Type = System.Convert.ToInt32(RecivedMatrix[4]);
Profiler[Counter].UUDI = RecivedMatrix[1];
Profiler[Counter].Name = RecivedMatrix[2];
this.Perfiles.Items.Add(Profiler[Counter].Name);
Counter++;
}
}
}
}
}
catch (Exception Ex) {
MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK);
}
}
public static Bitmap ResizeImage(Image image, int width, int height) {
var destRect = new Rectangle(0, 0, width, height);
var destImage = new Bitmap(width, height);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage)) {
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrapMode = new ImageAttributes()) {
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}
return destImage;
}
private static ImageCodecInfo GetEncoder(ImageFormat format) {
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs) {
if (codec.FormatID == format.Guid) {
return codec;
}
}
return null;
}
public MemoryStream ImageToStream(Image imageIn) {
MemoryStream ms = new MemoryStream();
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoder(ImageFormat.Jpeg);
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
myEncoderParameter = new EncoderParameter(myEncoder, 80L);
myEncoderParameters.Param[0] = myEncoderParameter;
imageIn.Save(ms, myImageCodecInfo, myEncoderParameters);
return ms;
}
public byte[] ImageToByteArray(Image imageIn) {
return ImageToStream(imageIn).ToArray();
}
public async void GetToken() {
if (token == "") {
Ready = false;
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
HttpResponseMessage response;
form.Add(new StringContent(ServerUser), "user");
form.Add(new StringContent(ServerPassword), "password");
form.Add(new StringContent(Profile), "profileuuid");
response = await httpClient.PostAsync(ServerAPIURL + "/api/v2/functions/login", form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
String[] RecivedMatrix = response.Content.ReadAsStringAsync().Result.Split('|');
if (RecivedMatrix[0] == "200") {
token = RecivedMatrix[1];
}
else {
token = "";
}
Ready = true;
}
}
public Double UnixTimeNow() {
var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return (Double)timeSpan.TotalSeconds;
}
public Cuentas()
{
InitializeComponent();
}
private void LoadUsers()
{
this.MainPanel.Visible = false;
this.WaitAnimation.Visible = true;
try
{
WebClient webClient = new WebClient();
webClient.Headers.Add("Authorization", "Bearer " + Program.LogInToken);
String response = webClient.DownloadString(ServerAPIURL + "/api/v2/admin/accounts/users");
String[] RecivedMatrix = response.Split('|');
if (RecivedMatrix[0] == "200")
{
String[] UserList = response.Split('\n');
foreach (String User in UserList)
{
if (User != "")
{
RecivedMatrix = User.Split('|');
String code = RecivedMatrix[0];
String principal = RecivedMatrix[4];
if (code == "200")
{
if (principal == "True")
{
uuid = RecivedMatrix[1];
user = RecivedMatrix[2];
this.WaitAnimation.Visible = false;
this.MainPanel.Visible = true;
return;
}
}
}
}
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK);
}
this.WaitAnimation.Visible = false;
this.MainPanel.Visible = true;
}
private void Administrator_Resize(object sender, EventArgs e) {
try {
WaitAnimation.Top = (this.Height / 2) - (WaitAnimation.Height / 2);
WaitAnimation.Left = (this.Width / 2) - (WaitAnimation.Width / 2);
this.splitContainer3.Panel1Collapsed = false;
this.splitContainer3.Panel2Collapsed = false;
this.splitContainer3.SplitterDistance = (int)(this.splitContainer3.ClientSize.Width - 400);
}
catch { }
}
private void SubPanel_unload(object sender, FormClosedEventArgs e) {
try {
this.MainPanel.Visible = true;
SubPanel.Visible = false;
SubPanel.Dispose();
SubPanel = null;
LoadUsers();
}
catch { }
}
private void Timer1_Tick(object sender, EventArgs e) {
try {
timer1.Enabled = false;
LoadUsers();
LoadProfiles();
LoadWindows();
Administrator_Resize(sender, e);
}
catch { }
}
private void LoadWindows() {
try
{
this.VentanasAbiertas.Items.Clear();
IntPtr hWnd = IntPtr.Zero;
foreach (Process pList in Process.GetProcesses()) {
String Nombre = pList.MainWindowTitle.Trim();
if (Nombre != "")
this.VentanasAbiertas.Items.Add(Nombre);
}
}
catch { }
}
private void SalirToolStripMenuItem_Click(object sender, EventArgs e) {
if (MessageBox.Show(this, "¿Quiere cerrar el actual stream?", "Atención", MessageBoxButtons.YesNo) == DialogResult.Yes)
this.Close();
}
private void AdministrarPerfilesToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
SubPanel = new Panel();
SubPanel.Dock = DockStyle.Fill;
this.Controls.Add(SubPanel);
SubPanel.Show();
this.MainPanel.Visible = false;
Perfiles AdminitradorWindow = new Perfiles(uuid, user);
AdminitradorWindow.TopLevel = false;
AdminitradorWindow.Dock = DockStyle.Fill;
SubPanel.Controls.Add(AdminitradorWindow);
AdminitradorWindow.Show();
AdminitradorWindow.FormClosed += new FormClosedEventHandler(SubPanel_unload);
}
catch { }
}
private void AdministrarCuentaToolStripMenuItem_Click(object sender, EventArgs e)
{
try {
SubPanel = new Panel();
SubPanel.Dock = DockStyle.Fill;
this.Controls.Add(SubPanel);
SubPanel.Show();
this.MainPanel.Visible = false;
ModifyAccount ModifyAccount_window = new ModifyAccount();
ModifyAccount_window.TopLevel = false;
ModifyAccount_window.Dock = DockStyle.Fill;
SubPanel.Controls.Add(ModifyAccount_window);
ModifyAccount_window.Show();
ModifyAccount_window.FormClosed += new FormClosedEventHandler(SubPanel_unload);
}
catch (Exception Ex) {
MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK);
}
}
private void Stop() {
hwnd = IntPtr.Zero;
if (grabber != null) {
grabber.Dispose();
grabber = null;
}
this.timer2.Enabled = false;
Program.Slots[SlotsIndex] = false;
Program.PreviewMatrix[SlotsIndex] = null;
BotonDeCobtrol.Text = "Iniciar";
this.DefineArea.Enabled = true;
this.Button1.Enabled = true;
this.Button2.Enabled = true;
this.Button3.Enabled = true;
this.Perfiles.Enabled = true;
this.administrarPerfilesToolStripMenuItem.Enabled = true;
this.administrarCuentaToolStripMenuItem.Enabled = true;
this.PanelDeEntradas.Enabled = true;
this.CerrarToolStripMenuItem.Enabled = true;
this.PreviewWindow.Image = null;
this.PreviewWindow.BackColor = Color.Black;
MediaFile = "";
}
private void Start() {
hwnd = IntPtr.Zero;
grabber = null;
this.Log.Rows.Clear();
if (this.Perfiles.Items.Count > 0) {
if (EndPoint.Trim() != "" && Profile.Trim() != "") {
if (ProgramMode == 0) {
if (AreaWidth == 0 && AreaHeight == 0 && AreaTop == 0 && AreaLeft == 0) {
DefineArea_Click(null, null);
}
}
if (ProgramMode == 1) {
if (this.VentanasAbiertas.Text.Trim() == "") {
MessageBox.Show(this, "Debe seleccionar una ventana a capturar antes de proseguir", "Atención", MessageBoxButtons.OK);
return;
}
}
SlotsIndex = GetSlots();
Program.Slots[SlotsIndex] = true;
Statistics = new EstadisticasVars[10000];
this.DefineArea.Enabled = false;
this.Button1.Enabled = false;
this.Button2.Enabled = false;
this.Button3.Enabled = false;
this.Perfiles.Enabled = false;
this.administrarPerfilesToolStripMenuItem.Enabled = false;
this.administrarCuentaToolStripMenuItem.Enabled = false;
this.PanelDeEntradas.Enabled = false;
this.CerrarToolStripMenuItem.Enabled = false;
Ready = true;
token = "";
Recivedtmp = "";
if (ProgramMode == 2)
MediaFile = this.URLVideo.Text.Trim();
if (ProgramMode == 3)
MediaFile = this.MediaText.Text.Trim();
if (ProgramMode == 4)
MediaFile = this.Devices.SelectedIndex.ToString();
BotonDeCobtrol.Text = "Detener";
this.timer2.Enabled = true;
}
else {
MessageBox.Show(this, "Debe seleccionar un perfil de detección", "Atención", MessageBoxButtons.OK);
}
}
else {
MessageBox.Show(this, "No tiene perfiles de deteccion creados. Cree un perfil en base a un modelo de detección antes de continuar.", "Atención", MessageBoxButtons.OK);
}
}
private void BotonDeCobtrol_Click(object sender, EventArgs e) {
if (this.timer2.Enabled == false) {
Start();
}
else
{
Stop();
}
}
private void Timer2_Tick(object sender, EventArgs e)
{
try {
if (grabber != null) {
if (grabber.QueryFrame() != null) {
currentFrame = grabber.QueryFrame().ToImage<Bgr, Byte>();
}
else {
Stop();
MessageBox.Show(this, "Error al conectar con la fuente de video", "Atención", MessageBoxButtons.OK);
return;
}
}
}
catch
{
Start();
Application.DoEvents();
return;
}
if (Ready)
CaptureMyScreen();
}
private async void Upload() {
Bitmap FrameToPlugin = null;
String ToJson = "{\"Data\":[";
String ToPipe = "";
try {
if (Preview != null) {
if (Preview.Width > 1919 || Preview.Height > 1079) {
Preview = ResizeImage(Preview, 1919, 1079);
}
if (ProgramMode == 1) {
AreaWidth = Preview.Width;
AreaHeight = Preview.Height;
}
if (ProgramMode == 2 || ProgramMode == 3 || ProgramMode == 4) {
AreaWidth = Preview.Width;
AreaHeight = Preview.Height;
}
FrameToPlugin = new Bitmap(Preview);
}
using (Graphics g = Graphics.FromImage(Preview)) {
Ready = false;
Recivedtmp = "";
GetToken();
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
HttpResponseMessage response;
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
form.Add(new ByteArrayContent(ImageToByteArray(Preview), 0, ImageToByteArray(Preview).Length), "photo", "image");
response = await httpClient.PostAsync(ServerAPIURL + EndPoint, form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
Recivedtmp = response.Content.ReadAsStringAsync().Result;
if (Recivedtmp.Trim() != "") {
String[] Metadata = Recivedtmp.Split('\n');
String[] ReceiveOnMatrix;
this.Log.Rows.Clear();
foreach (String Metaline in Metadata) {
if (Metaline.Trim() != "") {
if (Profiler[this.Perfiles.SelectedIndex].Type == 0 || Profiler[this.Perfiles.SelectedIndex].Type == 1 || Profiler[this.Perfiles.SelectedIndex].Type == 4 || Profiler[this.Perfiles.SelectedIndex].Type == 5) {
String[] Values = Metaline.Split('|');
WebClient webClient = new WebClient();
webClient.Headers.Add("Authorization", "Bearer " + token);
String response1 = webClient.DownloadString(ServerAPIURL + "/api/v2/admin/accounts/users/profiles/detections=" + Values[6] + "/name");
String[] RecivedMatrix1 = response1.Split('|');
if (RecivedMatrix1[0] == "200")
Recivedtmp = Metaline.Replace(Values[6], RecivedMatrix1[1]);
ReceiveOnMatrix = Recivedtmp.Split('|');
}
else {
ReceiveOnMatrix = Metaline.Split('|');
}
Int32 left = 0;
Int32 right = 0;
Int32 top = 0;
Int32 bottom = 0;
String Name = "";
Double Confidence = 0;
Double ymin = 0;
Double xmin = 0;
Double ymax = 0;
Double xmax = 0;
if (ReceiveOnMatrix[0] == "200") {
String DecimalSimbol = CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
if (DecimalSimbol == ",") {
ymin = Convert.ToDouble(ReceiveOnMatrix[2].Replace(".", ","));
xmin = Convert.ToDouble(ReceiveOnMatrix[3].Replace(".", ","));
ymax = Convert.ToDouble(ReceiveOnMatrix[4].Replace(".", ","));
xmax = Convert.ToDouble(ReceiveOnMatrix[5].Replace(".", ","));
Confidence = Convert.ToDouble(ReceiveOnMatrix[8].Replace(".", ","));
}
else {
ymin = Convert.ToDouble(ReceiveOnMatrix[2]);
xmin = Convert.ToDouble(ReceiveOnMatrix[3]);
ymax = Convert.ToDouble(ReceiveOnMatrix[4]);
xmax = Convert.ToDouble(ReceiveOnMatrix[5]);
Confidence = Convert.ToDouble(ReceiveOnMatrix[8]);
}
if (ymin > 100 || xmin > 100 || ymax > 100 || xmax > 100)
{
ymin = Convert.ToDouble(ReceiveOnMatrix[2].Replace(".", ","));
xmin = Convert.ToDouble(ReceiveOnMatrix[3].Replace(".", ","));
ymax = Convert.ToDouble(ReceiveOnMatrix[4].Replace(".", ","));
xmax = Convert.ToDouble(ReceiveOnMatrix[5].Replace(".", ","));
Confidence = Convert.ToDouble(ReceiveOnMatrix[8].Replace(".", ","));
}
if (ymin > 100 || xmin > 100 || ymax > 100 || xmax > 100) {
ymin = Convert.ToDouble(ReceiveOnMatrix[2].Replace(",", "."));
xmin = Convert.ToDouble(ReceiveOnMatrix[3].Replace(",", "."));
ymax = Convert.ToDouble(ReceiveOnMatrix[4].Replace(",", "."));
xmax = Convert.ToDouble(ReceiveOnMatrix[5].Replace(",", "."));
Confidence = Convert.ToDouble(ReceiveOnMatrix[8].Replace(",", "."));
}
left = Convert.ToInt32(xmin * AreaWidth);
right = Convert.ToInt32(xmax * AreaWidth);
top = Convert.ToInt32(ymin * AreaHeight);
bottom = Convert.ToInt32(ymax * AreaHeight);
Name = ReceiveOnMatrix[6];
Int32 Count = 0;
foreach (String Value in ReceiveOnMatrix) {
if (Count == 0)
ToJson = ToJson + "{\"code\":" + Value + ",";
if (Count == 1)
ToJson = ToJson + "\"value\":\"" + Value + "\",";
if (Count == 2)
ToJson = ToJson + "\"y1\":" + Value + ",";
if (Count == 3)
ToJson = ToJson + "\"x1\":" + Value + ",";
if (Count == 4)
ToJson = ToJson + "\"y2\":" + Value + ",";
if (Count == 5)
ToJson = ToJson + "\"x2\":" + Value + ",";
if (Count == 6)
ToJson = ToJson + "\"detected_id\":\"" + Value + "\",";
if (Count == 7)
ToJson = ToJson + "\"vector_id\":\"" + Value + "\",";
if (Count == 8)
ToJson = ToJson + "\"confidence\":" + Value + "},";
Count++;
ToPipe = ToPipe + Value + "|";
}
ToPipe = ToPipe + "\n";
}
if (Name != "-1" && Name != "FAIL")
{
AddToGraph(Name, 1);
g.FillRectangle(new System.Drawing.SolidBrush(Color.FromArgb(200, 255, 0, 0)), left - 2, top - 20, (new Font("Tahoma", 10).SizeInPoints * Name.Length), new Font("Tahoma", 10).Height);
g.DrawString(Name, new Font("Tahoma", 10), new System.Drawing.SolidBrush(Color.FromArgb(255, 255, 255, 255)), new PointF(left, top - 20));
Pen greenPen = new Pen(Color.FromArgb(200, 255, 0, 0), 2);
greenPen.Alignment = PenAlignment.Center;
Rectangle rect = new Rectangle(left, top, right - left, bottom - top);
g.DrawRectangle(greenPen, rect);
String X = System.Convert.ToString(System.Convert.ToInt32((xmin + ((xmax - xmin) / 2)) * 640));
String Y = System.Convert.ToString(System.Convert.ToInt32((ymin + ((ymax - ymin) / 2)) * 480));
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.Log);
row.Cells[0].Value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt");
row.Cells[1].Value = Name;
row.Cells[2].Value = X;
row.Cells[3].Value = Y;
row.Cells[4].Value = Math.Round(Confidence * 100, 1).ToString() + "%";
this.Log.Rows.Add(row);
this.Log.FirstDisplayedScrollingRowIndex = this.Log.RowCount - 1;
}
}
}
}
}
if (pIPEToolStripMenuItem.Checked) {
Clipboard.SetText(ToPipe);
}
if (jSONToolStripMenuItem.Checked) {
Clipboard.SetText(ToJson);
}
try {
if (selectedPlugin != null) {
selectedPlugin.Instance.Input = ToJson + "{\"code\":-1}]}";
if (FrameToPlugin != null)
selectedPlugin.Instance.Frame = ImageToStream(FrameToPlugin);
}
}
catch { }
Ready = true;
}
catch {
Ready = true;
}
Graficar();
this.PreviewWindow.Image = Preview;
this.PreviewWindow.Invalidate();
try {
if (Program.MiniVisor_visible == true) {
Program.PreviewMatrix[SlotsIndex] = this.PreviewWindow.Image;
}
else {
if (Program.IsHide == true) {
Program.IsHide = false;
this.miniVisorToolStripMenuItem.Checked = false;
}
}
}
catch { }
}
private void CaptureMyScreen()
{
try {
captureBitmap = null;
if (ProgramMode == 0) {
Rectangle captureRectangle = Screen.AllScreens[0].Bounds;
captureBitmap = new Bitmap(AreaWidth, AreaHeight, PixelFormat.Format32bppArgb);
Graphics captureGraphics = Graphics.FromImage(captureBitmap);
captureGraphics.CopyFromScreen(AreaLeft, AreaTop, captureRectangle.Left, captureRectangle.Top, captureRectangle.Size);
}
if (ProgramMode == 1) {
if (hwnd == IntPtr.Zero) {
foreach (Process pList in Process.GetProcesses()) {
if (pList.MainWindowTitle.Contains(this.VentanasAbiertas.Text.Trim())) {
hwnd = pList.MainWindowHandle;
break;
}
}
}
int width = 0, height = 0;
IntPtr dc = IntPtr.Zero;
dc = GetDC(hwnd);
RECT rect;
if (GetWindowRect(hwnd, out rect)) {
width = rect.Right - rect.Left;
height = rect.Bottom - rect.Top;
}
captureBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
AreaWidth = width;
AreaHeight = height;
if (dc != IntPtr.Zero) {
try {
using (Graphics g = Graphics.FromImage(captureBitmap)) {
IntPtr bdc = g.GetHdc();
try {
BitBlt(bdc, 0, 0, width, height, dc, 0, 0, TernaryRasterOperations.SRCCOPY);
}
catch {
Stop();
}
finally {
g.ReleaseHdc(bdc);
}
}
}
catch {
Stop();
}
finally {
ReleaseDC(hwnd, dc);
}
}
else
{
Stop();
}
}
if (ProgramMode == 2 || ProgramMode == 3 || ProgramMode == 4) {
try {
if (MediaFile != "" && MediaFile != "-1") {
if (grabber == null)
if (ProgramMode == 4)
grabber = new Capture(System.Convert.ToInt32(MediaFile));
else
grabber = new Capture(MediaFile);
if (currentFrame != null) {
captureBitmap = currentFrame.ToBitmap();
}
}
else {
Stop();
if (ProgramMode == 2)
MessageBox.Show(this, "Debe escribir la URL de donde obtener el stream de video para continuar.", "Atención", MessageBoxButtons.OK);
if (ProgramMode == 3)
MessageBox.Show(this, "Debe seleccionar un archivo de video para continuar.", "Atención", MessageBoxButtons.OK);
if (ProgramMode == 4)
MessageBox.Show(this, "Debe seleccionar un dispositivo de entrada de video para continuar.", "Atención", MessageBoxButtons.OK);
}
}
catch (Exception ex) {
Stop();
MessageBox.Show(ex.Message);
}
}
if (captureBitmap != null)
Preview = captureBitmap;
Upload();
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void DefineArea_Click(object sender, EventArgs e)
{
Program.IsHide = true;
AreaSelector areaSelector_Window = new AreaSelector();
if (AreaTop > 0 || AreaLeft > 0 || AreaHeight > 0 || AreaWidth > 0)
{
areaSelector_Window.Top = AreaTop;
areaSelector_Window.Left = AreaLeft;
areaSelector_Window.Width = AreaWidth;
areaSelector_Window.Height = AreaHeight;
}
areaSelector_Window.ShowDialog();
AreaTop = areaSelector_Window.Top;
AreaLeft = areaSelector_Window.Left;
AreaHeight = areaSelector_Window.Height;
AreaWidth = areaSelector_Window.Width;
Program.IsHide = false;
areaSelector_Window.Close();
}
private void Perfiles_SelectedIndexChanged(object sender, EventArgs e)
{
Profile = Profiler[this.Perfiles.SelectedIndex].UUDI;
if (Profiler[this.Perfiles.SelectedIndex].Type == 0) // FACEID
EndPoint = "/api/v2/functions/face/id";
if (Profiler[this.Perfiles.SelectedIndex].Type == 1) // OBJECT
EndPoint = "/api/v2/functions/object/detection";
if (Profiler[this.Perfiles.SelectedIndex].Type == 2) // QR
EndPoint = "/api/v2/functions/codebar/decoder";
if (Profiler[this.Perfiles.SelectedIndex].Type == 3) // APLR
EndPoint = "//api/v2/functions/lpr/id";
if (Profiler[this.Perfiles.SelectedIndex].Type == 4) // IMAGE ID
EndPoint = "/api/v2/functions/image/id";
if (Profiler[this.Perfiles.SelectedIndex].Type == 5) // NUDE
EndPoint = "/api/v2/functions/classification/nude";
if (Profiler[this.Perfiles.SelectedIndex].Type == 6) // OCR
EndPoint = "/api/v2/functions/ocr/decoder";
}
private void Timer3_Tick(object sender, EventArgs e) {
if (Program.NeedChange == true)
{
Program.NeedChange = false;
LoadProfiles();
Profile = "";
this.Perfiles.Text = "";
}
}
private void MiniVisorToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.timer2.Enabled && Program.MiniVisor_visible == false) {
MiniVisor_Window = new MiniVisor();
MiniVisor_Window.Show();
Program.MiniVisor_visible = true;
}
}