In this tutorial, I'll show you how to use the Alturos.Yolo to detect an object from the image using C#.NET
As you know, Alturos.Yolo is a state of the art real-time object detection system for C#. This project has support for CPU and GPU. As you know, if you use the GPU for detection it works much faster.
In the background we are use the windows Yolo version. You can open an image from path or the byte array, then using the yolo library to receive the position of the detected objects.
To play the demo, you should create a simple UI that allows you to select a image from file, then show the image to the Picture Box control. Next, you need to convert the image to byte arrays
Adding your code to handle your windows forms application as shown below
using Alturos.Yolo;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
namespace ObjectDetection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "PNG|*.png|JPEG|*.jpeg" })
{
if (ofd.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(ofd.FileName);
}
}
}
private void btnDetect_Click(object sender, EventArgs e)
{
var configurationDetector = new ConfigurationDetector();
var config = configurationDetector.Detect();
using (var yoloWrapper = new YoloWrapper(config))
{
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, ImageFormat.Png);
var items = yoloWrapper.Detect(ms.ToArray());
yoloItemBindingSource.DataSource = items;
//You can draw a rectangle around the object of detection
//items[0].Type -> "Person, Car, ..."
//items[0].Confidence -> 0.0 (low) -> 1.0 (high)
//items[0].X -> bounding box
//items[0].Y -> bounding box
//items[0].Width -> bounding box
//items[0].Height -> bounding box
}
}
}
}
The Alturos.Yolo doesn't support x86 bit, so you need to select your platform project target to x64 bit