ZBLOG

static void drawImage( cv::Mat &matBGR,const ListBody& bodies) { for (const auto &body: bodies) { int id = body.id; const int stickWidth = 4; int number = -1; // ...

根据你提供的代码,可以实现以下绘制效果:

static void drawImage(cv::Mat& matBGR, const ListBody& bodies)
{
    for (const auto& body : bodies)
    {
        int id = body.id;
        const int stickWidth = 4;
        int number = -1;
        cv::Scalar leftcolor = g_leftLinesColors[3];
        cv::Scalar rightcolor = g_rightLinesColors[3];

        for (const auto& limb : limbKeypointsIds)
        {
            auto& first_pt = body.joints[limb.first];
            auto& second_pt = body.joints[limb.second];
            number++;
            if ((first_pt.x < 0.1 && first_pt.y < 0.1) ||
                (second_pt.x < 0.1 && second_pt.y < 0.1))
            {
                continue;
            }
            
            cv::Scalar color;
            
            if (limb.first <= 2 && limb.second <= 2)
                color = rightcolor;
            else if (limb.second % 2 == 0)
                color = rightcolor;
            else if (limb.second % 2 != 0)
                color = leftcolor;

            cv::line(matBGR,
                     cv::Point2d(first_pt.x, first_pt.y),
                     cv::Point2d(second_pt.x, second_pt.y),
                     color,
                     stickWidth);
        }

        for (int idx = 0; idx < OBS_JOINT_MAX; ++idx)
        {
            cv::Point2d pt = cv::Point2d(body.joints[idx].x, body.joints[idx].y);

             // 绘制关节点
             if (pt.x > 0.1 && pt.y > 0.1)
             {
                 cv::Scalar pointColor;
                 if (idx <= 2)
                     pointColor = cv::Scalar(255, 255, 255);
                 else if (idx % 2 == 0)
                     pointColor = cv::Scalar(255, 255, 255);
                 else if (idx % 2 != 0)
                     pointColor = cv::Scalar(255, 255, 0);

                 cv::circle(matBGR, pt, 4, pointColor, -1);
             }
         }
     }
}

这段代码使用 OpenCV 库绘制身体关键点和连线。通过遍历 bodies 数组中的每个 body,依次获取关节点的坐标信息进行绘制。根据需要修改 cv::circlecv::line 函数的参数来调整关节点和连线的颜色、粗细等属性。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=17166

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?