Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify camera transformations with the new Frame3d-Feature from RoSys #152

Merged
merged 23 commits into from
Aug 28, 2024

Conversation

rodja
Copy link
Member

@rodja rodja commented Aug 13, 2024

Since the next RoSys release will fix zauberzeug/rosys#130, this PR utilizes the new Frame3d to get rid of hacks throughout the codebase. While at it, I fixed some typing issues, made some cleanups and extracted/renamed variables to improve readability and consistency.

NOTE: this branch does only work with the RoSys main line at the moment and should only be merged after RoSys 0.14.0 has been released.

ToDos

  • fix tests
  • wait for RoSys 0.14.0 and update requirements.txt
  • test camera card's tool augmentation and relevant weeds augmentation on real robot
  • test plant locator is proper functioning on real robot
  • review code
  • make sure we can load the old camera calibration configs

@rodja rodja added the enhancement New feature or request label Aug 13, 2024
@rodja rodja added this to the 0.3.0 milestone Aug 13, 2024
@rodja rodja marked this pull request as draft August 13, 2024 07:35
@rodja
Copy link
Member Author

rodja commented Aug 14, 2024

I fixed the test_follow_crops_outlier test by increasing the error margin from 1° to 2°. The introduction of the Frame3d seems to skew the orientation a bit different than before. To verify that 2° of error is still ok, I added multiple outliers to the follow crops simulation which looks quite good to me.

@rodja
Copy link
Member Author

rodja commented Aug 14, 2024

@pascalzauberzeug or @angelom93: you can review and test the code already (with rosys main branch). That way we could merge as soon as the 0.14.0 version of RoSys get's released.

@pascalzauberzeug
Copy link
Contributor

@rodja I already checked the code, but don't have time to test it on a robot until tuesday
@angelom93 you can test it if you find the time, otherwise I will do it on tuesday

@pascalzauberzeug
Copy link
Contributor

I have updated rosys to v0.14.0 and merged main into this branch.
We have to push this forward tomorrow, because #149 depends on v0.14.0 and needs this PR for it to work

@pascalzauberzeug pascalzauberzeug mentioned this pull request Aug 19, 2024
@angelom93
Copy link
Contributor

angelom93 commented Aug 22, 2024

@rodja @pascalzauberzeug I tried to get this PR working on a real robot. After fixing some issues with the calibration dialog and camera card, I encountered a bigger problem. In line 210 of camera_card.py, we try to get the image position of the world coordinates, including the odometer position of the robot:

tool_3d = self.odometer.prediction.point_3d() + \
            rosys.geometry.Point3d(x=self.field_friend.WORK_X, y=self.field_friend.y_axis.position, z=0)
tool_2d = self.camera.calibration.project_to_image(tool_3d) / self.shrink_factor

I think we need to pass the robot’s pose as frame parameter. As the calibration itself doesn´t know the current frame of the camera. The same issue occurs in the plant_locator in the other direction.

image_point = rosys.geometry.Point(x=d.cx, y=d.cy)
world_point_3d = camera.calibration.project_from_image(image_point)

Additionally, there was a problem with the old calibration on the robot, as it seems to be incompatible with the new code. Upgrading would require us to either recalibrate all robots or create a calibration import method.

@rodja
Copy link
Member Author

rodja commented Aug 22, 2024

@angelom93 Wow. Thanks for uncovering these issues. Let's dive in:

I think we need to pass the robot’s pose as frame parameter. As the calibration itself doesn´t know the current frame of the camera.

The camera pose should have already a associated frame which automatically should be used when doing the projection. At least that was true when testing in simulation. Maybe the frame is not set correctly on a real robot?
With your changes in ca81e46795f55 the tool display in the camera does not work anymore in the simulation.

Additionally, there was a problem with the old calibration on the robot, as it seems to be incompatible with the new code. Upgrading would require us to either recalibrate all robots or create a calibration import method.

That is problematic. How much effort would it be to write such a calibration import step? Maybe that is better than recalibrating every robot?

@pascalzauberzeug
Copy link
Contributor

@rodja I don't have a new calibration file on hand, but I think it shouldn't be too hard to write a converter. When looking at calibration in 0.14.0, extrinsics is a Pose3D and before it was it's own class.
I think this should be the main difference

@pascalzauberzeug
Copy link
Contributor

Here is an example of a broken calibration from F13/RB36

cat field_friend.vision.calibratable_usb_camera_provider.json

{
    "cameras": {
        "32e4-9230-platform-3610000.xhci-usb-0:2.4:1.0": {
            "id": "32e4-9230-platform-3610000.xhci-usb-0:2.4:1.0",
            "name": "32e4-9230-platform-3610000.xhci-usb-0:2.4:1.0",
            "connect_after_init": true,
            "streaming": false,
            "focal_length": 1830,
            "calibration": {
                "intrinsics": {
                    "model": "pinhole",
                    "matrix": [
                        [
                            704.3472414299275,
                            0.0,
                            515.2572427719205
                        ],
                        [
                            0.0,
                            709.5225125575603,
                            329.3347043150279
                        ],
                        [
                            0.0,
                            0.0,
                            1.0
                        ]
                    ],
                    "distortion": [
                        -0.42323083237038744,
                        0.24994860543758948,
                        -0.0016619969416450243,
                        -7.288107826439712e-05,
                        -0.07725206082664601
                    ],
                    "xi": 0.0,
                    "rotation": {
                        "R": [
                            [
                                1,
                                0,
                                0
                            ],
                            [
                                0,
                                1,
                                0
                            ],
                            [
                                0,
                                0,
                                1
                            ]
                        ]
                    },
                    "size": {
                        "width": 1020,
                        "height": 700
                    }
                },
                "extrinsics": {
                    "rotation": {
                        "R": [
                            [
                                0.0012156952531017229,
                                0.8037678718850602,
                                -0.5949417872451164
                            ],
                            [
                                0.9999974845579332,
                                -0.0020985613297158645,
                                -0.0007917816314380813
                            ],
                            [
                                -0.001884930465043511,
                                -0.5949393281383465,
                                -0.8037684012645899
                            ]
                        ]
                    },
                    "translation": [
                        0.0,
                        0.0,
                        1.0
                    ]
                }
            },
            "auto_exposure": true,
            "exposure": false,
            "width": 1280,
            "height": 720,
            "fps": 9
        },
        "32e4-9230-platform-3610000.xhci-usb-0:2.3:1.0": {
            "id": "32e4-9230-platform-3610000.xhci-usb-0:2.3:1.0",
            "name": "32e4-9230-platform-3610000.xhci-usb-0:2.3:1.0",
            "connect_after_init": true,
            "streaming": true,
            "focal_length": 1830,
            "calibration": {
                "intrinsics": {
                    "model": "pinhole",
                    "matrix": [
                        [
                            704.3472414299275,
                            0.0,
                            515.2572427719205
                        ],
                        [
                            0.0,
                            709.5225125575603,
                            329.3347043150279
                        ],
                        [
                            0.0,
                            0.0,
                            1.0
                        ]
                    ],
                    "distortion": [
                        -0.42323083237038744,
                        0.24994860543758948,
                        -0.0016619969416450243,
                        -7.288107826439712e-05,
                        -0.07725206082664601
                    ],
                    "xi": 0.0,
                    "rotation": {
                        "R": [
                            [
                                1,
                                0,
                                0
                            ],
                            [
                                0,
                                1,
                                0
                            ],
                            [
                                0,
                                0,
                                1
                            ]
                        ]
                    },
                    "size": {
                        "width": 1020,
                        "height": 700
                    }
                },
                "extrinsics": {
                    "rotation": {
                        "R": [
                            [
                                0.0012156952531017229,
                                0.8037678718850602,
                                -0.5949417872451164
                            ],
                            [
                                0.9999974845579332,
                                -0.0020985613297158645,
                                -0.0007917816314380813
                            ],
                            [
                                -0.001884930465043511,
                                -0.5949393281383465,
                                -0.8037684012645899
                            ]
                        ]
                    },
                    "translation": [
                        0.0,
                        0.0,
                        1.0
                    ]
                }
            },
            "auto_exposure": true,
            "exposure": false,
            "width": 1280,
            "height": 720,
            "fps": 9
        }
    }
}

@pascalzauberzeug
Copy link
Contributor

@rodja The camera and projection movement are now fixed for the 3dScene with zauberzeug/rosys#183.
It still needs to be tested on a real robot and the implement projection of the camera card is still broken, but @angelom93 and I think that the camera card should be adressed in another PR to get this one merged

@rodja
Copy link
Member Author

rodja commented Aug 28, 2024

Sounds good to me!

@rodja rodja marked this pull request as ready for review August 28, 2024 07:10
@pascalzauberzeug pascalzauberzeug merged commit ac7f164 into main Aug 28, 2024
1 check passed
@pascalzauberzeug pascalzauberzeug deleted the camera branch August 28, 2024 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants