parameters: (self, img_msg, desired_encoding = "passthrough")
return_statement: return res
docstring: Convert a sensor_msgs::Image message to an OpenCV :cpp:type:`cv::Mat`.
  
          :param img_msg:   A :cpp:type:`sensor_msgs::Image` message
          :param desired_encoding:  The encoding of the image data, one of the following strings:
  
             * ``"passthrough"``
             * one of the standard strings in sensor_msgs/image_encodings.h
  
          :rtype: :cpp:type:`cv::Mat`
          :raises CvBridgeError: when conversion is not possible.
  
          If desired_encoding is ``"passthrough"``, then the returned image has the same format as img_msg.
          Otherwise desired_encoding must be one of the standard image encodings
  
          This function returns an OpenCV :cpp:type:`cv::Mat` message on success, or raises :exc:`cv_bridge.CvBridgeError` on failure.
  
          If the image only has one channel, the shape has size 2 (width and height)
docstring_summary: Convert a sensor_msgs::Image message to an OpenCV :cpp:type:`cv::Mat`.
docstring_tokens: Convert a sensor_msgs :: Image message to an OpenCV : cpp : type : cv :: Mat .
function: def imgmsg_to_cv2(self, img_msg, desired_encoding = "passthrough"):
          """
          Convert a sensor_msgs::Image message to an OpenCV :cpp:type:`cv::Mat`.
  
          :param img_msg:   A :cpp:type:`sensor_msgs::Image` message
          :param desired_encoding:  The encoding of the image data, one of the following strings:
  
             * ``"passthrough"``
             * one of the standard strings in sensor_msgs/image_encodings.h
  
          :rtype: :cpp:type:`cv::Mat`
          :raises CvBridgeError: when conversion is not possible.
  
          If desired_encoding is ``"passthrough"``, then the returned image has the same format as img_msg.
          Otherwise desired_encoding must be one of the standard image encodings
  
          This function returns an OpenCV :cpp:type:`cv::Mat` message on success, or raises :exc:`cv_bridge.CvBridgeError` on failure.
  
          If the image only has one channel, the shape has size 2 (width and height)
          """
          import cv2
          import numpy as np
          dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
          dtype = np.dtype(dtype)
          dtype = dtype.newbyteorder('>' if img_msg.is_bigendian else '<')
          if n_channels == 1:
              im = np.ndarray(shape=(img_msg.height, img_msg.width),
                             dtype=dtype, buffer=img_msg.data)
          else:
              im = np.ndarray(shape=(img_msg.height, img_msg.width, n_channels),
                             dtype=dtype, buffer=img_msg.data)
          # If the byt order is different between the message and the system.
          if img_msg.is_bigendian == (sys.byteorder == 'little'):
              im = im.byteswap().newbyteorder()
  
          if desired_encoding == "passthrough":
              return im
  
          from cv_bridge.boost.cv_bridge_boost import cvtColor2
  
          try:
              res = cvtColor2(im, img_msg.encoding, desired_encoding)
          except RuntimeError as e:
              raise CvBridgeError(e)
  
          return res
function_tokens: def imgmsg_to_cv2 ( self , img_msg , desired_encoding = "passthrough" ) : import cv2 import numpy as np dtype , n_channels = self . encoding_to_dtype_with_channels ( img_msg . encoding ) dtype = np . dtype ( dtype ) dtype = dtype . newbyteorder ( '>' if img_msg . is_bigendian else '<' ) if n_channels == 1 : im = np . ndarray ( shape = ( img_msg . height , img_msg . width ) , dtype = dtype , buffer = img_msg . data ) else : im = np . ndarray ( shape = ( img_msg . height , img_msg . width , n_channels ) , dtype = dtype , buffer = img_msg . data ) # If the byt order is different between the message and the system. if img_msg . is_bigendian == ( sys . byteorder == 'little' ) : im = im . byteswap ( ) . newbyteorder ( ) if desired_encoding == "passthrough" : return im from cv_bridge . boost . cv_bridge_boost import cvtColor2 try : res = cvtColor2 ( im , img_msg . encoding , desired_encoding ) except RuntimeError as e : raise CvBridgeError ( e ) return res