discover_camera module

class discover_camera.Camera(subscribe=True, callback=None)

Bases: Config

A class used to instantiate and use the raspicam on the LeoRover. The camera is a 5 megapixel webcam with a 170-degree field of view. Images are published at approximately 67 frames per second.

Methods

get_info()

A function that returns information about the camera on the rover.

get_jpg()

A function that uses OpenCV's CvBridge to convert a sensor_msgs/Image object to an OpenCV image object, which is then saved as an .jpg file in the /experiment/photos directory.

get_latest_image()

A function that returns the latest image in the form of a sensor_msgs/Image object.

is_available()

A function that returns whether or not the camera on the rover is available.

set_callback(func)

A function that sets the callback function to be called whenever new images from the camera are available.

start_recording()

A function that opens a new rosbag file to record all ROS messages published on the /camera/image_raw topic.

stop_recording()

A function that closes a previously opened rosbag file that has records of ROS messages published on the /camera/image_raw topic.

subscribe_to_image_topic()

Subscribes to the ROS image topic published from the camera.

get_info() str

A function that returns information about the camera on the rover.

Parameters:
None
Returns:
str

A string containing information about the camera.

Examples

>>> from rover_api.discover_camera import Camera
>>> cam = Camera()
>>> info = cam.get_info()
get_jpg()

A function that uses OpenCV’s CvBridge to convert a sensor_msgs/Image object to an OpenCV image object, which is then saved as an .jpg file in the /experiment/photos directory. Images are saved as /experiment/photos/<number_of_image>.jpg.

Parameters:
None
Returns:
None

Examples

>>> from rover_api.discover_camera import Camera
>>> cam = Camera()
>>> cam.get_jpg()
get_latest_image() Image

A function that returns the latest image in the form of a sensor_msgs/Image object.

Parameters:
None
Returns:
Image

The latest image in the form of a sensor_msgs/Image object.

Examples

>>> from rover_api.discover_camera import Camera
>>> from sensor_msgs.msg import Image
>>> cam = Camera()
>>> image1 = cam.get_latest_image()
is_available() bool

A function that returns whether or not the camera on the rover is available.

Parameters:
None
Returns:
bool

A boolean value representing if the camera is available.

Examples

>>> from rover_api.discover_camera import Camera
>>> cam = Camera(subscribe=False)
>>> if cam.is_available():
>>>     cam.subscribe_to_image_topic()
set_callback(func)

A function that sets the callback function to be called whenever new images from the camera are available. The new callback function will not be called unless subscribe is set to True, or subscribe_to_image_topic() has been called.

Parameters:
funcfunction

The new callback function

Returns:
None

Examples

>>> from rover_api.discover_camera import Camera
>>> def cb_func():
>>>     print("New image published")
>>> 
>>> cam = Camera(False, None)
>>> cam.set_callback(cb_func)
>>> cam.subscribe_to_image_topic()
start_recording()

A function that opens a new rosbag file to record all ROS messages published on the /camera/image_raw topic.

Parameters:
None
Returns:
None

Examples

>>> from rover_api.discover_camera import Camera
>>> cam = Camera()
>>> cam.start_recording()
stop_recording()

A function that closes a previously opened rosbag file that has records of ROS messages published on the /camera/image_raw topic.

Parameters:
None
Returns:
None

Examples

>>> from rover_api.discover_camera import Camera
>>> from time import sleep
>>> cam = Camera()
>>> cam.start_recording()
>>> sleep(3)
>>> cam.stop_recording()
subscribe_to_image_topic()

Subscribes to the ROS image topic published from the camera. If subscribe is set to False, call this function to get data from the camera.

Parameters:
None
Returns:
None

Examples

>>> from rover_api.discover_camera import Camera
>>> cam = Camera(False)
>>> cam.subscribe_to_image_topic()