ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ImportError: No module named cv_bridge

asked 2014-08-19 20:06:46 -0500

Gideon gravatar image

updated 2014-08-19 20:29:18 -0500

ahendrix gravatar image

Hello all, I am trying to subscribe to a kinect publisher, grab an rgb image and convert it to an ipl image so I can manipulate it with opencv. I am using Fuerte and Ubuntu 12.04 and I am writing the code in Python. I am bit unsure how to make sure my package paths are all set up correctly. I have found some example code that I am posting below and I get an error stating

"ImportError: No module named cv_bridge"

I have added <run_depend>cv_bridge</run_depend> and <build_depend>cv_bridge</build_depend> to my package.xml

My package will hopefully control a sphero at some point, and so my package is called 'sphero_controller' and it is in a catkin workspace below my home folder. I have added this to the end of my .bashrc

export ROS_PACKAGE_PATH=/home/gideon:/opt/ros/fuerte/stacks:$ROS_PACKAGE_PATH

Does anyone know what I may be doing wrong?

Thanks

Gideon

#!/usr/bin/env python
import roslib
roslib.load_manifest('sphero_controller')
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 cv2.cv as cv

from std_msgs.msg import ColorRGBA

class image_converter:

  def __init__(self):
    self.image_pub = rospy.Publisher("image_topic_2",Image)

    cv2.namedWindow("Image window", 1)
    self.bridge = CvBridge()
    self.image_sub = rospy.Subscriber("/camera/rgb/image_color",Image,self.callback)

  def callback(self,data):
    try:
      cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
    except CvBridgeError, e:
      print e

    (rows,cols,channels) = cv_image.shape
    if cols > 60 and rows > 60 :
      cv2.circle(cv_image, (50,50), 10, 255)

    cv2.imshow("Image window", cv_image)
    cv2.waitKey(3)

    try:
      self.image_pub.publish(self.bridge.cv2_to_imgmsg(cv_image, "bgr8"))
    except CvBridgeError, e:
      print e

def main(args):
  ic = image_converter()
  rospy.init_node('image_converter', anonymous=True)
  try:
    rospy.spin()
  except KeyboardInterrupt:
    print "Shutting down"
  cv2.destroyAllWindows()

if __name__ == '__main__':
    main(sys.argv)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-08-19 20:36:48 -0500

ahendrix gravatar image

I STRONGLY recommend that you upgrade to a newer version of ROS. ROS Fuerte is no longer supported, and does not support the catkin package.xml that you're trying to use.





If for some reason you can't upgrade to a newer version of ROS, you'll need to:

  • switch your package to the older rosbuild build system
  • add a dependency on cv_bridge to your manifest.xml
  • make sure that the roslib.load_manifest() line in your python script is loading the manifest for your package. This is where the dependencies in your manifest.xml are added to your python path, so it's important to make sure it's loading the correct manifest.
edit flag offensive delete link more

Comments

Thank you for your help. I had indigo and ubuntu 14.04 installed initially but there is no package available for the sphero so I downgraded. I will try to build the sphero package from source.

Gideon gravatar image Gideon  ( 2014-08-21 10:28:31 -0500 )edit
1

This doesn't really answer his question. I just did a fresh install of Kinetic, and I also got this error...

Cerin gravatar image Cerin  ( 2016-08-23 22:44:33 -0500 )edit

Question Tools

Stats

Asked: 2014-08-19 20:06:46 -0500

Seen: 6,245 times

Last updated: Aug 19 '14