1480 markerCameraIntrinsic,
1489 cv::Mat ul = cv::Mat(cv::Point3f(0, 0, 1));
1490 cv::Mat ur = cv::Mat(cv::Point3f((
float)markerFrame.
imgGray.cols, 0, 1));
1491 cv::Mat ll = cv::Mat(cv::Point3f(0, (
float)markerFrame.
imgGray.rows, 1));
1492 cv::Mat lr = cv::Mat(cv::Point3f((
float)markerFrame.
imgGray.cols, (
float)markerFrame.
imgGray.rows, 1));
1494 cv::Mat ulKf1, urKf1, llKf1, lrKf1, ulKf2, urKf2, llKf2, lrKf2;
1495 cv::Mat ul3D, ur3D, ll3D, lr3D;
1498 for (
int i1 = 0; i1 < kfs.size() - 1; i1++)
1502 if (kfCand1->
isBad())
continue;
1505 cv::Mat homography1;
1511 ulKf1 = homography1 * ul;
1512 ulKf1 /= ulKf1.at<
float>(2, 0);
1513 urKf1 = homography1 * ur;
1514 urKf1 /= urKf1.at<
float>(2, 0);
1515 llKf1 = homography1 * ll;
1516 llKf1 /= llKf1.at<
float>(2, 0);
1517 lrKf1 = homography1 * lr;
1518 lrKf1 /= lrKf1.at<
float>(2, 0);
1520 for (
int i2 = i1 + 1; i2 < kfs.size(); i2++)
1524 if (kfCand2->
isBad())
continue;
1526 cv::Mat homography2;
1532 ulKf2 = homography2 * ul;
1533 ulKf2 /= ulKf2.at<
float>(2, 0);
1534 urKf2 = homography2 * ur;
1535 urKf2 /= urKf2.at<
float>(2, 0);
1536 llKf2 = homography2 * ll;
1537 llKf2 /= llKf2.at<
float>(2, 0);
1538 lrKf2 = homography2 * lr;
1539 lrKf2 /= lrKf2.at<
float>(2, 0);
1543 cv::Mat Rwc1 = Rcw1.t();
1545 cv::Mat Tcw1(3, 4, CV_32F);
1546 Rcw1.copyTo(Tcw1.colRange(0, 3));
1547 tcw1.copyTo(Tcw1.col(3));
1549 const float& fx1 = kfCand1->
fx;
1550 const float& fy1 = kfCand1->
fy;
1551 const float& cx1 = kfCand1->
cx;
1552 const float& cy1 = kfCand1->
cy;
1553 const float& invfx1 = kfCand1->
invfx;
1554 const float& invfy1 = kfCand1->
invfy;
1557 cv::Mat Rwc2 = Rcw2.t();
1559 cv::Mat Tcw2(3, 4, CV_32F);
1560 Rcw2.copyTo(Tcw2.colRange(0, 3));
1561 tcw2.copyTo(Tcw2.col(3));
1563 const float& fx2 = kfCand2->
fx;
1564 const float& fy2 = kfCand2->
fy;
1565 const float& cx2 = kfCand2->
cx;
1566 const float& cy2 = kfCand2->
cy;
1567 const float& invfx2 = kfCand2->
invfx;
1568 const float& invfy2 = kfCand2->
invfy;
1571 cv::Mat ul1 = (cv::Mat_<float>(3, 1) << (ulKf1.at<
float>(0, 0) - cx1) * invfx1, (ulKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
1572 cv::Mat ul2 = (cv::Mat_<float>(3, 1) << (ulKf2.at<
float>(0, 0) - cx2) * invfx2, (ulKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
1575 cv::Mat A(4, 4, CV_32F);
1576 A.row(0) = ul1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
1577 A.row(1) = ul1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
1578 A.row(2) = ul2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
1579 A.row(3) = ul2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
1582 cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
1584 ul3D = vt.row(3).t();
1586 if (ul3D.at<
float>(3) != 0)
1589 ul3D = ul3D.rowRange(0, 3) / ul3D.at<
float>(3);
1594 cv::Mat ur1 = (cv::Mat_<float>(3, 1) << (urKf1.at<
float>(0, 0) - cx1) * invfx1, (urKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
1595 cv::Mat ur2 = (cv::Mat_<float>(3, 1) << (urKf2.at<
float>(0, 0) - cx2) * invfx2, (urKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
1598 cv::Mat A(4, 4, CV_32F);
1599 A.row(0) = ur1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
1600 A.row(1) = ur1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
1601 A.row(2) = ur2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
1602 A.row(3) = ur2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
1605 cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
1607 ur3D = vt.row(3).t();
1609 if (ur3D.at<
float>(3) != 0)
1612 ur3D = ur3D.rowRange(0, 3) / ur3D.at<
float>(3);
1617 cv::Mat ll1 = (cv::Mat_<float>(3, 1) << (llKf1.at<
float>(0, 0) - cx1) * invfx1, (llKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
1618 cv::Mat ll2 = (cv::Mat_<float>(3, 1) << (llKf2.at<
float>(0, 0) - cx2) * invfx2, (llKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
1621 cv::Mat A(4, 4, CV_32F);
1622 A.row(0) = ll1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
1623 A.row(1) = ll1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
1624 A.row(2) = ll2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
1625 A.row(3) = ll2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
1628 cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
1630 ll3D = vt.row(3).t();
1632 if (ll3D.at<
float>(3) != 0)
1635 ll3D = ll3D.rowRange(0, 3) / ll3D.at<
float>(3);
1640 cv::Mat lr1 = (cv::Mat_<float>(3, 1) << (lrKf1.at<
float>(0, 0) - cx1) * invfx1, (lrKf1.at<
float>(1, 0) - cy1) * invfy1, 1.0);
1641 cv::Mat lr2 = (cv::Mat_<float>(3, 1) << (lrKf2.at<
float>(0, 0) - cx2) * invfx2, (lrKf2.at<
float>(1, 0) - cy2) * invfy2, 1.0);
1644 cv::Mat A(4, 4, CV_32F);
1645 A.row(0) = lr1.at<
float>(0) * Tcw1.row(2) - Tcw1.row(0);
1646 A.row(1) = lr1.at<
float>(1) * Tcw1.row(2) - Tcw1.row(1);
1647 A.row(2) = lr2.at<
float>(0) * Tcw2.row(2) - Tcw2.row(0);
1648 A.row(3) = lr2.at<
float>(1) * Tcw2.row(2) - Tcw2.row(1);
1651 cv::SVD::compute(A, w, u, vt, cv::SVD::MODIFY_A | cv::SVD::FULL_UV);
1653 lr3D = vt.row(3).t();
1655 if (lr3D.at<
float>(3) != 0)
1658 lr3D = lr3D.rowRange(0, 3) / lr3D.at<
float>(3);
1668 cv::Vec3f vn = vAB.cross(vAC);
1671 cv::Mat AD = lr3D - ul3D;
1674 float d = (float)cv::norm(vn.dot(vAD)) / (
float)cv::norm(vn);
1677 matchedKf1 = kfCand1;
1678 matchedKf2 = kfCand2;
1686 if (matchedKf2)
break;
1689 if (!matchedKf1 || !matchedKf2)
1697 cv::Mat system = cv::Mat::zeros(3, 3, CV_32F);
1698 AC.copyTo(system.rowRange(0, 3).col(0));
1699 AB.copyTo(system.rowRange(0, 3).col(1));
1700 n.copyTo(system.rowRange(0, 3).col(2));
1702 cv::Mat systemInv = system.inv();
1704 for (
int i = 0; i < mapPoints.size(); i++)
1708 if (mp->
isBad())
continue;
1710 cv::Mat sol = systemInv * (mp->
GetWorldPos() - ul3D);
1712 if (sol.at<
float>(0, 0) < 0 || sol.at<
float>(0, 0) > 1 ||
1713 sol.at<
float>(1, 0) < 0 || sol.at<
float>(1, 0) > 1 ||
1714 sol.at<
float>(2, 0) < -0.1f || sol.at<
float>(2, 0) > 0.1f)
1720 for (
int i = 0; i < kfs.size(); i++)
1724 if (kf->
mnId == 0 || kf->
isBad())
continue;
1729 for (
int j = 0; j < mps.size(); j++)
1733 if (!mp || mp->
isBad())
continue;
1744 cv::Mat systemNorm = cv::Mat::zeros(3, 3, CV_32F);
1745 systemNorm.rowRange(0, 3).col(0) = system.rowRange(0, 3).col(1) / cv::norm(AB);
1746 systemNorm.rowRange(0, 3).col(1) = system.rowRange(0, 3).col(0) / cv::norm(AC);
1747 systemNorm.rowRange(0, 3).col(2) = system.rowRange(0, 3).col(2) / cv::norm(n);
1749 cv::Mat systemNormInv = systemNorm.inv();
1751 nodeTransform = cv::Mat::eye(4, 4, CV_32F);
1752 cv::Mat ul3Dinv = -systemNormInv * ul3D;
1753 ul3Dinv.copyTo(nodeTransform.rowRange(0, 3).col(3));
1754 systemNormInv.copyTo(nodeTransform.rowRange(0, 3).colRange(0, 3));
1756 cv::Mat scaleMat = cv::Mat::eye(4, 4, CV_32F);
1757 float markerWidthInRef = (float)cv::norm(ul3D - ur3D);
1758 float scaleFactor = markerWidthInM / markerWidthInRef;
1759 scaleMat.at<
float>(0, 0) = scaleFactor;
1760 scaleMat.at<
float>(1, 1) = scaleFactor;
1761 scaleMat.at<
float>(2, 2) = scaleFactor;
1763 nodeTransform = scaleMat * nodeTransform;
std::vector< WAIMapPoint * > GetMapPointMatches()
std::vector< WAIMapPoint * > GetAllMapPoints()