parameters: (self, cvim, encoding = "passthrough", header = None)
return_statement: return img_msg
docstring: Convert an OpenCV :cpp:type:`cv::Mat` type to a ROS sensor_msgs::Image message.
  
          :param cvim:      An OpenCV :cpp:type:`cv::Mat`
          :param encoding:  The encoding of the image data, one of the following strings:
  
             * ``"passthrough"``
             * one of the standard strings in sensor_msgs/image_encodings.h
          :param header:    A std_msgs.msg.Header message
  
          :rtype:           A sensor_msgs.msg.Image message
          :raises CvBridgeError: when the ``cvim`` has a type that is incompatible with ``encoding``
  
          If encoding is ``"passthrough"``, then the message has the same encoding as the image's OpenCV type.
          Otherwise desired_encoding must be one of the standard image encodings
  
          This function returns a sensor_msgs::Image message on success, or raises :exc:`cv_bridge.CvBridgeError` on failure.
docstring_summary: Convert an OpenCV :cpp:type:`cv::Mat` type to a ROS sensor_msgs::Image message.
docstring_tokens: Convert an OpenCV : cpp : type : cv :: Mat type to a ROS sensor_msgs :: Image message .
function: def cv2_to_imgmsg(self, cvim, encoding = "passthrough", header = None):
          """
          Convert an OpenCV :cpp:type:`cv::Mat` type to a ROS sensor_msgs::Image message.
  
          :param cvim:      An OpenCV :cpp:type:`cv::Mat`
          :param encoding:  The encoding of the image data, one of the following strings:
  
             * ``"passthrough"``
             * one of the standard strings in sensor_msgs/image_encodings.h
          :param header:    A std_msgs.msg.Header message
  
          :rtype:           A sensor_msgs.msg.Image message
          :raises CvBridgeError: when the ``cvim`` has a type that is incompatible with ``encoding``
  
          If encoding is ``"passthrough"``, then the message has the same encoding as the image's OpenCV type.
          Otherwise desired_encoding must be one of the standard image encodings
  
          This function returns a sensor_msgs::Image message on success, or raises :exc:`cv_bridge.CvBridgeError` on failure.
          """
          import cv2
          import numpy as np
          if not isinstance(cvim, (np.ndarray, np.generic)):
              raise TypeError('Your input type is not a numpy array')
          img_msg = sensor_msgs.msg.Image()
          img_msg.height = cvim.shape[0]
          img_msg.width = cvim.shape[1]
          if header is not None:
              img_msg.header = header
          if len(cvim.shape) < 3:
              cv_type = self.dtype_with_channels_to_cvtype2(cvim.dtype, 1)
          else:
              cv_type = self.dtype_with_channels_to_cvtype2(cvim.dtype, cvim.shape[2])
          if encoding == "passthrough":
              img_msg.encoding = cv_type
          else:
              img_msg.encoding = encoding
              # Verify that the supplied encoding is compatible with the type of the OpenCV image
              if self.cvtype_to_name[self.encoding_to_cvtype2(encoding)] != cv_type:
                  raise CvBridgeError("encoding specified as %s, but image has incompatible type %s" % (encoding, cv_type))
          if cvim.dtype.byteorder == '>':
              img_msg.is_bigendian = True
          img_msg.data = cvim.tostring()
          img_msg.step = len(img_msg.data) // img_msg.height
  
          return img_msg
function_tokens: def cv2_to_imgmsg ( self , cvim , encoding = "passthrough" , header = None ) : import cv2 import numpy as np if not isinstance ( cvim , ( np . ndarray , np . generic ) ) : raise TypeError ( 'Your input type is not a numpy array' ) img_msg = sensor_msgs . msg . Image ( ) img_msg . height = cvim . shape [ 0 ] img_msg . width = cvim . shape [ 1 ] if header is not None : img_msg . header = header if len ( cvim . shape ) < 3 : cv_type = self . dtype_with_channels_to_cvtype2 ( cvim . dtype , 1 ) else : cv_type = self . dtype_with_channels_to_cvtype2 ( cvim . dtype , cvim . shape [ 2 ] ) if encoding == "passthrough" : img_msg . encoding = cv_type else : img_msg . encoding = encoding # Verify that the supplied encoding is compatible with the type of the OpenCV image if self . cvtype_to_name [ self . encoding_to_cvtype2 ( encoding ) ] != cv_type : raise CvBridgeError ( "encoding specified as %s, but image has incompatible type %s" % ( encoding , cv_type ) ) if cvim . dtype . byteorder == '>' : img_msg . is_bigendian = True img_msg . data = cvim . tostring ( ) img_msg . step = len ( img_msg . data ) // img_msg . height return img_msg