OpenVINO的环境配置不在叙述,这里主要采用2019R3版本。
测试环境:
win10
vs2015
硬件I74700
英特尔OpenVINO介绍如下模型:
void renderHumanPose(const std::vector& poses, cv::Mat& image) {
CV_Assert(image.type() == CV_8UC3);
const std::vector colors = {
cv::Scalar(255, 0, 0), cv::Scalar(255, 85, 0), cv::Scalar(255, 170, 0),
cv::Scalar(255, 255, 0), cv::Scalar(170, 255, 0), cv::Scalar(85, 255, 0),
cv::Scalar(0, 255, 0), cv::Scalar(0, 255, 85), cv::Scalar(0, 255, 170),
cv::Scalar(0, 255, 255), cv::Scalar(0, 170, 255), cv::Scalar(0, 85, 255),
cv::Scalar(0, 0, 255), cv::Scalar(85, 0, 255), cv::Scalar(170, 0, 255),
cv::Scalar(255, 0, 255), cv::Scalar(255, 0, 170), cv::Scalar(255, 0, 85)
};
const std::vector > limbKeypointsIds = {
{ 1, 2 },{ 1, 5 },{ 2, 3 },
{ 3, 4 },{ 5, 6 },{ 6, 7 },
{ 1, 8 },{ 8, 9 },{ 9, 10 },
{ 1, 11 },{ 11, 12 },{ 12, 13 },
{ 1, 0 },{ 0, 14 },{ 14, 16 },
{ 0, 15 },{ 15, 17 }
};
const int stickWidth = 4;
const cv::Point2f absentKeypoint(-1.0f, -1.0f);
for (const auto& pose : poses) {
CV_Assert(pose.keypoints.size() == HumanPoseEstimator::keypointsNumber);
for (size_t keypointIdx = 0; keypointIdx < pose.keypoints.size(); keypointIdx++) {
if (pose.keypoints[keypointIdx] != absentKeypoint) {
cv::circle(image, pose.keypoints[keypointIdx], 4, colors[keypointIdx], -1);
}
}
}
cv::Mat pane = image.clone();
for (const auto& pose : poses) {
for (const auto& limbKeypointsId : limbKeypointsIds) {
std::pair limbKeypoints(pose.keypoints[limbKeypointsId.first],
pose.keypoints[limbKeypointsId.second]);
if (limbKeypoints.first == absentKeypoint
|| limbKeypoints.second == absentKeypoint) {
continue;
}
float meanX = (limbKeypoints.first.x + limbKeypoints.second.x) / 2;
float meanY = (limbKeypoints.first.y + limbKeypoints.second.y) / 2;
cv::Point difference = limbKeypoints.first - limbKeypoints.second;
double length = std::sqrt(difference.x * difference.x + difference.y * difference.y);
int angle = static_cast(std::atan2(difference.y, difference.x) * 180 / CV_PI);
std::vector polygon;
cv::ellipse2Poly(cv::Point2d(meanX, meanY), cv::Size2d(length / 2, stickWidth),
angle, 0, 360, 1, polygon);
cv::fillConvexPoly(pane, polygon, colors[limbKeypointsId.second]);
}
}
cv::addWeighted(image, 0.4, pane, 0.6, 0, image);
}
相比于其他版本的Human Pose Estimation,openvino给出的Human Pose Estimation版本实时性发现很高,如图在我的老cpu上fp32的精度居然可以达到17fps,而且效果精度很高,很惊喜有木有!