| 555 | } |
| 556 | |
| 557 | std::list<orb_extractor_node> orb_extractor::initialize_nodes(const std::vector<cv::KeyPoint> &keypts_to_distribute, |
| 558 | const int min_x, const int max_x, const int min_y, const int max_y) const |
| 559 | { |
| 560 | // The aspect ratio of the target area for keypoint detection |
| 561 | const auto ratio = static_cast<double>(max_x - min_x) / (max_y - min_y); |
| 562 | // The width and height of the patches allocated to the initial node |
| 563 | double delta_x, delta_y; |
| 564 | // The number of columns or rows |
| 565 | unsigned int num_x_grid, num_y_grid; |
| 566 | |
| 567 | if (ratio > 1) |
| 568 | { |
| 569 | // If the aspect ratio is greater than 1, the patches are made in a horizontal direction |
| 570 | num_x_grid = std::round(ratio); |
| 571 | num_y_grid = 1; |
| 572 | delta_x = static_cast<double>(max_x - min_x) / num_x_grid; |
| 573 | delta_y = max_y - min_y; |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | // If the aspect ratio is equal to or less than 1, the patches are made in a vertical direction |
| 578 | num_x_grid = 1; |
| 579 | num_y_grid = std::round(1 / ratio); |
| 580 | delta_x = max_x - min_y; |
| 581 | delta_y = static_cast<double>(max_y - min_y) / num_y_grid; |
| 582 | } |
| 583 | |
| 584 | // The number of the initial nodes |
| 585 | const unsigned int num_initial_nodes = num_x_grid * num_y_grid; |
| 586 | |
| 587 | // A list of node |
| 588 | std::list<orb_extractor_node> nodes; |
| 589 | |
| 590 | // Initial node objects |
| 591 | std::vector<orb_extractor_node *> initial_nodes; |
| 592 | initial_nodes.resize(num_initial_nodes); |
| 593 | |
| 594 | // Create initial node substances |
| 595 | for (unsigned int i = 0; i < num_initial_nodes; ++i) |
| 596 | { |
| 597 | orb_extractor_node node; |
| 598 | |
| 599 | // x / y index of the node's patch in the grid |
| 600 | const unsigned int ix = i % num_x_grid; |
| 601 | const unsigned int iy = i / num_x_grid; |
| 602 | |
| 603 | node.pt_begin_ = cv::Point2i(delta_x * ix, delta_y * iy); |
| 604 | node.pt_end_ = cv::Point2i(delta_x * (ix + 1), delta_y * (iy + 1)); |
| 605 | node.keypts_.reserve(keypts_to_distribute.size()); |
| 606 | |
| 607 | nodes.push_back(node); |
| 608 | initial_nodes.at(i) = &nodes.back(); |
| 609 | } |
| 610 | |
| 611 | // Assign all keypoints to initial nodes which own keypoint's position |
| 612 | for (const auto &keypt : keypts_to_distribute) |
| 613 | { |
| 614 | // x / y index of the patch where the keypt is placed |