Guest User

Untitled

a guest
Jan 1st, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Timers;
  13. using System.Windows.Forms;
  14. using Alturos.Yolo;
  15.  
  16.  
  17. namespace ProiectStrajaSkiCount
  18. {
  19. public partial class Form1 : Form
  20. {
  21. public Form1()
  22. {
  23. InitializeComponent();
  24. // InitializeChromium();
  25. }
  26.  
  27.  
  28. public void InitializeChromium()
  29. {
  30. /* CefSettings settings = new CefSettings();
  31. // Initialize cef with the provided settings
  32. Cef.Initialize(settings);
  33. // Create a browser component
  34. chromiumWebBrowser1.Load("http://82.79.247.31:888/cgi-bin/faststream.jpg?stream=full&fps=12");
  35. */
  36. }
  37.  
  38. private void pictureBox1_Click(object sender, EventArgs e)
  39. {
  40.  
  41. }
  42. static YoloWrapper warpper = null;
  43. private async void Form1_LoadAsync(object sender, EventArgs e)
  44. {
  45.  
  46.  
  47.  
  48. var configurationDetector = new ConfigurationDetector();
  49. var config = configurationDetector.Detect();
  50. warpper = new YoloWrapper(config);
  51. new Thread(() =>
  52. {
  53. Thread.CurrentThread.IsBackground = true;
  54. System.Timers.Timer aTimer = new System.Timers.Timer();
  55. aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
  56. aTimer.Interval = 1000 / 50;
  57. aTimer.Enabled = true;
  58. }).Start();
  59. pictureBox1.Paint += new PaintEventHandler(this.pictureBox1_Paint);
  60.  
  61. }
  62. static List<Alturos.Yolo.Model.YoloItem> persons = new List<Alturos.Yolo.Model.YoloItem>();
  63. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  64. {
  65. Pen blackPen = new Pen(Color.Black, 3);
  66.  
  67. using (WebClient client = new WebClient())
  68. {
  69.  
  70.  
  71. byte[] data = client.DownloadData(new Uri($"http://82.79.247.31:4000/record/current.jpg?rand={DateTime.Now.GetHashCode()}"));
  72.  
  73. pictureBox1.Image = (Bitmap)((new ImageConverter()).ConvertFrom(data));
  74.  
  75. var itm = warpper.Detect(data).ToList();
  76.  
  77. foreach (var item in itm)
  78. {
  79. if (item.Type == "person" && item.Confidence > 0.500)
  80. {
  81.  
  82.  
  83. e.Graphics.DrawRectangle(blackPen, item.X, item.Y, item.Width, item.Height);
  84. // g.DrawString(item.Confidence.ToString(), DefaultFont, new SolidBrush(Color.Red), new PointF(item.X, item.Y));
  85.  
  86.  
  87. }
  88. }
  89.  
  90. }
  91. }
  92. private void OnTimedEvent(object source, ElapsedEventArgs e)
  93. {
  94.  
  95.  
  96. }
  97.  
  98.  
  99.  
  100.  
  101. private async void button1_ClickAsync(object sender, EventArgs e)
  102. {
  103. Pen blackPen = new Pen(Color.PowderBlue, 1);
  104.  
  105. var items = warpper.Detect(Utils.ImageToByte(pictureBox1.Image)).ToList();
  106.  
  107. foreach (var item in items)
  108. {
  109. Console.WriteLine($"{item.Type}");
  110.  
  111.  
  112. using (Graphics g = pictureBox1.CreateGraphics())
  113. {
  114. g.DrawRectangle(blackPen, item.X, item.Y, item.Width, item.Height);
  115. g.DrawString(item.Type, DefaultFont, new SolidBrush(Color.Red), new PointF(item.X, item.Y));
  116. }
  117.  
  118. }
  119. }
  120. }
  121. }
  122.  
  123. //
Advertisement
Add Comment
Please, Sign In to add comment