public YoloWrapper(string configurationFilename, string weightsFilename, string namesFilename, int gpu = 0) { objectTypeResolver = new YoloObjectTypeResolver(namesFilename); Initialize(configurationFilename, weightsFilename, gpu); container = new BboxContainer(); }
private IEnumerable <YoloItem> Convert(BboxContainer container) { var yoloItems = new List <YoloItem>(); foreach (var item in container.candidates.Where(o => o.h > 0 || o.w > 0)) { if (!this._objectType.TryGetValue((int)item.obj_id, out var objectType)) { objectType = "unknown key"; } var yoloItem = new YoloItem { X = (int)item.x, Y = (int)item.y, Height = (int)item.h, Width = (int)item.w, Confidence = item.prob, Type = objectType }; yoloItems.Add(yoloItem); } return(yoloItems); }
public IEnumerable <YoloItem> Track(IntPtr floatArrayPointer, int width, int height, int channel = 3) { var container = new BboxContainer(); TrackObjectsGpu(floatArrayPointer, width, height, channel, ref container); return(Convert(container, objectTypeResolver)); }
public IEnumerable <YoloItem> Detect(byte[] imageData) { var container = new BboxContainer(); var size = Marshal.SizeOf(imageData[0]) * imageData.Length; var pnt = Marshal.AllocHGlobal(size); try { // Copy the array to unmanaged memory. Marshal.Copy(imageData, 0, pnt, imageData.Length); var count = 0; switch (this.DetectionSystem) { case DetectionSystem.CPU: count = DetectImageCpu(pnt, imageData.Length, ref container); break; case DetectionSystem.GPU: count = DetectImageGpu(pnt, imageData.Length, ref container); break; } } catch (Exception exception) { return(null); } finally { // Free the unmanaged memory. Marshal.FreeHGlobal(pnt); } return(this.Convert(container)); }
public bbox_t[] Detect(string filename) { var container = new BboxContainer(); var count = DetectImage(filename, ref container); return(container.candidates); }
public bbox_t[] Detect(byte[] imageData) { var container = new BboxContainer(); var size = Marshal.SizeOf(imageData[0]) * imageData.Length; var pnt = Marshal.AllocHGlobal(size); try { // Copy the array to unmanaged memory. Marshal.Copy(imageData, 0, pnt, imageData.Length); DetectImage(pnt, imageData.Length, ref container); } catch (Exception exception) { return(null); } finally { // Free the unmanaged memory. Marshal.FreeHGlobal(pnt); } return(container.candidates); }
public bbox_t[] Detect(byte[] imageData) { var container = new BboxContainer(); var size = Marshal.SizeOf(imageData[0]) * imageData.Length; var pnt = Marshal.AllocHGlobal(size); try { // Copy the array to unmanaged memory. Marshal.Copy(imageData, 0, pnt, imageData.Length); var count = DetectImage(pnt, imageData.Length, ref container); if (count == -1) { throw new NotSupportedException($"{YoloLibraryName} has no OpenCV support"); } } catch (Exception exception) { return(null); } finally { // Free the unmanaged memory. Marshal.FreeHGlobal(pnt); } return(container.candidates); }
private IEnumerable <YoloItem> Convert(BboxContainer container) { var items = container.candidates.Where(o => o.h > 0 || o.w > 0).Select(o => new YoloItem { X = (int)o.x, Y = (int)o.y, Height = (int)o.h, Width = (int)o.w, Confidence = o.prob, Type = this._objectTypeResolver.Resolve((int)o.obj_id) } ).OrderBy(o => o.Y).ToList();; for (var i = 0; i < items.Count; i++) { if (i + 1 < items.Count) { items[i].StandardDeviation = CalculateStandardDeviationTwoPoints(new int[] { items[i].Y, items[i + 1].Y }); } else { items[i].StandardDeviation = 0.0; } } return(items.OrderBy(o => o.Y)); }
/// <summary> /// Detect objects on an image /// </summary> /// <param name="filepath"></param> /// <returns></returns> /// <exception cref="FileNotFoundException">Thrown when the filepath is wrong</exception> public IEnumerable <YoloItem> Detect(string filepath) { if (!File.Exists(filepath)) { throw new FileNotFoundException("Cannot find the file", filepath); } var container = new BboxContainer(); var count = 0; switch (this.DetectionSystem) { case DetectionSystem.CPU: count = DetectImageCpu(filepath, ref container); break; case DetectionSystem.GPU: count = DetectImageGpu(filepath, ref container); break; } if (count == -1) { throw new NotImplementedException("C++ dll compiled incorrectly"); } return(this.Convert(container)); }
/// <summary> /// Detect objects on an image /// </summary> /// <param name="imagePtr"></param> /// <param name="size"></param> /// <returns></returns> /// <exception cref="NotImplementedException">Thrown when the yolo_cpp dll is wrong compiled</exception> public IEnumerable <YoloItem> Detect(IntPtr imagePtr, int size) { var container = new BboxContainer(); var count = 0; try { switch (this.DetectionSystem) { case DetectionSystem.CPU: count = DetectImageCpu(imagePtr, size, ref container); break; case DetectionSystem.GPU: count = DetectImageGpu(imagePtr, size, ref container); break; } } catch (Exception) { return(null); } if (count == -1) { throw new NotImplementedException("C++ dll compiled incorrectly"); } return(this.Convert(container)); }
public IEnumerable <YoloItem> Track(byte[] imageData) { if (!this._imageAnalyzer.IsValidImageFormat(imageData)) { throw new Exception("Invalid image data, wrong image format"); } var container = new BboxContainer(); var size = Marshal.SizeOf(imageData[0]) * imageData.Length; var pnt = Marshal.AllocHGlobal(size); try { // Copy the array to unmanaged memory. Marshal.Copy(imageData, 0, pnt, imageData.Length); var count = 0; switch (this.DetectionSystem) { case DetectionSystem.CPU: count = TrackImageCpu(pnt, imageData.Length, (float)0.3, (float)0.2, ref container); break; case DetectionSystem.GPU: switch (this.DnnMode) { case DNNMode.Frame: case DNNMode.LT: count = TrackImageGpuLt(pnt, imageData.Length, (float)0.3, (float)0.2, ref container); break; case DNNMode.CC: count = TrackImageGpuCc(pnt, imageData.Length, (float)0.3, (float)0.2, ref container); break; } break; } if (count == -1) { throw new NotImplementedException("c++ dll compiled incorrectly"); } } catch (Exception) { return(null); } finally { // Free the unmanaged memory. Marshal.FreeHGlobal(pnt); } return(this.Convert(container)); }
public bbox_t[] Track(bbox_t[] candiates) { var container = new BboxContainer() { candidates = candiates }; var newContainer = new BboxContainer(); var count = TrackId(ref container, ref newContainer); return(newContainer.candidates); }
public IEnumerable <YoloItem> Detect(string filepath) { if (!File.Exists(filepath)) { throw new FileNotFoundException("Cannot find the file", filepath); } var container = new BboxContainer(); DetectImageGpu(filepath, ref container); return(Convert(container, objectTypeResolver)); }
public static IEnumerable <YoloItem> Convert(BboxContainer container, YoloObjectTypeResolver objectTypeResolver) => container.candidates.Where(o => o.h > 0 || o.w > 0) .Select(item => new YoloItem { X = (int)item.x, Y = (int)item.y, Height = (int)item.h, Width = (int)item.w, Confidence = item.prob, FrameId = (int)item.frames_counter, TrackId = (int)item.track_id, Shape = (YoloItem.ShapeType)item.shape, Type = objectTypeResolver.Resolve((int)item.obj_id) }).ToList();
public bbox_t[] Detect(image_t data, float threshold) { var container = new BboxContainer(); fixed(float *pData = data.data) { var internalData = new internal_image_t { w = data.w, h = data.h, c = data.c, data = pData }; var count = DetectTensor(internalData, threshold, ref container); return(container.candidates.Take(count).ToArray()); } }
private IEnumerable <YoloItem> Convert(BboxContainer container) { return(container.candidates.Where(o => o.h > 0 || o.w > 0).Select(o => new YoloItem { X = (int)o.x, Y = (int)o.y, Height = (int)o.h, Width = (int)o.w, Confidence = o.prob, Type = this._objectTypeResolver.Resolve((int)o.obj_id) } )); }
private IEnumerable <YoloItem> Convert(BboxContainer container) { var yoloItems = new List <YoloItem>(); foreach (var item in container.candidates.Where(o => o.h > 0 || o.w > 0)) { var objectType = this._objectType[(int)item.obj_id]; var yoloItem = new YoloItem() { X = (int)item.x, Y = (int)item.y, Height = (int)item.h, Width = (int)item.w, Confidence = item.prob, Type = objectType }; yoloItems.Add(yoloItem); } return(yoloItems); }
/// <summary> /// Detect objects on an image /// </summary> /// <param name="imageData"></param> /// <param name="size"></param> /// <returns></returns> /// <exception cref="NotImplementedException">Thrown when the yolo_cpp dll is wrong compiled</exception> public IEnumerable <YoloItem> Detect(IntPtr imageData, int size) { int minHeaderSize = this._imageAnalyzer.MinHeaderSize; bool ok = size >= minHeaderSize; if (ok) { Marshal.Copy(imageData, _headerBuffer, 0, minHeaderSize); ok = this._imageAnalyzer.IsValidImageFormat(_headerBuffer); } if (!ok) { throw new Exception("Invalid image data, wrong image format"); } var container = new BboxContainer(); var count = 0; try { switch (this.DetectionSystem) { case DetectionSystem.CPU: count = DetectImageCpu(imageData, size, ref container); break; case DetectionSystem.GPU: count = DetectImageGpu(imageData, size, ref container); break; } } catch (Exception) { return(null); } if (count == -1) { throw new NotImplementedException("C++ dll compiled incorrectly"); } return(this.Convert(container)); }
public IEnumerable <YoloItem> Detect(string filename) { var container = new BboxContainer(); var count = 0; switch (this.DetectionSystem) { case DetectionSystem.CPU: count = DetectImageCpu(filename, ref container); break; case DetectionSystem.GPU: count = DetectImageGpu(filename, ref container); break; } return(this.Convert(container)); }
public bbox_t[] Detect() { var container = new BboxContainer(); int CV_8UC3 = 16; // OpenCV constant // using Emgu.CV; // www.emgucv.com - cross platform .Net wrapper to the OpenCV image processing library. // Image<Bgr, byte> cvBitmap = new Image<Bgr, byte>(640, 480); // Image<Bgr, byte> cvBitmap = new Image<Bgr, byte>(System.Drawing.Bitmap bmp); // Image<Bgr, byte> cvBitmap = new Image<Bgr, byte>(string fileName); // etc.. // // // Mat mat = cvBitmap.Mat; // int count = DetectImage(mat.Rows, mat.Cols, CV_8UC3, mat.DataPointer, ref container); return(container.candidates); }
/// <summary> /// Detect objects on an image /// </summary> /// <param name="imageData"></param> /// <returns></returns> /// <exception cref="NotImplementedException">Thrown when the yolo_cpp dll is wrong compiled</exception> /// <exception cref="Exception">Thrown when the byte array is not a valid image</exception> public unsafe IEnumerable <YoloItem> Detect(byte[] imageData) { if (!_imageAnalyzer.IsValidImageFormat(imageData)) { throw new Exception("Invalid image data, wrong image format"); } var container = new BboxContainer(); var count = 0; try { fixed(byte *pnt = imageData) { switch (DetectionSystem) { case DetectionSystem.CPU: count = DetectImageCpu((IntPtr)pnt, imageData.Length, ref container); break; case DetectionSystem.GPU: count = DetectImageGpu((IntPtr)pnt, imageData.Length, ref container); break; } } } catch (Exception) { return(null); } if (count == -1) { throw new NotImplementedException("C++ dll compiled incorrectly"); } return(Convert(container)); }
public IEnumerable <YoloItem> Track(string filepath) { if (!File.Exists(filepath)) { throw new FileNotFoundException("Cannot find the file", filepath); } var container = new BboxContainer(); var count = 0; switch (this.DetectionSystem) { case DetectionSystem.CPU: count = TrackImageCpu(filepath, (float)0.3, (float)0.2, ref container); break; case DetectionSystem.GPU: switch (this.DnnMode) { case DNNMode.Frame: case DNNMode.LT: count = TrackImageGpuLt(filepath, (float)0.3, (float)0.2, ref container); break; case DNNMode.CC: count = TrackImageGpuCc(filepath, (float)0.3, (float)0.2, ref container); break; } break; } if (count == -1) { throw new NotImplementedException("c++ dll compiled incorrectly"); } return(this.Convert(container)); }
Convert(BboxContainer container, YoloObjectTypeResolver objectTypeResolver) { var yoloItems = new List <YoloItem>(); foreach (var item in container.candidates) { if (item.w > 0 || item.h > 0) { yoloItems.Add(new YoloItem { X = (int)item.x, Y = (int)item.y, Height = (int)item.h, Width = (int)item.w, Confidence = item.prob, FrameId = (int)item.frames_counter, TrackId = (int)item.track_id, Shape = (YoloItem.ShapeType)item.shape, Type = objectTypeResolver.Resolve((int)item.obj_id) }); } } return(yoloItems); }
internal static extern int DetectImageGpu(IntPtr pArray, int nSize, ref BboxContainer container);
internal static extern int DetectImageGpu(string filename, ref BboxContainer container);
private static extern int DetectTensor(internal_image_t data, float threshold, ref BboxContainer container);
private static extern int TrackId(ref BboxContainer container, ref BboxContainer newContainer);
private static extern int DetectImage(IntPtr pArray, int nSize, ref BboxContainer container);
private static extern int DetectImage(string filename, ref BboxContainer container);
private static extern int TrackObjectsGpu(IntPtr pArray, int width, int height, int channel, ref BboxContainer container);