ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

ros_bridge boost error

I am trying to create a ROS wrapper for caffe2 (Ros Kinetic, opencv version-3.4.1) and I get the following error:

[ERROR] [1532132328.463265]: bad callback: <bound method image_converter.callback of <main.image_converter instance at 0x7f01bdc8e7a0>>
Traceback (most recent call last):
File “/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/”, line 750, in _invoke_callback
File “”, line 72, in callback
cv_image = self.bridge.imgmsg_to_cv2(data, ‘bgr8’)
File “/opt/ros/kinetic/lib/python2.7/dist-packages/cv_bridge/”, line 182, in imgmsg_to_cv2
res = cvtColor2(im, img_msg.encoding, desired_encoding)
ArgumentError: Python argument types in
cv_bridge.boost.cv_bridge_boost.cvtColor2(numpy.ndarray, str, unicode)
did not match C++ signature:
cvtColor2(boost::python::api::object, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >)

Any help will be highly appreciated

#!/usr/bin/env python

"""Perform inference on a single image or all images with a certain  extension

(e.g., .jpg) in a folder.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from collections import defaultdict
import argparse
import cv2  # NOQA (Must import before importing caffe2 due to bug in cv2)
import glob
import logging
import os
import sys
import time

from caffe2.python import workspace

import roslib
import sys
import rospy
#import cv2
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import numpy as np
class image_converter:	

    def __init__(self):

	    self.bridge = CvBridge()
	    self.image_sub = rospy.Subscriber("/usb_cam/image_raw",Image,self.callback)
    def callback(self, data):
	    currentframe = 0
		    while True:

		    	cv_image = self.bridge.imgmsg_to_cv2(data, 'bgr8')

	    except CvBridgeError as e:	
def main(args):
    ic = image_converter()
    rospy.init_node('image_converter', anonymous=True)
    except KeyboardInterrupt:
	    print('Shutting Down')

if __name__ == '__main__':

        workspace.GlobalInit(['caffe2', '--caffe2_log_level=0'])
 #      setup_logging(__name__)

Thanks for your question. However we ask that you please ask questions on following our support guidelines:

ROS Discourse is for news and general interest discussions. ROS Answers provides a forum which can be filtered by tags to make sure the relevant people can find and/or answer the question, and not overload everyone with hundreds of posts.

If you’d like you can reply with a link to your question, but in the future please start there.