Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows.Forms;
- using Alturos.Yolo;
- namespace ProiectStrajaSkiCount
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- // InitializeChromium();
- }
- public void InitializeChromium()
- {
- /* CefSettings settings = new CefSettings();
- // Initialize cef with the provided settings
- Cef.Initialize(settings);
- // Create a browser component
- chromiumWebBrowser1.Load("http://82.79.247.31:888/cgi-bin/faststream.jpg?stream=full&fps=12");
- */
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- static YoloWrapper warpper = null;
- private async void Form1_LoadAsync(object sender, EventArgs e)
- {
- var configurationDetector = new ConfigurationDetector();
- var config = configurationDetector.Detect();
- warpper = new YoloWrapper(config);
- new Thread(() =>
- {
- Thread.CurrentThread.IsBackground = true;
- System.Timers.Timer aTimer = new System.Timers.Timer();
- aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
- aTimer.Interval = 1000 / 50;
- aTimer.Enabled = true;
- }).Start();
- pictureBox1.Paint += new PaintEventHandler(this.pictureBox1_Paint);
- }
- static List<Alturos.Yolo.Model.YoloItem> persons = new List<Alturos.Yolo.Model.YoloItem>();
- private void pictureBox1_Paint(object sender, PaintEventArgs e)
- {
- Pen blackPen = new Pen(Color.Black, 3);
- using (WebClient client = new WebClient())
- {
- byte[] data = client.DownloadData(new Uri($"http://82.79.247.31:4000/record/current.jpg?rand={DateTime.Now.GetHashCode()}"));
- pictureBox1.Image = (Bitmap)((new ImageConverter()).ConvertFrom(data));
- var itm = warpper.Detect(data).ToList();
- foreach (var item in itm)
- {
- if (item.Type == "person" && item.Confidence > 0.500)
- {
- e.Graphics.DrawRectangle(blackPen, item.X, item.Y, item.Width, item.Height);
- // g.DrawString(item.Confidence.ToString(), DefaultFont, new SolidBrush(Color.Red), new PointF(item.X, item.Y));
- }
- }
- }
- }
- private void OnTimedEvent(object source, ElapsedEventArgs e)
- {
- }
- private async void button1_ClickAsync(object sender, EventArgs e)
- {
- Pen blackPen = new Pen(Color.PowderBlue, 1);
- var items = warpper.Detect(Utils.ImageToByte(pictureBox1.Image)).ToList();
- foreach (var item in items)
- {
- Console.WriteLine($"{item.Type}");
- using (Graphics g = pictureBox1.CreateGraphics())
- {
- g.DrawRectangle(blackPen, item.X, item.Y, item.Width, item.Height);
- g.DrawString(item.Type, DefaultFont, new SolidBrush(Color.Red), new PointF(item.X, item.Y));
- }
- }
- }
- }
- }
- //
Advertisement
Add Comment
Please, Sign In to add comment