Exemplo n.º 1
0
    public unsafe void PassIntPtrFromFloatArray(bool track)
    {
        IEnumerable <YoloItem> yoloItems;

        fixed(float *floatArrayPointer = &floatYoloFormatArray[0])
        {
            yoloItems = track
                                ? yolo.Track(new IntPtr(floatArrayPointer), colorImage.Width, colorImage.Height, channels)
                                : yolo.Detect(new IntPtr(floatArrayPointer), colorImage.Width, colorImage.Height, channels);
        }

        WriteDetectedObjectsOnConsole(yoloItems);
    }
Exemplo n.º 2
0
        public unsafe void PassIntPtrForObjectTracking()
        {
            var image      = new Bitmap(YoloConfigurationTests.DummyImageFilename, false);
            var colorImage = BitmapToColorImage(image, new Model.Size(image.Width, image.Height));
            var floatArray = new FloatArray();
            var array      = floatArray.GetYoloFloatArray(colorImage, Channels);
            IEnumerable <YoloItem> yoloResponse;

            fixed(float *floatArrayPointer = &array[0])
            {
                yoloResponse = yolo.Track(new IntPtr(floatArrayPointer), colorImage.Width,
                                          colorImage.Height, Channels);
            }

            foreach (var item in yoloResponse)
            {
                Assert.That(item.Type, Is.EqualTo("StressBall"));
                Console.WriteLine("Frame: " + item.FrameId + " Shape: " + item.Shape + " Found:" +
                                  item.Type + " ID: " + item.TrackId + " BB: [" + item.X + "," + item.Y + "," +
                                  item.Width + "," + item.Height + "]");
            }
        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            string currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string sourceFolder     = Path.Combine(currentDirectory, "thumbnails");

            if (!Directory.Exists(sourceFolder))
            {
                Console.WriteLine($"{sourceFolder} does not exist. Exiting ...");
                Console.ReadLine();
            }

            // set dll load path
            SetDllDirectory(Path.Combine(currentDirectory, @"lib"));

            // quick detect
            string inputImage0 = Path.Combine(sourceFolder, "thumbnail-0.jpg");
            string inputImage1 = Path.Combine(sourceFolder, "thumbnail-1.jpg");
            string inputImage2 = Path.Combine(sourceFolder, "thumbnail-2.jpg");

            string[] inputImages = { inputImage0, inputImage1, inputImage2 };

            string objectNames     = Path.Combine(currentDirectory, @"config\coco.names");
            string cfgFile         = Path.Combine(currentDirectory, @"config\yolov3.cfg");
            string weightsFilename = Path.Combine(currentDirectory, @"weights\yolov3.weights");

            try
            {
                string[] names = File.ReadAllLines(objectNames);

                using (YoloWrapper yolo = new YoloWrapper(cfgFile, weightsFilename, 0))
                {
                    Stopwatch watch = Stopwatch.StartNew();
                    foreach (string inputImage in inputImages)
                    {
                        watch.Restart();
                        YoloWrapper.bbox_t[] objectBoxes = yolo.Detect(inputImage);
                        watch.Stop();
                        long detectMili = watch.ElapsedMilliseconds;

                        watch.Restart();
                        YoloWrapper.bbox_t[] boxes = yolo.Track(objectBoxes);
                        watch.Stop();
                        long trackmili = watch.ElapsedMilliseconds;

                        Console.WriteLine($"File {ShortenString(inputImage)} predicted in\t: {detectMili / 1000d}s");
                        Console.WriteLine($"File {ShortenString(inputImage)} tracking in\t: {trackmili / 1000d}s");
                        Console.WriteLine($"Total detections\t: {boxes.Length}");

                        foreach (YoloWrapper.bbox_t item in boxes)
                        {
                            if (item.prob >= detectionThreshold)
                            {
                                string detectedObject = item.obj_id < names.Length ? names[item.obj_id] : "N/A";
                                Console.Write($"[{item.track_id}]\t{detectedObject}: {Math.Floor(item.prob * 100d)}%\t");
                                Console.WriteLine($"(left_x:\t{item.x}\ttop_y:\t{item.y}\twidth:\t{item.w}\theight:\t{item.h})");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            finally
            {
                Console.ReadLine();
            }
        }