Skip to content

Commit d27931a

Browse files
authored
Merge pull request #24 from zz990099/develop_support_multi_iteration_refinement
Support multi iteration refinement
2 parents 05df195 + 5b0904e commit d27931a

8 files changed

Lines changed: 99 additions & 136 deletions

File tree

detection_6d_foundationpose/include/detection_6d_foundationpose/foundationpose.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ class Base6DofDetectionModel {
2929
* @param mask Object mask (CV_8UC1 format, positive pixels > 0)
3030
* @param target_name Object category name (must match construction mapping)
3131
* @param out_pose_in_mesh Output pose in mesh coordinate frame
32+
* @param refine_itr Refinement process iteration num
3233
* @return true Registration successful
3334
* @return false Registration failed
3435
*/
3536
virtual bool Register(const cv::Mat &rgb,
3637
const cv::Mat &depth,
3738
const cv::Mat &mask,
3839
const std::string &target_name,
39-
Eigen::Matrix4f &out_pose_in_mesh) = 0;
40+
Eigen::Matrix4f &out_pose_in_mesh,
41+
size_t refine_itr = 1) = 0;
4042

4143
/**
4244
* @brief Track object pose from subsequent frames (lightweight version of Register)
@@ -50,14 +52,16 @@ class Base6DofDetectionModel {
5052
* @param hyp_pose_in_mesh Hypothesis pose in mesh frame (from Register or other sources)
5153
* @param target_name Object category name (must match construction mapping)
5254
* @param out_pose_in_mesh Output pose in mesh coordinate frame
55+
* @param refine_itr Refinement process iteration num
5356
* @return true Tracking successful
5457
* @return false Tracking failed
5558
*/
5659
virtual bool Track(const cv::Mat &rgb,
5760
const cv::Mat &depth,
5861
const Eigen::Matrix4f &hyp_pose_in_mesh,
5962
const std::string &target_name,
60-
Eigen::Matrix4f &out_pose_in_mesh) = 0;
63+
Eigen::Matrix4f &out_pose_in_mesh,
64+
size_t refine_itr = 1) = 0;
6165

6266
/**
6367
* @brief Virtual destructor for proper resource cleanup

detection_6d_foundationpose/src/foundationpose.cpp

Lines changed: 85 additions & 119 deletions
Large diffs are not rendered by default.

detection_6d_foundationpose/src/foundationpose_render.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,13 @@ void WrapFloatPtrToNHWCTensor(
220220
FoundationPoseRenderer::FoundationPoseRenderer(std::shared_ptr<BaseMeshLoader> mesh_loader,
221221
const Eigen::Matrix3f &intrinsic,
222222
const int input_poses_num,
223-
const float crop_ratio,
224223
const int crop_window_H,
225224
const int crop_window_W,
226225
const float min_depth,
227226
const float max_depth)
228227
: mesh_loader_(mesh_loader),
229228
intrinsic_(intrinsic),
230229
input_poses_num_(input_poses_num),
231-
crop_ratio_(crop_ratio),
232230
crop_window_H_(crop_window_H),
233231
crop_window_W_(crop_window_W),
234232
min_depth_(min_depth),
@@ -820,14 +818,15 @@ bool FoundationPoseRenderer::RenderAndTransform(const std::vector<Eigen::Matrix4
820818
int input_image_height,
821819
int input_image_width,
822820
void *render_buffer,
823-
void *transf_buffer)
821+
void *transf_buffer,
822+
float crop_ratio)
824823
{
825824
const int input_poses_num = _poses.size();
826825

827826
// 1. 根据目标位姿计算变换矩阵
828827
std::vector<Eigen::MatrixXf> poses(_poses.begin(), _poses.end());
829828
Eigen::Vector2i out_size = {crop_window_H_, crop_window_W_};
830-
auto tfs = ComputeCropWindowTF(poses, intrinsic_, out_size, crop_ratio_, mesh_diameter_);
829+
auto tfs = ComputeCropWindowTF(poses, intrinsic_, out_size, crop_ratio, mesh_diameter_);
831830
CHECK_STATE(tfs.size() != 0, "[FoundationposeRender] The transform matrix vector is empty");
832831

833832
// 2. 将输入的poses拷贝到device端

detection_6d_foundationpose/src/foundationpose_render.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ class FoundationPoseRenderer {
2121
FoundationPoseRenderer(std::shared_ptr<BaseMeshLoader> mesh_loader,
2222
const Eigen::Matrix3f &intrinsic,
2323
const int input_poses_num,
24-
const float crop_ratio = 1.2,
2524
const int crop_window_H = 160,
2625
const int crop_window_W = 160,
27-
const float min_depth = 0.1,
26+
const float min_depth = 0.001,
2827
const float max_depth = 4.0);
2928

3029
bool RenderAndTransform(const std::vector<Eigen::Matrix4f> &_poses,
@@ -34,7 +33,8 @@ class FoundationPoseRenderer {
3433
int input_image_height,
3534
int input_image_width,
3635
void *render_buffer,
37-
void *transf_buffer);
36+
void *transf_buffer,
37+
float crop_ratio);
3838

3939
~FoundationPoseRenderer();
4040

@@ -94,7 +94,6 @@ class FoundationPoseRenderer {
9494
// crop window size (model input size)
9595
const int crop_window_H_;
9696
const int crop_window_W_;
97-
const float crop_ratio_; // refine, score->1.1
9897
const Eigen::Matrix3f intrinsic_;
9998

10099
// depth threshold

detection_6d_foundationpose/src/foundationpose_sampling.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ bool GuessTranslation(const Eigen::MatrixXf &depth,
300300
FoundationPoseSampler::FoundationPoseSampler(const int max_input_image_H,
301301
const int max_input_image_W,
302302
const float min_depth,
303-
const float max_depth,
304303
const Eigen::Matrix3f &intrinsic)
305304
: max_input_image_H_(max_input_image_H),
306305
max_input_image_W_(max_input_image_W),

detection_6d_foundationpose/src/foundationpose_sampling.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class FoundationPoseSampler {
1313
FoundationPoseSampler(const int max_input_image_H,
1414
const int max_input_image_W,
1515
const float min_depth,
16-
const float max_depth,
1716
const Eigen::Matrix3f &intrinsic);
1817

1918
bool GetHypPoses(void *_depth_on_device,

detection_6d_foundationpose/src/foundationpose_utils.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ struct FoundationPosePipelinePackage : public async_pipeline::IPipelinePackage {
5454
std::shared_ptr<void> depth_on_device;
5555
// device端由depth转换得到的xyz_map
5656
std::shared_ptr<void> xyz_map_on_device;
57-
// device端的输入mask缓存
58-
// std::shared_ptr<void> mask_on_device;
5957
// 生成的假设位姿
6058
std::vector<Eigen::Matrix4f> hyp_poses;
61-
// refine后的位姿
62-
std::vector<Eigen::Matrix4f> refine_poses;
6359

6460
// 保存refine阶段用的推理缓存
6561
std::shared_ptr<inference_core::IBlobsBuffer> refiner_blobs_buffer;

simple_tests/src/test_foundationpose.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static const std::string demo_textured_obj_path = demo_data_path_ + "/mesh/textu
1717
static const std::string demo_textured_map_path = demo_data_path_ + "/mesh/texture_map.png";
1818
static const std::string demo_name_ = "mustard";
1919
static const std::string frame_id = "1581120424100262102";
20+
static const size_t refine_itr = 1;
2021

2122
std::tuple<std::shared_ptr<Base6DofDetectionModel>, std::shared_ptr<BaseMeshLoader>> CreateModel()
2223
{
@@ -58,7 +59,7 @@ TEST(foundationpose_test, test)
5859
const Eigen::Vector3f object_dimension = mesh_loader->GetObjectDimension();
5960

6061
Eigen::Matrix4f out_pose;
61-
CHECK(foundation_pose->Register(rgb.clone(), depth, mask, demo_name_, out_pose));
62+
CHECK(foundation_pose->Register(rgb.clone(), depth, mask, demo_name_, out_pose, refine_itr));
6263
LOG(WARNING) << "first Pose : " << out_pose;
6364

6465
// [temp] for test

0 commit comments

Comments
 (0)