Created
October 31, 2016 17:43
-
-
Save Kikimora/b2690a9279460065ff3084c0b403a5ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the 2D shape (in image space) from global and local parameters | |
void PDM::CalcShape2D(cv::Mat_<double>& out_shape, const cv::Mat_<double>& params_local, const cv::Vec6d& params_global) const | |
{ | |
int n = this->NumberOfPoints(); | |
double s = params_global[0]; // scaling factor | |
double tx = params_global[4]; // x offset | |
double ty = params_global[5]; // y offset | |
// get the rotation matrix from the euler angles | |
cv::Vec3d euler(params_global[1], params_global[2], params_global[3]); | |
cv::Matx33d currRot = Euler2RotationMatrix(euler); | |
// get the 3D shape of the object | |
cv::Mat_<double> Shape_3D = mean_shape + princ_comp * params_local; | |
// create the 2D shape matrix (if it has not been defined yet) | |
if((out_shape.rows != mean_shape.rows) || (out_shape.cols != 1)) | |
{ | |
out_shape.create(2*n,1); | |
} | |
// for every vertex | |
for(int i = 0; i < n; i++) | |
{ | |
// Transform this using the weak-perspective mapping to 2D from 3D | |
out_shape.at<double>(i ,0) = s * ( currRot(0,0) * Shape_3D.at<double>(i, 0) + currRot(0,1) * Shape_3D.at<double>(i+n ,0) + currRot(0,2) * Shape_3D.at<double>(i+n*2,0) ) + tx; | |
out_shape.at<double>(i+n,0) = s * ( currRot(1,0) * Shape_3D.at<double>(i, 0) + currRot(1,1) * Shape_3D.at<double>(i+n ,0) + currRot(1,2) * Shape_3D.at<double>(i+n*2,0) ) + ty; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment