Skip to content

Commit a91185d

Browse files
committed
fixed garbage in cv::Mat
1 parent a1c926c commit a91185d

1 file changed

Lines changed: 6 additions & 28 deletions

File tree

hand_eye_calibration/include/hand_eye_calibration/calibrate_helpers.hpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -641,59 +641,43 @@ inline void findGripper2Base(const fs::path &datasetPath,
641641
Rs.reserve(poses.size());
642642
tvecs.reserve(poses.size());
643643

644-
Eigen::Matrix3d R_eigen;
645-
cv::Mat rvec;
646-
647644
for (const auto &pose : poses) {
645+
cv::Mat R_cv(3, 3, CV_64F);
646+
cv::Mat tvec = (cv::Mat_<double>(3, 1) << pose[0], pose[1], pose[2]);
648647
switch (*posesOption) {
649648
case (PosesOption::ROT_XYZW): {
650-
tvecs.emplace_back(
651-
std::initializer_list<double>{pose[0], pose[1], pose[2]});
652-
653649
Eigen::Quaterniond q;
654650

655651
q.x() = pose[3];
656652
q.y() = pose[4];
657653
q.z() = pose[5];
658654
q.w() = pose[6];
659655

660-
R_eigen = q.normalized().toRotationMatrix();
656+
Eigen::Matrix3d R_eigen = q.normalized().toRotationMatrix();
661657

662-
cv::Mat R_cv;
663658
cv::eigen2cv(R_eigen, R_cv);
664-
665-
Rs.emplace_back(R_cv);
666659
break;
667660
}
668661
case (PosesOption::ROT_WXYZ): {
669-
tvecs.emplace_back(
670-
std::initializer_list<double>{pose[0], pose[1], pose[2]});
671662
Eigen::Quaterniond q;
672663

673664
q.w() = pose[3];
674665
q.x() = pose[4];
675666
q.y() = pose[5];
676667
q.z() = pose[6];
677668

678-
R_eigen = q.normalized().toRotationMatrix();
669+
Eigen::Matrix3d R_eigen = q.normalized().toRotationMatrix();
679670

680-
cv::Mat R_cv;
681671
cv::eigen2cv(R_eigen, R_cv);
682-
683-
Rs.emplace_back(R_cv);
684672
break;
685673
}
686674
case (PosesOption::ROT_RPY_RAD): {
687-
tvecs.emplace_back(
688-
std::initializer_list<double>{pose[0], pose[1], pose[2]});
689-
690675
double roll = pose[3];
691676
double pitch = pose[4];
692677
double yaw = pose[5];
693678

694679
tf2::Matrix3x3 R_tf2;
695680
R_tf2.setEulerYPR(yaw, pitch, roll);
696-
cv::Mat R_cv(3, 3, CV_64F);
697681

698682
for (int32_t i = 0; i < R_cv.rows; ++i) {
699683
const tf2::Vector3 &row = R_tf2.getRow(i);
@@ -702,21 +686,15 @@ inline void findGripper2Base(const fs::path &datasetPath,
702686
R_cv.at<double>(i, 2) = row[2];
703687
}
704688

705-
Rs.emplace_back(R_cv);
706-
707689
break;
708690
}
709691
case (PosesOption::ROT_RPY_DEG): {
710-
tvecs.emplace_back(
711-
std::initializer_list<double>{pose[0], pose[1], pose[2]});
712-
713692
double roll = pose[3] * DEG2RAD;
714693
double pitch = pose[4] * DEG2RAD;
715694
double yaw = pose[5] * DEG2RAD;
716695

717696
tf2::Matrix3x3 R_tf2;
718697
R_tf2.setEulerYPR(yaw, pitch, roll);
719-
cv::Mat R_cv(3, 3, CV_64F);
720698

721699
for (int32_t i = 0; i < R_cv.rows; ++i) {
722700
const tf2::Vector3 &row = R_tf2.getRow(i);
@@ -725,14 +703,14 @@ inline void findGripper2Base(const fs::path &datasetPath,
725703
R_cv.at<double>(i, 2) = row[2];
726704
}
727705

728-
Rs.emplace_back(R_cv);
729-
730706
break;
731707
}
732708
case (PosesOption::JOINTS): {
733709
throw std::runtime_error("Not implemented!");
734710
}
735711
}
712+
Rs.emplace_back(R_cv);
713+
tvecs.emplace_back(tvec);
736714
}
737715
}
738716

0 commit comments

Comments
 (0)