Skip to content

Commit

Permalink
update c# api && demo
Browse files Browse the repository at this point in the history
  • Loading branch information
irexyc committed Sep 20, 2023
1 parent 707aba7 commit 8307560
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
45 changes: 41 additions & 4 deletions csrc/mmdeploy/apis/csharp/MMDeploy/APIs/PoseDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ internal unsafe struct CPoseDetect
{
public Pointf* Point;
public float* Score;
public Rect* BBox;
public float* BBoxScore;
public int Length;
public int BBoxNum;
}
#pragma warning restore 0649

Expand All @@ -28,6 +31,16 @@ public struct PoseDetect
/// </summary>
public List<float> Scores;

/// <summary>
/// BBox.
/// </summary>
public Rect BBox;

/// <summary>
/// BBoxScore.
/// </summary>
public float BBoxScore;

/// <summary>
/// Init points and scores if empty.
/// </summary>
Expand All @@ -40,6 +53,17 @@ private void Init()
}
}

/// <summary>
/// Set bounding box and score.
/// </summary>
/// <param name="bbox">BBox.</param>
/// <param name="score">BBox score.</param>
public void SetBBox(Rect bbox, float score)
{
BBox = bbox;
BBoxScore = score;
}

/// <summary>
/// Add single keypoint to list.
/// </summary>
Expand Down Expand Up @@ -170,13 +194,26 @@ private unsafe void FormatResult(int matCount, int* bboxCount, CPoseDetect* resu
PoseDetectorOutput outi = default;
for (int j = 0; j < bboxCount[i]; j++)
{
PoseDetect boxRes = default;
for (int k = 0; k < results->Length; k++)
int bbox_num = results->BBoxNum;
int num_point_each_bbox = results->Length / results->BBoxNum;
for (int box_id = 0; box_id < bbox_num; box_id++)
{
boxRes.Add(results->Point[k], results->Score[k]);
PoseDetect boxRes = default;
Rect bbox = default;
float score = results->BBoxScore[box_id];
bbox.Left = results->BBox[box_id].Left;
bbox.Top = results->BBox[box_id].Top;
bbox.Right = results->BBox[box_id].Right;
bbox.Bottom = results->BBox[box_id].Bottom;
boxRes.SetBBox(bbox, score);
for (int kp_id = 0; kp_id < num_point_each_bbox; kp_id++)
{
boxRes.Add(results->Point[(box_id * num_point_each_bbox) + kp_id], results->Score[(box_id * num_point_each_bbox) + kp_id]);
}

outi.Add(boxRes);
}

outi.Add(boxRes);
results++;
total++;
}
Expand Down
9 changes: 6 additions & 3 deletions demo/csharp/pose_detection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ static void Main(string[] args)
int index = 0;
foreach (var box in output[0].Results)
{
for (int i = 0; i < box.Points.Count; i++)
var pt1 = new OpenCvSharp.Point((int)box.BBox.Left, (int)box.BBox.Top);
var pt2 = new OpenCvSharp.Point((int)box.BBox.Right, (int)box.BBox.Bottom);
var color = new Scalar(palette[index][0], palette[index][1], palette[index][2]);
Cv2.Rectangle(imgs[0], pt1, pt2, color, 2);
foreach (var point in box.Points)
{
Cv2.Circle(imgs[0], (int)box.Points[i].X, (int)box.Points[i].Y, 1,
new Scalar(palette[index][0], palette[index][1], palette[index][2]), 2);
Cv2.Circle(imgs[0], (int)point.X, (int)point.Y, 1,color, 2);
}
index++;
}
Expand Down

0 comments on commit 8307560

Please sign in to comment.