Skip to content

Add keypoints matching visualization for real-time pose estimation tutorial - #13835

Merged
opencv-pushbot merged 1 commit into
opencv:3.4from
catree:real_time_pose_tutorial_keypoints_matching
Feb 18, 2019
Merged

opencv-pushbot merged 1 commit into
opencv:3.4from
catree:real_time_pose_tutorial_keypoints_matching

Conversation

@catree

@catree catree commented Feb 14, 2019 •

Copy link
Copy Markdown
Contributor
  • Lots of auto formatting code changes.
  • Fix parsing of arguments:
    numKeyPoints = !parser.has("keypoints") ? parser.get<int>("keypoints") : numKeyPoints;
    ratioTest = !parser.has("ratio") ? parser.get<float>("ratio") : ratioTest;
    fast_match = !parser.has("fast") ? parser.get<bool>("fast") : fast_match;
    iterationsCount = !parser.has("iterations") ? parser.get<int>("iterations") : iterationsCount;
    reprojectionError = !parser.has("error") ? parser.get<float>("error") : reprojectionError;
    confidence = !parser.has("confidence") ? parser.get<float>("confidence") : confidence;
    minInliersKalman = !parser.has("inliers") ? parser.get<int>("inliers") : minInliersKalman;
    pnpMethod = !parser.has("method") ? parser.get<int>("method") : pnpMethod;
  • Add keypoints matching visualization (only after training a new model file)
  • Add possibility to use another type of keypoints (not only ORB)

It is not possible to get the same detection results with the provided image and video than in the tutorial video.

Beware of the Kalman filter formulation used (constant acceleration on Euler angles). Here what looks like a better formulation.


Some video results (unfortunately, YouTube applied too much compression):

Training pose:

cv::Mat rvec = (cv::Mat_<double>(3,1) << 2.073596928195101, -0.8861248486736736, 0.4648378262984375);
cv::Mat tvec = (cv::Mat_<double>(3,1) << -65.34756669790684, -34.34732391473651, 361.0313725421983);

cv::FileStorage storage(path, cv::FileStorage::WRITE);
storage << "points_3d" << points3dmatrix;
storage << "points_2d" << points2dmatrix;
storage << "keypoints" << list_keypoints_;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modification to save keypoints and path to the training image. This way, during the detection it is possible to display the keypoints matching.

@catree
catree force-pushed the real_time_pose_tutorial_keypoints_matching branch from 023db96 to 57d590c Compare February 14, 2019 19:02
cv::FileStorage storage(path, cv::FileStorage::READ);
storage["points_3d"] >> points3d_mat;
storage["descriptors"] >> descriptors_;
if (!storage["keypoints"].empty())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read keypoints and path to training image if node is not empty.

};

// Functions for Möller-Trumbore intersection algorithm
cv::Point3f CROSS(cv::Point3f v1, cv::Point3f v2);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions declaration not needed here.

cv::Point2i pointZ = list_points2d[3];

drawArrow(image, origin, pointX, red, 9, 2);
drawArrow(image, origin, pointY, blue, 9, 2);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix Y axis drawn in blue (should be green).

return ss.str();
}

void createFeatures(const std::string &featureName, int numKeypoints, cv::Ptr<cv::Feature2D> &detector, cv::Ptr<cv::Feature2D> &descriptor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add possibility to use different types of features.

"{keypoints k |2000 | number of keypoints to detect }"
"{ratio r |0.7 | threshold for ratio test }"
"{iterations it |500 | RANSAC maximum iterations count }"
"{error e |6.0 | RANSAC reprojection error }"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increase RANSAC reprojection (2 pixel error seems too harsh, some valid points could be treated as outliers, especially with the incertitude errors about the intrinsic camera parameters and the camera distortion) threshold and RANSAC confidence.

@catree

catree commented Feb 14, 2019

Copy link
Copy Markdown
Contributor Author

I have put some comments to highlight the relevant changes since lots of the changes are whitespace related.

@catree
catree force-pushed the real_time_pose_tutorial_keypoints_matching branch 2 times, most recently from a4abf48 to 5569465 Compare February 15, 2019 08:55

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you for the contribution 👍


string img_path = tutorial_path + "Data/resized_IMG_3875.JPG"; // image to register
string ply_read_path = tutorial_path + "Data/box.ply"; // object mesh
string write_path = tutorial_path + "Data/cookies_ORB.yml"; // output file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try to use samples::findFile() from here: #12354 ?
Perhaps "../../samples" prefix should be dropped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works with the updated changes (on Ubuntu).

…atures type. Add keypoints matching visualization. Auto format code.
@catree
catree force-pushed the real_time_pose_tutorial_keypoints_matching branch from 5569465 to 3c92d40 Compare February 18, 2019 13:16
@opencv-pushbot
opencv-pushbot merged commit 3c92d40 into opencv:3.4 Feb 18, 2019
opencv-pushbot pushed a commit that referenced this pull request Feb 18, 2019
@alalek alalek mentioned this pull request Feb 19, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants