Skip to content

[RSDK-12054] Including distortion parameters in get_properties response#52

Merged
SebastianMunozP merged 4 commits intoviam-modules:mainfrom
SebastianMunozP:send_distortion_parameters_in_get_properties_function
Oct 3, 2025
Merged

[RSDK-12054] Including distortion parameters in get_properties response#52
SebastianMunozP merged 4 commits intoviam-modules:mainfrom
SebastianMunozP:send_distortion_parameters_in_get_properties_function

Conversation

@SebastianMunozP
Copy link
Contributor

@SebastianMunozP SebastianMunozP commented Oct 3, 2025

This is needed for the openCV version of the FrameCalibration module.
But in general, we should always be populating this data.

Note that the distortion parameters, as well as the intrinsic ones, have names, but the distortion_parameters interface only accepts a vector of doubles, so we must make an implicit agreement on what each value means, this should definitely be fixed, but it's not the scope of this PR

Tested adding a debug do_command, we can keep it if we think it's valuable to have these kinds of commands, or I can remove it

Input:

{
"call_get_properties": null
}

Output:

{
  "intrinsic_parameters": {
    "focal_x_px": 1255.5146484375,
    "focal_y_px": 1255.356689453125,
    "center_x_px": 977.0808715820312,
    "center_y_px": 537.7965087890625,
    "height_px": 1080,
    "width_px": 1920
  },
  "distortion_parameters": {
    "parameters": [
      0.11218076944351196,
      -0.3130626380443573,
      0.23617683351039886,
      0,
      0,
      0,
      0.0001295953115914017,
      -0.0002027312875725329
    ],
    "model": "BROWN_CONRADY_K6"
  },
  "supports_pcd": true
}

p.distortion_parameters.model = "BROWN_CONRADY_K6";
break;
case OB_DISTORTION_KANNALA_BRANDT4:
p.distortion_parameters.model = "KANNALA_BRANDT4";
Copy link
Collaborator

@hexbabe hexbabe Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we getting these strings from? If the orbbec sdk exposes them as enums/string consts, could we import them instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrbbecSDK only expose these models as a enum, they provide a way to convert some of its enums to strings, but not for these enums in particular

Comment on lines +1470 to +1492
if (call_get_properties) {
VIAM_SDK_LOG(info) << "[do_command] calling get_properties";
auto const props = get_properties();
VIAM_SDK_LOG(info) << "[do_command] get_properties called";
vsdk::ProtoStruct resp;
resp["supports_pcd"] = props.supports_pcd;
resp["intrinsic_parameters"] = vsdk::ProtoStruct{{"width_px", props.intrinsic_parameters.width_px},
{"height_px", props.intrinsic_parameters.height_px},
{"focal_x_px", props.intrinsic_parameters.focal_x_px},
{"focal_y_px", props.intrinsic_parameters.focal_y_px},
{"center_x_px", props.intrinsic_parameters.center_x_px},
{"center_y_px", props.intrinsic_parameters.center_y_px}};
vsdk::ProtoStruct distortion_params;
distortion_params["model"] = props.distortion_parameters.model;
std::vector<viam::sdk::ProtoValue> proto_params;
for (const auto& val : props.distortion_parameters.parameters) {
proto_params.emplace_back(val); // Each double becomes a ProtoValue
}
distortion_params["parameters"] = viam::sdk::ProtoValue(proto_params);
resp["distortion_parameters"] = distortion_params;
VIAM_SDK_LOG(info) << "[do_command] get_properties returning";
return resp;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. Why do we need this as a docommand route if get_properties exists as a method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted a easy way to iterate on calling get_properties and verify its output. I.e. that I could manually call it for these purposes.

We may not be interested in keeping this, in which case I can just delete it.

Comment on lines +1157 to +1164
p.distortion_parameters.parameters = std::vector<double>{distortion_props.k1,
distortion_props.k2,
distortion_props.k3,
distortion_props.k4,
distortion_props.k5,
distortion_props.k6,
distortion_props.p1,
distortion_props.p2};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the order these are returned in to k1, k2, p1, p2, k3, k4, k5, k6.

This is more in line with opencv standards https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html

Copy link
Collaborator

@hexbabe hexbabe Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also do we need to update the README to document which coefficient each element of this array represents, so users don't have to dive into code to find out? I know this is a high prio ask but may be nice if we have time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, this makes sense

@hexbabe hexbabe self-requested a review October 3, 2025 18:38
@SebastianMunozP SebastianMunozP merged commit c3f6476 into viam-modules:main Oct 3, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants