Landmark smoothers
This commit is contained in:
parent
15febc4651
commit
ec0d5090fc
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
//#define USE_PREDICTION
|
//#define USE_PREDICTION
|
||||||
|
|
||||||
|
#define SMOOTH_LANDMARKS
|
||||||
|
|
||||||
cv::Point flipVertical(cv::Point point) {
|
cv::Point flipVertical(cv::Point point) {
|
||||||
return cv::Point(point.x, 720 - point.y);
|
return cv::Point(point.x, 720 - point.y);
|
||||||
}
|
}
|
||||||
@ -53,6 +55,20 @@ FaceStruct::FaceStruct(const std::array<cv::Point2f, LANDMARK_POINT_COUNT>& from
|
|||||||
|
|
||||||
void FaceStruct::CalcFromPreds(double similarity, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficients)
|
void FaceStruct::CalcFromPreds(double similarity, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficients)
|
||||||
{
|
{
|
||||||
|
#ifdef SMOOTH_LANDMARKS
|
||||||
|
for(size_t i = 0; i < LANDMARK_POINT_COUNT; i++) {
|
||||||
|
if(similarity < 0.01) {
|
||||||
|
preds[i] = Vector2f(
|
||||||
|
landmarkSmoothers[i * 2].responsiveAnalogReadSimple(preds[i](0)),
|
||||||
|
landmarkSmoothers[i * 2 + 1].responsiveAnalogReadSimple(preds[i](1))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
landmarkSmoothers[i * 2].reset();
|
||||||
|
landmarkSmoothers[i * 2 + 1].reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
float minX = preds[0](0);
|
float minX = preds[0](0);
|
||||||
float maxX = preds[0](0);
|
float maxX = preds[0](0);
|
||||||
float minY = preds[0](1);
|
float minY = preds[0](1);
|
||||||
@ -107,17 +123,17 @@ void FaceStruct::CalcFromPreds(double similarity, cv::Mat& cameraMatrix, cv::Mat
|
|||||||
|
|
||||||
cv::solvePnP(modelPoints, imagePoints, cameraMatrix, distortionCoefficients, rotationVector, translationVector);
|
cv::solvePnP(modelPoints, imagePoints, cameraMatrix, distortionCoefficients, rotationVector, translationVector);
|
||||||
|
|
||||||
if(similarity > 0.01) {
|
//if(similarity > 0.01) {
|
||||||
for (size_t i = 0; i < 3; i++) {
|
// for (size_t i = 0; i < 3; i++) {
|
||||||
rotationVectorSmoothers[i].reset();
|
// rotationVectorSmoothers[i].reset();
|
||||||
translationVectorSmoothers[i].reset();
|
// translationVectorSmoothers[i].reset();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
for(size_t i = 0; i < 3; i++) {
|
/*for(size_t i = 0; i < 3; i++) {
|
||||||
rotationVector.at<double>(i) = rotationVectorSmoothers[i].responsiveAnalogReadSimple(rotationVector.at<double>(i));
|
rotationVector.at<double>(i) = rotationVectorSmoothers[i].responsiveAnalogReadSimple(rotationVector.at<double>(i));
|
||||||
// translationVector.at<double>(i) = translationVectorSmoothers[i].responsiveAnalogReadSimple(translationVector.at<double>(i));
|
translationVector.at<double>(i) = translationVectorSmoothers[i].responsiveAnalogReadSimple(translationVector.at<double>(i));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
cv::projectPoints(boxModelSrc, rotationVector, translationVector, cameraMatrix, distortionCoefficients, boxModelDst);
|
cv::projectPoints(boxModelSrc, rotationVector, translationVector, cameraMatrix, distortionCoefficients, boxModelDst);
|
||||||
|
|
||||||
@ -478,7 +494,7 @@ void TMyApplication::InnerUpdate(size_t dt)
|
|||||||
faceStruct[index].ApplyPreds(faceLandmarkArr[index].landmarkArr, faceLandmarkArr[index].similarity, cameraMatrix, distortionCoefficients);
|
faceStruct[index].ApplyPreds(faceLandmarkArr[index].landmarkArr, faceLandmarkArr[index].similarity, cameraMatrix, distortionCoefficients);
|
||||||
std::ostringstream similarityText;
|
std::ostringstream similarityText;
|
||||||
similarityText << std::setprecision(3) << faceLandmarkArr[index].similarity;
|
similarityText << std::setprecision(3) << faceLandmarkArr[index].similarity;
|
||||||
cv::putText(renderImage, similarityText.str(), cv::Point(50, index * 60 + 60), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(0, 0, 0));
|
cv::putText(renderImage, similarityText.str(), cv::Point(50, index * 60 + 60), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(255, 255, 255));
|
||||||
|
|
||||||
for (size_t i = 0; i < LANDMARK_POINT_COUNT; i++)
|
for (size_t i = 0; i < LANDMARK_POINT_COUNT; i++)
|
||||||
{
|
{
|
||||||
|
@ -45,20 +45,15 @@ struct FaceStruct
|
|||||||
std::vector<cv::Point3d> boxModelSrc;
|
std::vector<cv::Point3d> boxModelSrc;
|
||||||
std::vector<cv::Point2d> boxModelDst;
|
std::vector<cv::Point2d> boxModelDst;
|
||||||
|
|
||||||
|
ValueSmoother landmarkSmoothers[2 * LANDMARK_POINT_COUNT];
|
||||||
ValueSmoother rotationVectorSmoothers[3];
|
ValueSmoother rotationVectorSmoothers[3];
|
||||||
ValueSmoother translationVectorSmoothers[3];
|
ValueSmoother translationVectorSmoothers[3];
|
||||||
|
|
||||||
std::vector<cv::Point3f> noseEndPoint3d;
|
|
||||||
std::vector<cv::Point2f> noseEndPoint2d;
|
|
||||||
|
|
||||||
FaceStruct();
|
FaceStruct();
|
||||||
|
|
||||||
FaceStruct(const std::array<cv::Point2f, LANDMARK_POINT_COUNT>& fromPreds, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficients);
|
FaceStruct(const std::array<cv::Point2f, LANDMARK_POINT_COUNT>& fromPreds, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficients);
|
||||||
|
|
||||||
void CalcFromPreds(double similarity, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficients);
|
void CalcFromPreds(double similarity, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficients);
|
||||||
|
|
||||||
void ApplyPreds(const std::array<cv::Point2f, LANDMARK_POINT_COUNT>& fromPred, double similarity, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficientss);
|
void ApplyPreds(const std::array<cv::Point2f, LANDMARK_POINT_COUNT>& fromPred, double similarity, cv::Mat& cameraMatrix, cv::Mat& distortionCoefficientss);
|
||||||
|
|
||||||
void InnerApplyPreds(const std::array<cv::Point2f, LANDMARK_POINT_COUNT>& fromPreds);
|
void InnerApplyPreds(const std::array<cv::Point2f, LANDMARK_POINT_COUNT>& fromPreds);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
bool inited = false;
|
bool inited = false;
|
||||||
|
|
||||||
//float SNAP_MULTIPLIER_SIMPLE = 1.0 / 60;
|
float SNAP_MULTIPLIER_SIMPLE = 1.0 / 60;
|
||||||
|
|
||||||
float SNAP_MULTIPLIER_SIMPLE = 0.3;
|
//float SNAP_MULTIPLIER_SIMPLE = 0.3;
|
||||||
|
|
||||||
float smoothValue = 0;
|
float smoothValue = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user