------------------
Finds an object pose from 3D-2D point correspondences using the RANSAC scheme.
-.. ocv:function:: bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int iterationsCount = 100, float reprojectionError = 8.0, float confidence = 0.99, OutputArray inliers = noArray(), int flags = ITERATIVE )
+.. ocv:function:: bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int iterationsCount = 100, float reprojectionError = 8.0, double confidence = 0.99, OutputArray inliers = noArray(), int flags = ITERATIVE )
.. ocv:pyfunction:: cv2.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, minInliersCount[, inliers[, flags]]]]]]]]) -> rvec, tvec, inliers
InputArray cameraMatrix, InputArray distCoeffs,
OutputArray rvec, OutputArray tvec,
bool useExtrinsicGuess = false, int iterationsCount = 100,
- float reprojectionError = 8.0, float confidence = 0.99,
+ float reprojectionError = 8.0, double confidence = 0.99,
OutputArray inliers = noArray(), int flags = ITERATIVE );
//! initializes camera matrix from a few 3D points and the corresponding projections.
bool cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
InputArray _cameraMatrix, InputArray _distCoeffs,
OutputArray _rvec, OutputArray _tvec, bool useExtrinsicGuess,
- int iterationsCount, float reprojectionError, float confidence,
+ int iterationsCount, float reprojectionError, double confidence,
OutputArray _inliers, int flags)
{
getline(liness, z);
cv::Point3f tmp_p;
- tmp_p.x = StringToInt(x);
- tmp_p.y = StringToInt(y);
- tmp_p.z = StringToInt(z);
+ tmp_p.x = (float)StringToInt(x);
+ tmp_p.y = (float)StringToInt(y);
+ tmp_p.z = (float)StringToInt(z);
list_vertex.push_back(tmp_p);
count++;
csvReader.readPLY(list_vertex_, list_triangles_);
// Update mesh attributes
- num_vertexs_ = list_vertex_.size();
- num_triangles_ = list_triangles_.size();
+ num_vertexs_ = (int)list_vertex_.size();
+ num_triangles_ = (int)list_triangles_.size();
}
// Estimate the pose given a list of 2D/3D correspondences with RANSAC and the method to use
void PnPProblem::estimatePoseRANSAC( const std::vector<cv::Point3f> &list_points3d, // list with model 3D coordinates
- const std::vector<cv::Point2f> &list_points2d, // list with scene 2D coordinates
- int flags, cv::Mat &inliers, int iterationsCount, // PnP method; inliers container
- float reprojectionError, float confidence ) // Ransac parameters
+ const std::vector<cv::Point2f> &list_points2d, // list with scene 2D coordinates
+ int flags, cv::Mat &inliers, int iterationsCount, // PnP method; inliers container
+ float reprojectionError, double confidence ) // Ransac parameters
{
cv::Mat distCoeffs = cv::Mat::zeros(4, 1, CV_64FC1); // vector of distortion coefficients
cv::Mat rvec = cv::Mat::zeros(3, 1, CV_64FC1); // output rotation vector
// Normalization of [u v]'
cv::Point2f point2d;
- point2d.x = point2d_vec.at<double>(0) / point2d_vec.at<double>(2);
- point2d.y = point2d_vec.at<double>(1) / point2d_vec.at<double>(2);
+ point2d.x = (float)(point2d_vec.at<double>(0) / point2d_vec.at<double>(2));
+ point2d.y = (float)(point2d_vec.at<double>(1) / point2d_vec.at<double>(2));
return point2d;
}
bool estimatePose(const std::vector<cv::Point3f> &list_points3d, const std::vector<cv::Point2f> &list_points2d, int flags);
void estimatePoseRANSAC( const std::vector<cv::Point3f> &list_points3d, const std::vector<cv::Point2f> &list_points2d,
int flags, cv::Mat &inliers,
- int iterationsCount, float reprojectionError, float confidence );
+ int iterationsCount, float reprojectionError, double confidence );
cv::Mat get_A_matrix() const { return _A_matrix; }
cv::Mat get_R_matrix() const { return _R_matrix; }
// For text
int fontFace = cv::FONT_ITALIC;
double fontScale = 0.75;
-double thickness_font = 2;
+int thickness_font = 2;
// For circles
int lineType = 8;
// RANSAC parameters
int iterationsCount = 500; // number of Ransac iterations.
float reprojectionError = 2.0; // maximum allowed distance to consider it an inlier.
-float confidence = 0.95; // ransac successful confidence.
+double confidence = 0.95; // ransac successful confidence.
// Kalman Filter parameters
int minInliersKalman = 30; // Kalman threshold updating
drawObjectMesh(frame_vis, &mesh, &pnp_detection_est, yellow); // draw estimated pose
}
- double l = 5;
+ float l = 5;
std::vector<cv::Point2f> pose_points2d;
pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(0,0,0))); // axis center
pose_points2d.push_back(pnp_detection_est.backproject3DPoint(cv::Point3f(l,0,0))); // axis x
// Draw some debug text
int inliers_int = inliers_idx.rows;
- int outliers_int = good_matches.size() - inliers_int;
+ int outliers_int = (int)good_matches.size() - inliers_int;
std::string inliers_str = IntToString(inliers_int);
std::string outliers_str = IntToString(outliers_int);
- std::string n = IntToString(good_matches.size());
+ std::string n = IntToString((int)good_matches.size());
std::string text = "Found " + inliers_str + " of " + n + " matches";
std::string text2 = "Inliers: " + inliers_str + " - Outliers: " + outliers_str;
int n_regist = registration.getNumRegist();
int n_vertex = pts[n_regist];
- cv::Point2f point_2d = cv::Point2f(x,y);
+ cv::Point2f point_2d = cv::Point2f((float)x,(float)y);
cv::Point3f point_3d = mesh.getVertex(n_vertex-1);
bool is_registrable = registration.is_registrable();
std::vector<cv::Point2f> list_points_out = model.get_points2d_out();
// Draw some debug text
- std::string num = IntToString(list_points_in.size());
+ std::string num = IntToString((int)list_points_in.size());
std::string text = "There are " + num + " inliers";
drawText(img_vis, text, green);
// Draw some debug text
- num = IntToString(list_points_out.size());
+ num = IntToString((int)list_points_out.size());
text = "There are " + num + " outliers";
drawText2(img_vis, text, red);