/// <summary> /// 提取出边框盒 /// </summary> /// <param name="outputs"></param> /// <returns></returns> private Dictionary <Point, List <CubicBoundingBox> > ExtractBoundingBox(Dictionary <Point, float[]> outputs) { Dictionary <Point, List <CubicBoundingBox> > boxesInCells = new Dictionary <Point, List <CubicBoundingBox> >(); int outputCountPerAnchor = 9 * 2 + classOut + 1; foreach (var output in outputs) { List <CubicBoundingBox> boxes = new List <CubicBoundingBox>(); for (int i = 0; i < anchorCount; ++i) { int anchorOffset = i * outputCountPerAnchor; var outputValue = output.Value; //�������ĺ��� //var confidentValue = Sigmoid(outputValue[2 * 9 + anchorOffset]); PointF centerPoint = new PointF((Sigmoid(outputValue[0 + anchorOffset]) + output.Key.X) / SegementsSize.Width, (Sigmoid(outputValue[1 + anchorOffset]) + output.Key.Y) / SegementsSize.Height); CubicBoundingBox cubicBoundingBoxes = new CubicBoundingBox(); cubicBoundingBoxes.ControlPoint[8] = centerPoint; for (int j = 2; j < 2 + 8 * 2; j += 2) { PointF point = new PointF((outputValue[j + anchorOffset] + output.Key.X) / SegementsSize.Width, (outputValue[j + 1 + anchorOffset] + output.Key.Y) / SegementsSize.Height); cubicBoundingBoxes.ControlPoint[j / 2 - 1] = point; } boxes.Add(cubicBoundingBoxes); } boxesInCells.Add(output.Key, boxes); } return(boxesInCells); }
public async Task <List <CubicBoundingBox> > DetectObjectPoseFromImagePixelsAsync(byte[] imagePixels) { List <CubicBoundingBox> boxes = new List <CubicBoundingBox>(); using (var imageTensor = ConvertPixelsByteToTensor(imagePixels, BitmapPixelFormat.Bgra8)) using (var input = new SingelObjectApeModelV8Input() { Image = imageTensor }) using (var output = await model.EvaluateAsync(input).ConfigureAwait(true)) { var shape = output.Grid.Shape; var content = output.Grid.GetAsVectorView().ToArray(); List <float[]> abc = new List <float[]> { content }; using (OutputParser outputParser = new OutputParser(abc, classCount, anchorCount, confThresh)) { foreach (var box in outputParser.BoundingBoxes) { var newBox = new CubicBoundingBox() { Confidence = box.Confidence, Identity = box.Identity }; foreach (var point in box.ControlPoint) { newBox.ControlPoint.Append(point); } boxes.Add(box); } } } return(boxes); }