RobotRaconteurCompanion.Util.ImageUtil
Utility class for working with Robot Raconteur images. The images are converted between the Robot Raconteur image structure and the OpenCV image structure. OpenCV image structures in Python are typically numpy arrays. Compressed and uncompressed Robot Raconteur images are supported.
A simple example:
from RobotRaconteur.Client import *
from RobotRaconteurCompanion.Util.ImageUtil import ImageUtil
c = RRN.ConnectService('rr+tcp://localhost:2355?service=camera')
im = c.capture_frame()
im_util = ImageUtil(client_obj=c)
im_mat = im_util.image_to_numpy(im)
# Do something with the image
# Create a random image
im_mat = np.random.randint(0,255,(480,640,3),dtype=np.uint8)
rr_img = im_util.array_to_image(im_mat, "bgr888")
# Send the image
c.send_frame(rr_img)
ImageUtil
- class RobotRaconteurCompanion.Util.ImageUtil.ImageUtil(node=None, client_obj=None)
- array_to_compressed_image_jpg(arr, quality=95)
Convert a numpy array to a compressed Robot Raconteur Image in jpg format.
- Parameters:
arr (numpy.ndarray) – The array to convert
quality (int) – The JPEG quality (0-100). Default is 95.
- Returns:
The converted image
- Return type:
com.robotraconteur.image.CompressedImage
- array_to_compressed_image_png(arr)
Convert a numpy array to a compressed Robot Raconteur Image in png format.
- Parameters:
arr (numpy.ndarray) – The array to convert
- Returns:
The converted image
- Return type:
com.robotraconteur.image.CompressedImage
- array_to_image(arr, encoding)
Convert a numpy array to a Robot Raconteur Image. The array must be in the format specified by the image encoding.
The following image encoding codes are supported:
bgr888
rgb888
bgra8888
rgba8888
mono8
mono16
mono32
depth_f32
- Parameters:
arr (numpy.ndarray) – The array to convert
- Encoding:
The image encoding
- Returns:
The converted image
- Return type:
com.robotraconteur.image.Image
- compressed_image_to_array(rr_compressed_image, flags=-1)
Convert a compressed Robot Raconteur Image to a numpy array. This function uses cv2.imdecode to decode the image.
- Parameters:
rr_compressed_image (com.robotraconteur.image.CompressedImage) – The image to convert
flags (int) – OpenCV flags for decoding. Default is -1.
- image_to_array(rr_image)
Convert a Robot Raconteur Image to an array. The array will be in the format specified by the image encoding.
The following image encoding codes are supported:
bgr888
rgb888
bgra8888
rgba8888
mono8
mono16
mono32
depth_f32
- Parameters:
rr_image (com.robotraconteur.image.Image) – The Robot Raconteur Image to convert
- Returns:
The converted image
- Return type:
numpy.ndarray