private void narsalarniAniqlashToolStripMenuItem_Click(object sender, EventArgs e) { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { var items = yoloWrapper.Detect(ImageToByte(pictureBox1.Image)); if (items.Count() > 0) { foreach (YoloItem item in items) { Bitmap bmp = new Bitmap(pictureBox1.Image); Rectangle rectangle = new Rectangle(item.X, item.Y, item.Width, item.Height); ImgInput = new Image <Bgr, byte>(bmp); ImgInput.Draw(rectangle, new Bgr(0, 0, 255), 2); ImgInput.Draw($"{item.Type} ({string.Format("{0:0.0}", item.Confidence)})", new Point(item.X - 2, item.Y - 2), Emgu.CV.CvEnum.FontFace.HersheyDuplex, 0.5, new Bgr(Color.DarkBlue)); pictureBox1.Image = ImgInput.Bitmap; } } } }
public YoloServiceImpl() { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); yoloWrapper = new YoloWrapper(config); }
static void TestTracking() { Directory.CreateDirectory("trackingImages"); var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { var yoloTracking = new YoloTracking(yoloWrapper, 200); yoloTracking.SetTrackingObject(new Point(216, 343)); var files = Directory.GetFiles(@"test"); //yoloTracking.SetTrackingObject(new Point(385, 480)); //var files = Directory.GetFiles(@"test3"); foreach (var file in files) { var imageData = File.ReadAllBytes(file); var trackingItem = yoloTracking.Analyse(imageData); if (trackingItem == null) { continue; } var fileInfo = new FileInfo(file); File.WriteAllBytes($@"trackingImages\{trackingItem.Index}.bmp", trackingItem.TaggedImageData); } } Console.ReadLine(); }
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()); foreach (var item in items) { var x = item.X; var y = item.Y; var width = item.Width; var height = item.Height; var type = item.Type; Pen pen = new Pen(Color.Red); Graphics g = pictureBox1.CreateGraphics(); g.DrawRectangle(pen, x, y, width, height); } dataGridView1.DataSource = items; } }
//without validation i.e., output all yolo detections public FrameDNNDarknet(string modelConfig, DNNMode dnnMode) { var configurationDetector = new ConfigurationDetector(modelConfig); frameYolo = new YoloWrapper(configurationDetector.Detect(), dnnMode); frameYoloTracking = new YoloTracking(frameYolo); }
//distance-based validation public FrameDNNDarknet(string modelConfig, DNNMode dnnMode, double rFactor) { var configurationDetector = new ConfigurationDetector(modelConfig); frameYolo = new YoloWrapper(configurationDetector.Detect(), dnnMode); frameYoloTracking = new YoloTracking(frameYolo, Convert.ToInt32(DNNConfig.ValidRange * rFactor)); }
private void Grabar(object sender, NewFrameEventArgs frame) { Bitmap video = (Bitmap)frame.Frame.Clone(); Bitmap temp = new Bitmap(video.Width, video.Height); Graphics g = Graphics.FromImage(temp); int left = video.Width / 4; int top = video.Height / 4; int width = video.Width / 2; int height = video.Height / 2; Rectangle srcRect = new Rectangle(left, top, width, height); Rectangle dstRect = new Rectangle(0, 0, temp.Width, temp.Height); g.DrawImage(video, dstRect, srcRect, GraphicsUnit.Pixel); //========================================= Prueba IA ================================================= picture.Image = video; var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); var yolo = new YoloWrapper(config); var memoryStream = new MemoryStream(); video.Save(memoryStream, ImageFormat.Png); var items = yolo.Detect(memoryStream.ToArray()).ToList(); AddDetailsToPictureBox(picture, items, frame); //========================================= Prueba IA ================================================= //picture.Image = temp; //pictureBox1.Image = this.Tracker(frame, color1, "celeste"); //pictureBox2.Image = this.Tracker(frame, color2, "verde"); //pictureBox3.Image = this.Tracker(frame, color3, "rojo"); }
public YoloObjectDetection() { var configurationDetector = new ConfigurationDetector(); var configuration = configurationDetector.Detect(); this._yoloWrapper = new YoloWrapper(configuration); }
private YoloConfiguration GetConfiguration() { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(Constants.ResourceFolder); return(config); }
private string Detection(byte[] imagebyte) { UIUpdate("In detect"); var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); YoloWrapper yoloWrapper = new YoloWrapper(config); // 使用YoloWrapper物件(Alturos裡的主要辨識程式) IEnumerable <YoloItem> items = yoloWrapper.Detect(imagebyte); // 呼叫偵測函式,結果儲存於items裡 string message = string.Empty; foreach (YoloItem item in items) { //if (item.Type == "TroopsHeadquarters") //{ // message += "1,"; //} //else message += item.Type + ','; message += (item.Type == "TroopsHeadquarters" ? "1" : item.Type) + ',' + item.X + ',' + item.Y + ',' + item.Width + ',' + item.Height + ',' + item.Confidence + ';'; // 將目標的種類、座標及信賴值存成字串,以方便傳輸 } return(message); }
//overlap ratio-based validation public FrameDNNDarknet(string modelConfig, DNNMode dnnMode, List <Tuple <string, int[]> > lines) { var configurationDetector = new ConfigurationDetector(modelConfig); frameYolo = new YoloWrapper(configurationDetector.Detect(), dnnMode); frameYoloTracking = new YoloTracking(frameYolo); _lines = lines; }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); YoloWrapper yoloWrapper = new YoloWrapper(config); // OpenCV & WPF setting image = new Mat(); //WriteableBitmap wb = new WriteableBitmap(yoloWidth, yoloHeight, 96, 96, PixelFormats.Bgr24, null); var bgWorker = (BackgroundWorker)sender; byte[] imageInBytes = new byte[(int)(yoloWidth * yoloHeight * image.Channels())]; videocapture = new VideoCapture(textBox1.Text); while (!bgWorker.CancellationPending) { using (Mat imageOriginal = new Mat()) { // read a single frame and convert the frame into a byte array videocapture.Read(imageOriginal); if (imageOriginal.Empty()) { break; } image = imageOriginal.Resize(new OpenCvSharp.Size(yoloWidth, yoloHeight)); imageInBytes = image.ToBytes(); // conduct object detection and display the result var items = yoloWrapper.Detect(imageInBytes); foreach (var item in items) { var x = item.X; var y = item.Y; var width = item.Width; var height = item.Height; var type = item.Type; // class name of the object // draw a bounding box for the detected object // you can set different colors for different classes Cv2.Rectangle(image, new OpenCvSharp.Rect(x, y, width, height), Scalar.Green, 3); Cv2.PutText(image, type, new OpenCvSharp.Point(x - 10, y), HersheyFonts.HersheyComplex, 0.5, Scalar.Red); } bgWorker.ReportProgress(0, image); //// display the detection result //WriteableBitmapConverter.ToWriteableBitmap(image, wb); ///* WPF component: videoViewer //<Canvas Name="canvasYoloVideo" Height="608" Width="608"> // <Image Name="videoViewer" Height="608" Width="608" Stretch="Fill" /> //</Canvas> //*/ //videoViewer.Source = wb; } } // Read a video file and run object detection over it! }
static void TestLogic2() { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { var result = yoloWrapper.Detect(@"image.jpg"); } }
private void btnDetect_Click(object sender, EventArgs e) { if (picSample.Image != null) { var configuration = detector.Detect(); var yol = new YoloWrapper(configuration); picSample.Image.Save(stream, ImageFormat.Jpeg); var extractedItems = yol.Detect(stream.ToArray()).ToList(); } }
private void Button_Click(object sender, RoutedEventArgs e) { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { var items = yoloWrapper.Detect("image.png"); } }
private static void Initialize(string path) { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(path + "\\yoloData\\"); if (config == null) { return; } Initialize(config); }
private void btnDetect_Click(object sender, EventArgs e) { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); YoloWrapper yolo = new YoloWrapper(config); var memoryStream = new MemoryStream(); picImage.Image.Save(memoryStream, ImageFormat.Png); var _items = yolo.Detect(memoryStream.ToArray()).ToList(); AddDetailsToPictureBox(picImage, _items); }
private void Detect() { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); var yolo = new YoloWrapper(config); var memoryStream = new MemoryStream(); pictureBox1.Image.Save(memoryStream, ImageFormat.Png); var _items = yolo.Detect(memoryStream.ToArray()).ToList(); AddDetailsToPictureBox(pictureBox1, _items); }
private void button2_Click(object sender, EventArgs e) { var con = new ConfigurationDetector(); var config = con.Detect(); var dectect = new YoloWrapper(config); //if you want custom detection/trainm it your self do var yoloCustomWrapper = new YoloWrapper("<<path to .cfg file>>", "<<path to .weights file>>", "<<path to .names file>>"); var mS = new MemoryStream(); pictureBox1.Image.Save(mS, ImageFormat.Png); var item = dectect.Detect(mS.ToArray()).ToList(); AddRect(pictureBox1, item); }
static void Main(string[] args) { Image myImage = Image.FromFile(args[0]); Image yoloImage = myImage; var detectorConf = new ConfigurationDetector(); var conf = detectorConf.Detect(); var yolo = new YoloWrapper(conf); var memStream = new System.IO.MemoryStream(); yoloImage.Save(memStream, ImageFormat.Png); var _items = yolo.Detect(memStream.ToArray()).ToList(); SaveYoloImage(yoloImage, _items); }
private void ExObjectDetect() { this.MediaService.Capture(); var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { var items = yoloWrapper.Detect(@"C:\Users\csy18\OneDrive\바탕 화면\RomanticLabel\RomanticLabel\cap.png"); foreach (var item in items) { var rect = new Rect(item.X, item.Y, item.Width, item.Height); BoundingBoxes.Add(new BoundingBox(rect, item.Type)); } } }
private void SetupYolo(List <YoloEntry> configs, YoloEntry.YoloSelection selection) { if (yoloWrapper != null) { yoloWrapper.Dispose(); yoloWrapper = null; } var config = configs.Find(x => x.Selection == selection).Conf; if (config.IsValid) { configurationDetector = new ConfigurationDetector(config); config = configurationDetector.Detect(); yoloWrapper = new YoloWrapper(config); } else { throw new InvalidDataException("Configuration files missing!"); } }
static void Main(string[] args) { //The download takes some time depending on the internet connection. //var repository = new YoloPreTrainedDatasetRepository(); //var task= repository.DownloadDatasetAsync("YOLOv3", "."); //task.Wait(); var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { var items = yoloWrapper.Detect(@"IMG_2072.JPG"); //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 } Console.ReadKey(); }
private void BtnDetect_Click(object sender, EventArgs e) { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { using (MemoryStream ms = new MemoryStream()) { picBox.Image.Save(ms, ImageFormat.Png); var items = yoloWrapper.Detect(ms.ToArray()); result.DataSource = items; } //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 } }
public Classifier() { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; //initialize components List <SizeInfo> sizeList = new List <SizeInfo>(); sizeList.Add(new SizeInfo { Name = "Large", Value = "L" }); sizeList.Add(new SizeInfo { Name = "Medium", Value = "M" }); sizeList.Add(new SizeInfo { Name = "Small", Value = "S" }); carSizeList.ItemsSource = sizeList; carSizeList.DisplayMemberPath = "Name"; carSizeList.SelectedValuePath = "Value"; carSizeList.SelectedIndex = 0; //initialize classifier try { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); wrapper = new YoloWrapper(config); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); Close(); } }
private void btnDetect_Click_1(object sender, EventArgs e) { //Проверка типа файла для распознавания if (cart == true) //Для изображений { var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { using (MemoryStream ms = new MemoryStream()) { //Конвертация цветного изображения в черно-белое var picWB = pic.Image; picWB.Save(@"temp.jpg"); Mat src = new Mat(@"temp.jpg", ImreadModes.Grayscale); ImageConverter converter = new ImageConverter(); byte[] WbTemp = (byte[])converter.ConvertTo(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src), typeof(byte[])); using (FileStream fstream = new FileStream(@"tempWB.jpg", FileMode.Create)) { fstream.Write(WbTemp, 0, WbTemp.Length); } //Без использования using файл tempWB.jpg занят процессом и не может быть удален using (var WB = Image.FromFile(@"tempWB.jpg")) { WB.Save(ms, ImageFormat.Png); var items = yoloWrapper.Detect(ms.ToArray()); yoloItemBindingSource.DataSource = items; foreach (var item in items) { //Запись в лог using (StreamWriter w = File.AppendText("log.txt")) { } void Log(string logMessage, TextWriter w) { w.Write("\r\nLog Entry : "); w.WriteLine($"{DateTime.Now.ToLongTimeString()} {DateTime.Now.ToLongDateString()}"); w.WriteLine(" :"); w.WriteLine($" :{logMessage}"); w.WriteLine("-------------------------------"); } //Определение параметров для отображения сцепки и рисование рамки x = (float)item.X; y = (float)item.Y; width = (float)item.Width; height = (float)item.Height; if ((double)item.Confidence > 0.85) { if (item.Type == "coup1") { Graphics graph = Graphics.FromImage(pic.Image); Pen pen = new Pen(Color.Blue, 3f); graph.DrawRectangle(pen, x, y, width, height); pic.Image = pic.Image; using (StreamWriter w = File.AppendText("log.txt")) { Log($"Обнаружена полусцепка: {NameF} | X: {x} | Y: {y} | width: {width} | height: {height} | Confidence: {item.Confidence}", w); } } if (item.Type == "coup2") { Graphics graph = Graphics.FromImage(pic.Image); Pen pen = new Pen(Color.Red, 3f); graph.DrawRectangle(pen, x, y, width, height); pic.Image = pic.Image; using (StreamWriter w = File.AppendText("log.txt")) { Log($"Обнаружена сцепка: {NameF} | X: {x} | Y: {y} | width: {width} | height: {height} | Confidence: {item.Confidence}", w); } /*CoupJSON image = new CoupJSON(); * image.ImageName = ($"{NameF}"); * CoupJSON TL = new CoupJSON(); * TL.TopLeft = new List<int> { $"{ x }", $"{ y }" }; */ } Directory.CreateDirectory(@"JSON"); var CoupJSON = GetCoupJSON(); var jsonToWrite = JsonConvert.SerializeObject(CoupJSON, Formatting.Indented); using (var writer = new StreamWriter(@"JSON/" + NameF + ".json")) { writer.Write(jsonToWrite); } } } } } } } else //Для видео { var capture = new VideoCapture(PathF); int sleepTime = (int)Math.Round(1000 / capture.Fps); int count = 0; Mat image = new Mat(); while (true) { count++; capture.Read(image); if (image.Empty()) { break; } capture.Read(image); if (bStop == true) //Действие на кнопку Стоп { bStop = false; break; } //Сохранение временных файлов, начиная с 1 кадра using (FileStream fstream = new FileStream(@"temp/temp" + count + ".jpg", FileMode.Create)) { ImageConverter converter = new ImageConverter(); byte[] bTemp = (byte[])converter.ConvertTo(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(image), typeof(byte[])); fstream.Write(bTemp, 0, bTemp.Length); } pic.Image = Image.FromFile(@"temp/temp" + count + ".jpg"); //Передача кадра в pictureBox var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); using (var yoloWrapper = new YoloWrapper(config)) { using (MemoryStream ms = new MemoryStream()) { pic.Image.Save(ms, ImageFormat.Png); //Загрузка кадра из pictureBox в Yolo var items = yoloWrapper.Detect(ms.ToArray()); yoloItemBindingSource.DataSource = items; foreach (var item in items) { var x = (float)item.X; var y = (float)item.Y; var width = (float)item.Width; var height = (float)item.Height; if ((double)item.Confidence > 0.85) { if (item.Type == "coup1") { Graphics graph = Graphics.FromImage(pic.Image); Pen pen = new Pen(Color.Blue, 3f); graph.DrawRectangle(pen, x, y, width, height); pic.Image = pic.Image; } if (item.Type == "coup2") { Graphics graph = Graphics.FromImage(pic.Image); Pen pen = new Pen(Color.Red, 3f); graph.DrawRectangle(pen, x, y, width, height); pic.Image = pic.Image; } } } } } Cv2.WaitKey(sleepTime); } } }
public Form1() { InitializeComponent(); configurationDetector = new ConfigurationDetector(); config = configurationDetector.Detect(); }
public void Setup() { Configuration = new ConfigurationDetector(); Wrapper = new YoloWrapper(Configuration.Detect()); }
private void TestVideoDetection() { Task.Run(() => { // YOLO setting //int yoloWidth = 1920, yoloHeight = 1129; int yoloWidth = 175, yoloHeight = 102; //int yoloWidth = 1000, yoloHeight = 588; var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); var yoloWrapper = new YoloWrapper(config); // OpenCV & WPF setting VideoCapture videocapture; Mat image = new Mat(); WriteableBitmap wb = new WriteableBitmap(yoloWidth, yoloHeight, 96, 96, System.Windows.Media.PixelFormats.Bgr24, null); byte[] imageInBytes = new byte[(int)(yoloWidth * yoloHeight * image.Channels())]; // Read a video file and run object detection over it! using (videocapture = new VideoCapture("E:\\WPF Projects\\Automotive_Drones_Analysis_Tool\\Daten_automatisches_Fahren\\DJI_0137.MP4")) { for (int i = 0; i < videocapture.FrameCount; i++) { using (Mat imageOriginal = new Mat()) { // read a single frame and convert the frame into a byte array videocapture.Read(imageOriginal); image = imageOriginal.Resize(new OpenCvSharp.Size(yoloWidth, yoloHeight)); imageInBytes = image.ToBytes(); // conduct object detection and display the result var items = yoloWrapper.Detect(imageInBytes); // We use the image to detect the objects in a very small size - then we draw them onto the // uiImage and scale it up! var uiImage = imageOriginal.Resize(new OpenCvSharp.Size(yoloWidth * 10, yoloHeight * 10)); foreach (var item in items) { var x = item.X * 10; var y = item.Y * 10; var width = item.Width * 10; var height = item.Height * 10; var type = item.Type; // class name of the object // draw a bounding box for the detected object // you can set different colors for different classes Cv2.Rectangle(uiImage, new OpenCvSharp.Rect(x, y, width, height), Scalar.Green, 3); } // display the detection result Application.Current?.Dispatcher?.Invoke(() => { videoViewer.Source = BitmapHelper.BitmapToBitmapSource(BitmapConverter.ToBitmap(uiImage)); }); } i++; } } }); }