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

camera_readerをc++からpythonに変更 #27

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 0 additions & 42 deletions device/camera_reader/CMakeLists.txt

This file was deleted.

Empty file.
34 changes: 34 additions & 0 deletions device/camera_reader/camera_reader/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Image
import cv2
from cv_bridge import CvBridge

class Camera(Node):
def __init__(self):
super().__init__('camera')
self.publisher_=self.create_publisher(Image,'camera_image',10)
self.timer=self.create_timer(0.1,self.timer_callback)
self.cap=cv2.VideoCapture(0)
self.bridge=CvBridge()
if not self.cap.isOpened():
self.get_logger().error('Failed to open camera')
rclpy.shutdown()

def timer_callback(self):
ret,frame=self.cap.read()
if ret:
msg=self.bridge.cv2_to_imgmsg(frame,"bgr8")
self.publisher_.publish(msg)
else:
self.get_logger().error('Failed to capture image')

def main(args=None):
rclpy.init(args=args)
camera=Camera()
rclpy.spin(camera)
camera.destroy_node()
rclpy.shutdown()

if __name__=="__main__":
main()
17 changes: 0 additions & 17 deletions device/camera_reader/include/camera_reader/camera_reader.hpp

This file was deleted.

21 changes: 8 additions & 13 deletions device/camera_reader/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
<package format="3">
<name>camera_reader</name>
<version>0.0.0</version>
<description>ROS 2 package for receiving images</description>
<maintainer email="[email protected]">hiro</maintainer>
<license>MIT License</license>
<description>TODO: Package description</description>
<maintainer email="[email protected]">hiro</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>rclcpp</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>image_transport</build_depend>
<exec_depend>rclcpp</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>image_transport</exec_depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_cmake</build_type>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions device/camera_reader/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/camera_reader
[install]
install_scripts=$base/lib/camera_reader
21 changes: 21 additions & 0 deletions device/camera_reader/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from setuptools import find_packages, setup

package_name = 'camera_reader'

setup(
name=package_name,
version='0.0.0',
packages=[package_name],
install_requires=['setuptools'],
zip_safe=True,
maintainer='hiro',
maintainer_email='[email protected]',
description='Camera for ROS2',
license='MIT license',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'camera=camera_reader.camera:main',
],
},
)
29 changes: 0 additions & 29 deletions device/camera_reader/src/camera_reader.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions device/camera_reader/src/main.cpp

This file was deleted.

25 changes: 25 additions & 0 deletions device/camera_reader/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2015 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


# Remove the `skip` decorator once the source file(s) have a copyright header
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
25 changes: 25 additions & 0 deletions device/camera_reader/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 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_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)
23 changes: 23 additions & 0 deletions device/camera_reader/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 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=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'