/// <summary> /// Initializes a new instance of the <see cref="FastRCNN"/> class. /// </summary> /// <param name="model">The model to use.</param> public FastRCNN(FastRCNNModel model) { this.model = model; actualValues = new Dictionary <int, string>(); ExpandoObject jsonValues = Newtonsoft.Json.JsonConvert.DeserializeObject <ExpandoObject>(PredMap.Cifar10); foreach (var item in jsonValues) { actualValues.Add(Convert.ToInt32(item.Key), item.Value.ToString()); } }
/// <summary> /// Generates the rois. /// </summary> /// <param name="bmp">The BMP.</param> /// <param name="model">The model.</param> /// <returns></returns> private List <float> GenerateROIS(Bitmap bmp, FastRCNNModel model) { int selectRois = 4000; int selectionParam = 100; if (model == FastRCNNModel.Grocery100) { selectRois = 100; selectionParam = 1500; } float[] roiList = new float[selectRois * 4]; List <float> inArg3 = new List <float>(); var imgArray = bmp.ToByteArray(); var img = DlibDotNet.Dlib.LoadImageData <DlibDotNet.RgbAlphaPixel>(imgArray, 1000, 1000, 1); var rects = DlibDotNet.Dlib.FindCandidateObjectLocations(img); if (!img.IsDisposed) { img.Dispose(); } int counter = 0; foreach (var item in rects) { if (counter >= selectRois * 4) { break; } roiList[counter] = item.Top * 4; counter++; roiList[counter] = item.Left * 4; counter++; roiList[counter] = item.Width * 4; counter++; roiList[counter] = item.Height * 4; counter++; proposedBoxes.Add(new Rectangle(item.Left * 4, item.Top * 4, (int)item.Width * 4, (int)item.Height * 4)); } if (counter <= selectRois) { for (int i = counter; i < selectRois; i++) { roiList[i] = -1; } } return(roiList.ToList()); }
/// <summary> /// Generates the rois. /// </summary> /// <param name="bmp">The BMP.</param> /// <param name="model">The model.</param> /// <returns></returns> private List <float> GenerateROIS(Bitmap bmp, FastRCNNModel model) { int selectRois = 4000; int selectionParam = 100; if (model == FastRCNNModel.Grocery100) { selectRois = 100; selectionParam = 1500; } float[] roiList = new float[selectRois * 4]; Emgu.CV.Image <Bgr, byte> img = new Image <Bgr, byte>(bmp); Emgu.CV.XImgproc.SelectiveSearchSegmentation seg = new Emgu.CV.XImgproc.SelectiveSearchSegmentation(); var resizedImg = img.Resize(250, 250, Emgu.CV.CvEnum.Inter.Nearest); seg.SetBaseImage(resizedImg); seg.SwitchToSelectiveSearchQuality(selectionParam, selectionParam); var rects = seg.Process(); //rects = rects.OrderBy(x => (x.X)).ToArray(); int counter = 0; foreach (var item in rects) { if (counter >= selectRois * 4) { break; } roiList[counter] = item.X * 4; counter++; roiList[counter] = item.Y * 4; counter++; roiList[counter] = item.Width * 4; counter++; roiList[counter] = item.Height * 4; counter++; proposedBoxes.Add(new Rectangle(item.X * 4, item.Y * 4, item.Width * 4, item.Height * 4)); } if (counter <= selectRois) { for (int i = counter; i < selectRois; i++) { roiList[i] = -1; } } return(roiList.ToList()); }
/// <summary> /// Gets the output variable. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> private Variable GetOutputVar(FastRCNNModel model) { switch (model) { case FastRCNNModel.Pascal: return(modelFunc.Outputs.Where(x => (x.Shape.TotalSize == 84000)).ToList()[0]); case FastRCNNModel.Grocery100: return(modelFunc.Outputs.Where(x => (x.Shape.TotalSize == 1700)).ToList()[0]); default: break; } return(null); }
/// <summary> /// Gets the labels. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> private string[] GetLabels(FastRCNNModel model) { string[] result = null; switch (model) { case FastRCNNModel.Grocery100: result = new[] { "__background__", "avocado", "orange", "butter", "champagne", "egg_Box", "gerkin", "yogurt", "ketchup", "orange_juice", "onion", "pepper", "tomato", "water", "milk", "tabasco", "mustard" }; break; case FastRCNNModel.Pascal: result = new[] { "__background__", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "dining_table", "dog", "horse", "motor_bike", "person", "potted_plant", "sheep", "sofa", "train", "tv_monitor" }; break; default: break; } return(result); }