OpenVINO的環境配置不在敘述,這裏主要採用2019R3版本。
測試環境:
win10
vs2015
硬件I74700
英特爾OpenVINO介紹如下模型:
- Object Detection Models / 目標檢測模型
- Object Recognition Models / 目標識別模型
- Reidentification Models / 迴歸模型
- Semantic Segmentation Models / 語義分割模型
- Instance Segmentation Models / 實例分割模型
- Human Pose Estimation Models / 人類姿勢識別模型
- Image Processing/ 圖像處理
- Text Detection / 文本檢測
- Text Recognition / 文本識別
- Text Spotting / 文本識別
- Action Recognition Models / 動作識別模型
- Image Retrieval / 圖像檢索
- Compressed models / 壓縮模型
void renderHumanPose(const std::vector<HumanPose>& poses, cv::Mat& image) {
CV_Assert(image.type() == CV_8UC3);
const std::vector<cv::Scalar> 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<std::pair<int, int> > 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<cv::Point2f, cv::Point2f> 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<int>(std::atan2(difference.y, difference.x) * 180 / CV_PI);
std::vector<cv::Point> 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,而且效果精度很高,很驚喜有木有!