From 4f890a7d423b5e05bed890553aa840de2666fd97 Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Sat, 11 Nov 2017 09:22:15 +0000 Subject: [PATCH] Adding visualization files to the project. --- .../src/LandmarkDetectorUtils.cpp | 150 ------------------ lib/local/Utilities/Utilities.vcxproj | 2 + lib/local/Utilities/Utilities.vcxproj.filters | 6 + 3 files changed, 8 insertions(+), 150 deletions(-) diff --git a/lib/local/LandmarkDetector/src/LandmarkDetectorUtils.cpp b/lib/local/LandmarkDetector/src/LandmarkDetectorUtils.cpp index 2bce381..76f334c 100644 --- a/lib/local/LandmarkDetector/src/LandmarkDetectorUtils.cpp +++ b/lib/local/LandmarkDetector/src/LandmarkDetectorUtils.cpp @@ -705,156 +705,6 @@ cv::Matx22d AlignShapesWithScale(cv::Mat_& src, cv::Mat_ dst) // Visualisation functions //=========================================================================== -void DrawBox(cv::Mat image, cv::Vec6d pose, cv::Scalar color, int thickness, float fx, float fy, float cx, float cy) -{ - double boxVerts[] = {-1, 1, -1, - 1, 1, -1, - 1, 1, 1, - -1, 1, 1, - 1, -1, 1, - 1, -1, -1, - -1, -1, -1, - -1, -1, 1}; - - vector> edges; - edges.push_back(pair(0,1)); - edges.push_back(pair(1,2)); - edges.push_back(pair(2,3)); - edges.push_back(pair(0,3)); - edges.push_back(pair(2,4)); - edges.push_back(pair(1,5)); - edges.push_back(pair(0,6)); - edges.push_back(pair(3,7)); - edges.push_back(pair(6,5)); - edges.push_back(pair(5,4)); - edges.push_back(pair(4,7)); - edges.push_back(pair(7,6)); - - // The size of the head is roughly 200mm x 200mm x 200mm - cv::Mat_ box = cv::Mat(8, 3, CV_64F, boxVerts).clone() * 100; - - cv::Matx33d rot = LandmarkDetector::Euler2RotationMatrix(cv::Vec3d(pose[3], pose[4], pose[5])); - cv::Mat_ rotBox; - - // Rotate the box - rotBox = cv::Mat(rot) * box.t(); - rotBox = rotBox.t(); - - // Move the bounding box to head position - rotBox.col(0) = rotBox.col(0) + pose[0]; - rotBox.col(1) = rotBox.col(1) + pose[1]; - rotBox.col(2) = rotBox.col(2) + pose[2]; - - // draw the lines - cv::Mat_ rotBoxProj; - Project(rotBoxProj, rotBox, fx, fy, cx, cy); - - cv::Rect image_rect(0,0,image.cols * draw_multiplier, image.rows * draw_multiplier); - - for (size_t i = 0; i < edges.size(); ++i) - { - cv::Mat_ begin; - cv::Mat_ end; - - rotBoxProj.row(edges[i].first).copyTo(begin); - rotBoxProj.row(edges[i].second).copyTo(end); - - - cv::Point p1(cvRound(begin.at(0) * (double)draw_multiplier), cvRound(begin.at(1) * (double)draw_multiplier)); - cv::Point p2(cvRound(end.at(0) * (double)draw_multiplier), cvRound(end.at(1) * (double)draw_multiplier)); - - // Only draw the line if one of the points is inside the image - if(p1.inside(image_rect) || p2.inside(image_rect)) - { - cv::line(image, p1, p2, color, thickness, CV_AA, draw_shiftbits); - } - - } - -} - -vector> CalculateBox(cv::Vec6d pose, float fx, float fy, float cx, float cy) -{ - double boxVerts[] = {-1, 1, -1, - 1, 1, -1, - 1, 1, 1, - -1, 1, 1, - 1, -1, 1, - 1, -1, -1, - -1, -1, -1, - -1, -1, 1}; - - vector> edges; - edges.push_back(pair(0,1)); - edges.push_back(pair(1,2)); - edges.push_back(pair(2,3)); - edges.push_back(pair(0,3)); - edges.push_back(pair(2,4)); - edges.push_back(pair(1,5)); - edges.push_back(pair(0,6)); - edges.push_back(pair(3,7)); - edges.push_back(pair(6,5)); - edges.push_back(pair(5,4)); - edges.push_back(pair(4,7)); - edges.push_back(pair(7,6)); - - // The size of the head is roughly 200mm x 200mm x 200mm - cv::Mat_ box = cv::Mat(8, 3, CV_64F, boxVerts).clone() * 100; - - cv::Matx33d rot = LandmarkDetector::Euler2RotationMatrix(cv::Vec3d(pose[3], pose[4], pose[5])); - cv::Mat_ rotBox; - - // Rotate the box - rotBox = cv::Mat(rot) * box.t(); - rotBox = rotBox.t(); - - // Move the bounding box to head position - rotBox.col(0) = rotBox.col(0) + pose[0]; - rotBox.col(1) = rotBox.col(1) + pose[1]; - rotBox.col(2) = rotBox.col(2) + pose[2]; - - // draw the lines - cv::Mat_ rotBoxProj; - Project(rotBoxProj, rotBox, fx, fy, cx, cy); - - vector> lines; - - for (size_t i = 0; i < edges.size(); ++i) - { - cv::Mat_ begin; - cv::Mat_ end; - - rotBoxProj.row(edges[i].first).copyTo(begin); - rotBoxProj.row(edges[i].second).copyTo(end); - - cv::Point2d p1(begin.at(0), begin.at(1)); - cv::Point2d p2(end.at(0), end.at(1)); - - lines.push_back(pair(p1,p2)); - - } - - return lines; -} - -void DrawBox(vector> lines, cv::Mat image, cv::Scalar color, int thickness) -{ - cv::Rect image_rect(0,0,image.cols, image.rows); - - for (size_t i = 0; i < lines.size(); ++i) - { - cv::Point p1 = lines.at(i).first; - cv::Point p2 = lines.at(i).second; - // Only draw the line if one of the points is inside the image - if(p1.inside(image_rect) || p2.inside(image_rect)) - { - cv::line(image, p1, p2, color, thickness, CV_AA); - } - - } - -} - // Computing landmarks (to be drawn later possibly) vector CalculateVisibleLandmarks(const cv::Mat_& shape2D, const cv::Mat_& visibilities) { diff --git a/lib/local/Utilities/Utilities.vcxproj b/lib/local/Utilities/Utilities.vcxproj index 5aa039a..d01b231 100644 --- a/lib/local/Utilities/Utilities.vcxproj +++ b/lib/local/Utilities/Utilities.vcxproj @@ -145,6 +145,7 @@ + @@ -152,6 +153,7 @@ + diff --git a/lib/local/Utilities/Utilities.vcxproj.filters b/lib/local/Utilities/Utilities.vcxproj.filters index 41ddb41..1049037 100644 --- a/lib/local/Utilities/Utilities.vcxproj.filters +++ b/lib/local/Utilities/Utilities.vcxproj.filters @@ -30,6 +30,9 @@ Source Files + + Source Files + @@ -47,5 +50,8 @@ Header Files + + Header Files + \ No newline at end of file