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

[image_geometry] Migrated to ROS2 #260

Open
wants to merge 8 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions image_geometry/image_geometry/cameramodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def fromCameraInfo(self, msg):

Set the camera parameters from the :class:`sensor_msgs.msg.CameraInfo` message.
"""
self.K = mkmat(3, 3, msg.K)
if msg.D:
self.D = mkmat(len(msg.D), 1, msg.D)
self.K = mkmat(3, 3, msg.k)
if msg.d:
self.D = mkmat(len(msg.d), 1, msg.d)
else:
self.D = None
self.R = mkmat(3, 3, msg.R)
self.P = mkmat(3, 4, msg.P)
self.full_K = mkmat(3, 3, msg.K)
self.full_P = mkmat(3, 4, msg.P)
self.R = mkmat(3, 3, msg.r)
self.P = mkmat(3, 4, msg.p)
self.full_K = mkmat(3, 3, msg.k)
self.full_P = mkmat(3, 4, msg.p)
self.width = msg.width
self.height = msg.height
self.binning_x = max(1, msg.binning_x)
Expand Down
3 changes: 3 additions & 0 deletions image_geometry/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>

<doc_depend>dvipng</doc_depend>
<doc_depend>texlive-latex-extra</doc_depend>
Expand Down
55 changes: 55 additions & 0 deletions image_geometry/ros2_image_geometry_migration_readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

**This file describes work done and steps to perform test on the image_geometry package for ROS2 (Bouncy & Crystal).**

**Overview:**

image_geometry is a package for interpreting images geometrically.

**List of changes from ROS1 to ROS2:**

The changes has been done by following the Migration guide for ROS2( https://index.ros.org/doc/ros2/Migration-Guide/ ).

1. Migrated directed.py python tests to ROS2
2. Enabled pytests in image_geometry package.
3. Migrated cameramodels.py, directed.py, CMakelists.txt & package.xml files for ROS2.
4. Merged Approved changes from PR #257.
5. Followed cosmetics rules and updated the files with copyright, pep257 and flake8 rules.

**Pre-requisites:**

1. System should have installed Crystal/Bouncy distro. Check out installation instructions and tutorials https://index.ros.org/doc/ros2/.
2. System should have checkout ros2 vision_opencv pkg & build (Refer Steps below).

Steps to checkout vision_opencv package:
1. Open the new terminal and run below commands.
2. mkdir -p vision_opencv_ws/src
3. cd ~/vision_opencv_ws/src
4. git clone [email protected]:akhileshmoghe/vision_opencv.git
#git branch -ra //This command will show different branches of main git on #kinetic
5. cd vision_opencv/
6. git checkout -b ros2-devel remotes/origin/ros2-devel

Steps to Build vision_opencv package:
1. cd ~/vision_opencv_ws/
2. for Crystal:
source /opt/ros/crystal/setup.bash
for Bouncy:
source /opt/ros/bouncy/setup.bash
3. cd ~/vision_opencv_ws/src/vision_opencv
4. colcon build

4. System should have both ROS1 & ROS2. Note: We have verified on ROS1(i.e. melodic) & ROS2 (i.e. Bouncy & Crystal).


**Future Work:-**

1. Make Cpp code for image_geometry package to be completely cosmetic rules compliant.


**TESTING:-**

Run the test cases as follows:-
cd ~/vision_opencv_ws_crystal/src/vision_opencv/
colcon test


10 changes: 8 additions & 2 deletions image_geometry/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
find_package(ament_cmake_gtest REQUIRED)
# TODO(mikaelarguedas) Reenable this when tests are ported to ROS 2
# find_package(ament_cmake_pytest REQUIRED)
find_package(ament_cmake_pytest REQUIRED)
find_package(ament_cmake_flake8 REQUIRED)
find_package(ament_cmake_pep257 REQUIRED)
find_package(ament_cmake_copyright REQUIRED)

# ament_add_pytest_test(directed.py "directed.py")
ament_add_pytest_test(directed.py "directed.py")
ament_copyright()
ament_pep257()
ament_flake8()

ament_add_gtest(${PROJECT_NAME}-utest utest.cpp APPEND_LIBRARY_DIRS "${image_geometry_lib_dir}")
target_link_libraries(${PROJECT_NAME}-utest ${PROJECT_NAME} ${OpenCV_LIBS})
49 changes: 38 additions & 11 deletions image_geometry/test/directed.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
# Copyright 2018 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function

import unittest
import sensor_msgs.msg

from image_geometry import PinholeCameraModel, StereoCameraModel

import sensor_msgs.msg


class TestDirected(unittest.TestCase):

def setUp(self):
Expand All @@ -19,7 +35,7 @@ def test_monocular(self):
cam.fromCameraInfo(ci)
print(cam.rectifyPoint((0, 0)))

print(cam.project3dToPixel((0,0,0)))
print(cam.project3dToPixel((0, 0, 0)))

def test_stereo(self):
lmsg = sensor_msgs.msg.CameraInfo()
Expand All @@ -29,15 +45,25 @@ def test_stereo(self):
m.height = 480

# These parameters taken from a real camera calibration
lmsg.D = [-0.363528858080088, 0.16117037733986861, -8.1109585007538829e-05, -0.00044776712298447841, 0.0]
lmsg.K = [430.15433020105519, 0.0, 311.71339830549732, 0.0, 430.60920415473657, 221.06824942698509, 0.0, 0.0, 1.0]
lmsg.R = [0.99806560714807102, 0.0068562422224214027, 0.061790256276695904, -0.0067522959054715113, 0.99997541519165112, -0.0018909025066874664, -0.061801701660692349, 0.0014700186639396652, 0.99808736527268516]
lmsg.P = [295.53402059708782, 0.0, 285.55760765075684, 0.0, 0.0, 295.53402059708782, 223.29617881774902, 0.0, 0.0, 0.0, 1.0, 0.0]
lmsg.d = [-0.363528858080088, 0.16117037733986861, -8.1109585007538829e-05,
-0.00044776712298447841, 0.0]
lmsg.k = [430.15433020105519, 0.0, 311.71339830549732, 0.0, 430.60920415473657,
221.06824942698509, 0.0, 0.0, 1.0]
lmsg.r = [0.99806560714807102, 0.0068562422224214027, 0.061790256276695904,
-0.0067522959054715113, 0.99997541519165112, -0.0018909025066874664,
-0.061801701660692349, 0.0014700186639396652, 0.99808736527268516]
lmsg.p = [295.53402059708782, 0.0, 285.55760765075684, 0.0, 0.0, 295.53402059708782,
223.29617881774902, 0.0, 0.0, 0.0, 1.0, 0.0]

rmsg.D = [-0.3560641041112021, 0.15647260261553159, -0.00016442960757099968, -0.00093175810713916221]
rmsg.K = [428.38163131344191, 0.0, 327.95553847249192, 0.0, 428.85728580588329, 217.54828640915309, 0.0, 0.0, 1.0]
rmsg.R = [0.9982082576219119, 0.0067433328293516528, 0.059454199832973849, -0.0068433268864187356, 0.99997549128605434, 0.0014784127772287513, -0.059442773257581252, -0.0018826283666309878, 0.99822993965212292]
rmsg.P = [295.53402059708782, 0.0, 285.55760765075684, -26.507895206214123, 0.0, 295.53402059708782, 223.29617881774902, 0.0, 0.0, 0.0, 1.0, 0.0]
rmsg.d = [-0.3560641041112021, 0.15647260261553159, -0.00016442960757099968,
-0.00093175810713916221]
rmsg.k = [428.38163131344191, 0.0, 327.95553847249192, 0.0, 428.85728580588329,
217.54828640915309, 0.0, 0.0, 1.0]
rmsg.r = [0.9982082576219119, 0.0067433328293516528, 0.059454199832973849,
-0.0068433268864187356, 0.99997549128605434, 0.0014784127772287513,
-0.059442773257581252, -0.0018826283666309878, 0.99822993965212292]
rmsg.p = [295.53402059708782, 0.0, 285.55760765075684, -26.507895206214123, 0.0,
295.53402059708782, 223.29617881774902, 0.0, 0.0, 0.0, 1.0, 0.0]

cam = StereoCameraModel()
cam.fromCameraInfo(lmsg, rmsg)
Expand All @@ -51,7 +77,7 @@ def test_stereo(self):
self.assertAlmostEqual(y, ry, 3)
self.assertAlmostEqual(x, lx, 3)
self.assertAlmostEqual(x, rx + d, 3)

u = 100.0
v = 200.0
du = 17.0
Expand All @@ -66,6 +92,7 @@ def test_stereo(self):
self.assertAlmostEqual(cam.left.getDeltaX(du, Z), xyz1[0] - xyz0[0], 3)
self.assertAlmostEqual(cam.left.getDeltaY(dv, Z), xyz1[1] - xyz0[1], 3)


if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(TestDirected('test_stereo'))
Expand Down
23 changes: 23 additions & 0 deletions image_geometry/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2018 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_copyright.main import main
import pytest


@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
23 changes: 23 additions & 0 deletions image_geometry/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2018 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_flake8.main import main
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc = main(argv=[])
assert rc == 0, 'Found errors'
23 changes: 23 additions & 0 deletions image_geometry/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2018 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=[])
assert rc == 0, 'Found code style errors / warnings'
14 changes: 14 additions & 0 deletions image_geometry/test/utest.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2018 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "image_geometry/pinhole_camera_model.h"
#include <sensor_msgs/distortion_models.hpp>
#include <gtest/gtest.h>
Expand Down