ros-perception / vision_opencv

Apache License 2.0
536 stars 599 forks source link

image_geometry/cameramodels.py uses deprecated numpy.matrix subclass #524

Closed ScottMonaghan closed 2 months ago

ScottMonaghan commented 3 months ago

[!NOTE] I revised this issue with corrections and for clarity after I completed a close-reading of the ROS 2 Developer Guide,

I'd be happy to try to tackle solving and creating a PR for this issue, but I have some questions before I proceed.

Background

This issue arises from PendingDeprecationWarning reported in ros-perception/image_pipeline issue #572.

Issue Summary

image_geometry/cameramodels.py uses deprecated numpy.matrix subclass causing runtime PendingDeprecationWarning.

The use of numpy.matrix should be deprecated and/or replaced.

Details

PinholeCamera's nominally private members--K, D,R,P,full_K, and full_P are initialized as deprecated numpy.matrix objects (see below).

https://github.com/ros-perception/vision_opencv/blob/8b42d66f4946f4204387b30aabc8c2921e5d9f47/image_geometry/image_geometry/cameramodels.py#L6-L9

...

https://github.com/ros-perception/vision_opencv/blob/8b42d66f4946f4204387b30aabc8c2921e5d9f47/image_geometry/image_geometry/cameramodels.py#L32-L47

This will cause the warning during initialization every time the public API members below are called:

The following public members of PinholeCameraModel currently have a return type of numpy.matrix

Suggested Acceptance Criteria for fix

[!NOTE] Updated 4/5/2024 based on feedback from @ijnek.

I'd like to do all these, but I've categorized them in order of priority: MUST HAVE, SHOULD HAVE, NICE TO HAVE.

MUST HAVE

SHOULD HAVE

NICE TO HAVE

@ijnek , I'm interested in your thoughts on the above. I'll take guidance from you on whether to do some all or none of the above. This would be my first ROS 2 contribution, so I'm excited to give this a shot.

ijnek commented 3 months ago

Hi @ScottMonaghan, sorry for the late reply and thanks for the nicely written issue.

Everything in general looks good, strategies for preventing API breakage are good too. Please use DeprecationWarning instead of PendingDeprecationWarning. Let's aim to deprecate in ROS 2 Jazzy, and completely remove in ROS 2 K-turtle.

To maintain functionality of deprecated API, I suggest updating underlying numpy data structure, and do a conversion to numpy.matrix upon request. The new methods can have the same name, but using snake case instead of camel case. Please add a note in the deprecation warning saying that the returned numpy data type of the new method is different.

ScottMonaghan commented 3 months ago

@ijnek, no problem with the delay. This past week was an object lesson in why we all need to treat our volunteer FOSS maintainers with gratitude.

Regarding time, I'm going to target getting a PR submitted by end of April;

Please let me know if that's too far out.

ScottMonaghan commented 2 months ago

@ijnek, with the merging of PR #527, this issue should be able to be closed.