| 586 | } |
| 587 | |
| 588 | bool Frame::ProjectPointDistort(MapPoint* pMP, cv::Point2f &kp, float &u, float &v) |
| 589 | { |
| 590 | |
| 591 | // 3D in absolute coordinates |
| 592 | Eigen::Vector3f P = pMP->GetWorldPos(); |
| 593 | |
| 594 | // 3D in camera coordinates |
| 595 | const Eigen::Vector3f Pc = mRcw * P + mtcw; |
| 596 | const float &PcX = Pc(0); |
| 597 | const float &PcY= Pc(1); |
| 598 | const float &PcZ = Pc(2); |
| 599 | |
| 600 | // Check positive depth |
| 601 | if(PcZ<0.0f) |
| 602 | { |
| 603 | cout << "Negative depth: " << PcZ << endl; |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | // Project in image and check it is not outside |
| 608 | const float invz = 1.0f/PcZ; |
| 609 | u=fx*PcX*invz+cx; |
| 610 | v=fy*PcY*invz+cy; |
| 611 | |
| 612 | if(u<mnMinX || u>mnMaxX) |
| 613 | return false; |
| 614 | if(v<mnMinY || v>mnMaxY) |
| 615 | return false; |
| 616 | |
| 617 | float u_distort, v_distort; |
| 618 | |
| 619 | float x = (u - cx) * invfx; |
| 620 | float y = (v - cy) * invfy; |
| 621 | float r2 = x * x + y * y; |
| 622 | float k1 = mDistCoef.at<float>(0); |
| 623 | float k2 = mDistCoef.at<float>(1); |
| 624 | float p1 = mDistCoef.at<float>(2); |
| 625 | float p2 = mDistCoef.at<float>(3); |
| 626 | float k3 = 0; |
| 627 | if(mDistCoef.total() == 5) |
| 628 | { |
| 629 | k3 = mDistCoef.at<float>(4); |
| 630 | } |
| 631 | |
| 632 | // Radial distorsion |
| 633 | float x_distort = x * (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2); |
| 634 | float y_distort = y * (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2); |
| 635 | |
| 636 | // Tangential distorsion |
| 637 | x_distort = x_distort + (2 * p1 * x * y + p2 * (r2 + 2 * x * x)); |
| 638 | y_distort = y_distort + (p1 * (r2 + 2 * y * y) + 2 * p2 * x * y); |
| 639 | |
| 640 | u_distort = x_distort * fx + cx; |
| 641 | v_distort = y_distort * fy + cy; |
| 642 | |
| 643 | |
| 644 | u = u_distort; |
| 645 | v = v_distort; |
nothing calls this directly
no test coverage detected