Python cv_bridge.CvBridge() Examples
The following are 30
code examples of cv_bridge.CvBridge().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv_bridge
, or try the search function
.
Example #1
Source File: camera_subscriber.py From DE3-ROB1-CHESS with Creative Commons Attribution 4.0 International | 9 votes |
def __init__(self, debug=False, init_ros_node=False): self.debug = debug self.rgb_raw = None self.depth_raw = None self.bridge = CvBridge() if init_ros_node: rospy.init_node('image_converter', anonymous=True) self.image_sub = Subscriber("/camera/rgb/image_rect_color", Image) self.depth_sub = Subscriber("/camera/depth_registered/image_raw", Image) self.tss = message_filters.ApproximateTimeSynchronizer([self.image_sub, self.depth_sub], queue_size=10, slop=0.5) self.tss.registerCallback(self.callback) time.sleep(0.5) if self.debug: print("Waiting for subscriber to return initial camera feed.") while self.depth_raw is None: time.sleep(0.1) if self.debug: print('Camera feed initialisation successful.')
Example #2
Source File: gCamera.py From Cherry-Autonomous-Racecar with MIT License | 7 votes |
def gCamera(): print "gstWebCam" bridge = CvBridge() video ="video4" pub = rospy.Publisher('stream', Image, queue_size=10) rospy.init_node('GstWebCam',anonymous=True) Gst.init(None) pipe = Gst.parse_launch("""v4l2src device=/dev/"""+video+""" ! video/x-raw, width=640, height=480,format=(string)BGR ! appsink sync=false max-buffers=2 drop=true name=sink emit-signals=true""") sink = pipe.get_by_name('sink') pipe.set_state(Gst.State.PLAYING) while not rospy.is_shutdown(): sample = sink.emit('pull-sample') img = gst_to_opencv(sample.get_buffer()) try: pub.publish(bridge.cv2_to_imgmsg(img, "bgr8")) except CvBridgeError as e: print(e)
Example #3
Source File: camera_subscriber_processes.py From DE3-ROB1-CHESS with Creative Commons Attribution 4.0 International | 7 votes |
def __init__(self, rgb_q, depth_q, debug=False): self.debug = debug self.rgb_q = rgb_q self.depth_q = depth_q self.bridge = CvBridge() image_sub = Subscriber("/camera/rgb/image_rect_color", Image) depth_sub = Subscriber("/camera/depth_registered/image_raw", Image) tss = message_filters.ApproximateTimeSynchronizer([image_sub, depth_sub], queue_size=10, slop=0.5) tss.registerCallback(self.callback) if self.debug: print('Initialised ImageConverter')
Example #4
Source File: runModel.py From Cherry-Autonomous-Racecar with MIT License | 6 votes |
def __init__(self): rospy.loginfo("runner.__init__") # ---------------------------- self.sess = tf.InteractiveSession() self.model = cnn_cccccfffff() saver = tf.train.Saver() saver.restore(self.sess, "/home/ubuntu/catkin_ws/src/car/scripts/model.ckpt") rospy.loginfo("runner.__init__: model restored") # ---------------------------- self.bridge = CvBridge() self.netEnable = False self.controller = XBox360() rospy.Subscriber("/camera/rgb/image_rect_color", Image, self.runCB) rospy.Subscriber("/joy", Joy ,self.joyCB) self.pub_twist = rospy.Publisher("/neural_twist", TwistStamped, queue_size=1) self.sound = rospy.Publisher("/sound_server/speech_synth", String, queue_size=1) rospy.init_node('neural_cmd',anonymous=True) rospy.spin()
Example #5
Source File: cv_bridge_demo.py From Learning-Robotics-using-Python-Second-Edition with MIT License | 6 votes |
def __init__(self): self.node_name = "cv_bridge_demo" rospy.init_node(self.node_name) # What we do during shutdown rospy.on_shutdown(self.cleanup) # Create the OpenCV display window for the RGB image self.cv_window_name = self.node_name # Create the cv_bridge object self.bridge = CvBridge() # Subscribe to the camera image and depth topics and set # the appropriate callbacks rospy.Subscriber("/camera/rgb/image_raw", Image, self.image_callback) rospy.Subscriber("/camera/depth/image_raw", Image, self.depth_callback) rospy.Timer(rospy.Duration(0.03), self.show_img_cb) rospy.loginfo("Waiting for image topics...")
Example #6
Source File: bag2dataframe.py From rpg_feature_tracking_analysis with MIT License | 6 votes |
def __init__(self, path_to_bag, topic): self.times = [] self.depth_maps = [] self.bridge = CvBridge() with rosbag.Bag(path_to_bag) as bag: topics = bag.get_type_and_topic_info().topics if topic not in topics: raise ValueError("The topic with name %s was not found in bag %s" % (topic, path_to_bag)) for topic, msg, t in bag.read_messages(topics=[topic]): time = msg.header.stamp.secs + 1e-9 * msg.header.stamp.nsecs self.times.append(time) img = self.bridge.imgmsg_to_cv2(msg, "32FC1") self.depth_maps.append(img)
Example #7
Source File: bag2dataframe.py From rpg_feature_tracking_analysis with MIT License | 6 votes |
def __init__(self, path_to_bag, topic): self.path_to_bag = path_to_bag self.times = [] self.images = [] self.bridge = CvBridge() with rosbag.Bag(path_to_bag) as bag: topics = bag.get_type_and_topic_info().topics if topic not in topics: raise ValueError("The topic with name %s was not found in bag %s" % (topic, path_to_bag)) for topic, msg, t in bag.read_messages(topics=[topic]): time = msg.header.stamp.secs + 1e-9 * msg.header.stamp.nsecs self.times.append(time) img = self.bridge.imgmsg_to_cv2(msg, "bgr8") self.images.append(img)
Example #8
Source File: camera_subscriber.py From DE3-ROB1-CHESS with Creative Commons Attribution 4.0 International | 6 votes |
def __init__(self, rgb_q, depth_q, debug=False): self.debug = debug self.rgb_q = rgb_q self.depth_q = depth_q self.bridge = CvBridge() image_sub = Subscriber("/camera/rgb/image_rect_color", Image) depth_sub = Subscriber("/camera/depth_registered/image_raw", Image) tss = message_filters.ApproximateTimeSynchronizer([image_sub, depth_sub],queue_size=10, slop=0.5) tss.registerCallback(self.callback) if self.debug: print('Initialised ImageConverter')
Example #9
Source File: cv_bridge_demo.py From Learning-Robotics-using-Python-Second-Edition with MIT License | 6 votes |
def __init__(self): self.node_name = "cv_bridge_demo" rospy.init_node(self.node_name) # What we do during shutdown rospy.on_shutdown(self.cleanup) # Create the OpenCV display window for the RGB image self.cv_window_name = self.node_name # Create the cv_bridge object self.bridge = CvBridge() # Subscribe to the camera image and depth topics and set # the appropriate callbacks rospy.Subscriber("/camera/rgb/image_raw", Image, self.image_callback) rospy.Subscriber("/camera/depth/image_raw", Image, self.depth_callback) rospy.Timer(rospy.Duration(0.03), self.show_img_cb) rospy.loginfo("Waiting for image topics...")
Example #10
Source File: GazeboDomainRandom.py From GazeboDomainRandom with GNU General Public License v3.0 | 6 votes |
def __init__(self, fovy=75, altitude=1.0, port=11311, env=None) : self.fovy = fovy self.altitude = altitude self.spawned = False self.port = port self.env = env if self.env is None : self.env = os.environ self.K = np.zeros((3,3)) self.K[0][0] = self.fovy self.K[1][1] = self.fovy self.K[2][2] = 1.0 self.K = np.matrix(self.K) self.P = np.matrix( np.concatenate( [self.K, np.zeros((3,1)) ], axis=1) ) self.camerainfo = None self.listener_camera_info = rospy.Subscriber( '/CAMERA/camera_info', CameraInfo, self.callbackCAMERAINFO ) self.image = None self.bridge = CvBridge() self.listener_image = rospy.Subscriber( '/CAMERA/image_raw', Image, self.callbackIMAGE )
Example #11
Source File: ros_wrapper.py From qibullet with Apache License 2.0 | 6 votes |
def __init__(self): """ Constructor """ if MISSING_IMPORT is not None: raise pybullet.error(MISSING_IMPORT) self.spin_thread = None self._wrapper_termination = False self.image_bridge = CvBridge() self.front_info_msg = dict() self.bottom_info_msg = dict() self.depth_info_msg = dict() self.roslauncher = None self.transform_broadcaster = tf2_ros.TransformBroadcaster() atexit.register(self.stopWrapper)
Example #12
Source File: semantic_segmentation_node.py From SARosPerceptionKitti with MIT License | 6 votes |
def __init__(self): rospy.init_node('semantic_segmentation') self.sub = rospy.Subscriber('/kitti/camera_color_left/image_raw', Image, self.callback_read_semantic_segmentation, queue_size=10) self.pub = rospy.Publisher('/pre_processing/segmented_semantic_image', Image, queue_size=10) self.bridge = CvBridge() self.message_counter = 0 scenario = str(rospy.get_param('~scenario', '0001')).zfill(4) self.dir = '~/kitti_data/' + scenario \ + '/segmented_semantic_images/' rospy.spin()
Example #13
Source File: ros_tensorflow_mnist.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def __init__(self): self._cv_bridge = CvBridge() self.x = tf.placeholder(tf.float32, [None,28,28,1], name="x") self.keep_prob = tf.placeholder("float") self.y_conv = makeCNN(self.x,self.keep_prob) self._saver = tf.train.Saver() self._session = tf.InteractiveSession() init_op = tf.global_variables_initializer() self._session.run(init_op) ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) PATH_TO_CKPT = ROOT_PATH + '/include/mnist/model.ckpt' self._saver.restore(self._session, PATH_TO_CKPT) self._sub = rospy.Subscriber('usb_cam/image_raw', Image, self.callback, queue_size=1) self._pub = rospy.Publisher('/result_ripe', Int16, queue_size=1)
Example #14
Source File: core.py From pyrobot with MIT License | 6 votes |
def __init__(self, configs): """ Constructor for Camera parent class. :param configs: configurations for camera :type configs: YACS CfgNode """ self.configs = configs self.cv_bridge = CvBridge() self.camera_info_lock = threading.RLock() self.camera_img_lock = threading.RLock() self.rgb_img = None self.depth_img = None self.camera_info = None self.camera_P = None rospy.Subscriber( self.configs.CAMERA.ROSTOPIC_CAMERA_INFO_STREAM, CameraInfo, self._camera_info_callback, ) rgb_topic = self.configs.CAMERA.ROSTOPIC_CAMERA_RGB_STREAM self.rgb_sub = message_filters.Subscriber(rgb_topic, Image) depth_topic = self.configs.CAMERA.ROSTOPIC_CAMERA_DEPTH_STREAM self.depth_sub = message_filters.Subscriber(depth_topic, Image) img_subs = [self.rgb_sub, self.depth_sub] self.sync = message_filters.ApproximateTimeSynchronizer( img_subs, queue_size=10, slop=0.2 ) self.sync.registerCallback(self._sync_callback)
Example #15
Source File: tensorflow_in_ros_mnist.py From Tensorflow_in_ROS with Apache License 2.0 | 6 votes |
def __init__(self): self._cv_bridge = CvBridge() self.x = tf.placeholder(tf.float32, [None,28,28,1], name="x") self.keep_prob = tf.placeholder("float") self.y_conv = makeCNN(self.x,self.keep_prob) self._saver = tf.train.Saver() self._session = tf.InteractiveSession() init_op = tf.global_variables_initializer() self._session.run(init_op) self._saver.restore(self._session, "model/model.ckpt") self._sub = rospy.Subscriber('image', Image, self.callback, queue_size=1) self._pub = rospy.Publisher('result', Int16, queue_size=1)
Example #16
Source File: ObjectMeasurer.py From openag_cv with GNU General Public License v3.0 | 6 votes |
def __init__(self, argv): self.node_name = "ObjectMeasurer" rospy.init_node(self.node_name) # What we do during shutdown rospy.on_shutdown(self.cleanup) # Create the cv_bridge object self.bridge = CvBridge() # Subscribe to the camera image topics and set # the appropriate callbacks self.image_sub = rospy.Subscriber(argv[1], Image, self.image_callback) self.image_pub = rospy.Publisher( "%s/ObjectMeasurer" % (argv[1]), Image, queue_size=10) rospy.loginfo("Waiting for image topics...") # Initialization of the 'pixels per metric variable' self.pixelsPerMetric = None
Example #17
Source File: MaskPlantTray.py From openag_cv with GNU General Public License v3.0 | 6 votes |
def __init__(self, args): self.node_name = "MaskPlantTray" rospy.init_node(self.node_name) # What we do during shutdown rospy.on_shutdown(self.cleanup) # Create the cv_bridge object self.bridge = CvBridge() # Subscribe to the camera image topics and set # the appropriate callbacks self.image_sub = rospy.Subscriber(args[1], Image, self.image_callback) self.image_pub = rospy.Publisher( "%s/MaskPlantTray" % (args[1]), Image, queue_size=10) rospy.loginfo("Waiting for image topics...")
Example #18
Source File: Merger.py From openag_cv with GNU General Public License v3.0 | 6 votes |
def __init__(self, args): self.node_name = "ImgMerger" rospy.init_node(self.node_name) # What we do during shutdown rospy.on_shutdown(self.cleanup) # Create the cv_bridge object self.bridge = CvBridge() self.frame_img1 = np.zeros((1280, 1024), np.uint8) self.frame_img2 = np.zeros((1280, 1024), np.uint8) # Subscribe to the camera image topics and set # the appropriate callbacks self.image_sub_first_image = rospy.Subscriber( args[1], Image, self.image_callback_img1) self.image_sub_second_image = rospy.Subscriber( args[2], Image, self.image_callback_img2) self.image_pub = rospy.Publisher(args[3], Image, queue_size=10) rospy.loginfo("Waiting for image topics...")
Example #19
Source File: goggle.py From midlevel-reps with MIT License | 6 votes |
def __init__(self): #self.rgb = None rospy.init_node('gibson-goggle') self.depth = None self.image_pub = rospy.Publisher("/gibson_ros/camera_goggle/rgb/image", Image, queue_size=10) self.depth_pub = rospy.Publisher("/gibson_ros/camera_goggle/depth/image", Image, queue_size=10) self.bridge = CvBridge() self.model = self.load_model() self.imgv = Variable(torch.zeros(1, 3, 240, 320), volatile=True).cuda() self.maskv = Variable(torch.zeros(1, 2, 240, 320), volatile=True).cuda() self.mean = torch.from_numpy(np.array([0.57441127, 0.54226291, 0.50356019]).astype(np.float32)) self.mean = self.mean.view(3, 1, 1).repeat(1, 240, 320) self.rgb_sub = rospy.Subscriber("/camera/rgb/image_raw", Image, self.rgb_callback) self.depth_sub = rospy.Subscriber("/camera/depth/image_raw", Image, self.depth_callback)
Example #20
Source File: head_display.py From intera_sdk with Apache License 2.0 | 6 votes |
def _setup_image(self, image_path): """ Load the image located at the specified path @type image_path: str @param image_path: the relative or absolute file path to the image file @rtype: sensor_msgs/Image or None @param: Returns sensor_msgs/Image if image convertable and None otherwise """ if not os.access(image_path, os.R_OK): rospy.logerr("Cannot read file at '{0}'".format(image_path)) return None img = cv2.imread(image_path) # Return msg return cv_bridge.CvBridge().cv2_to_imgmsg(img, encoding="bgr8")
Example #21
Source File: recorder.py From ros-video-recorder with MIT License | 6 votes |
def __init__(self, output_width, output_height, output_fps, output_format, output_path): self.frame_wrappers = [] self.start_time = -1 self.end_time = -1 self.pub_img = None self.bridge = CvBridge() self.fps = output_fps self.interval = 1.0 / self.fps self.output_width = output_width self.output_height = output_height if opencv_version() == 2: fourcc = cv2.cv.FOURCC(*output_format) elif opencv_version() == 3: fourcc = cv2.VideoWriter_fourcc(*output_format) else: raise self.output_path = output_path if self.output_path: self.video_writer = cv2.VideoWriter(output_path, fourcc, output_fps, (output_width, output_height)) else: self.video_writer = None
Example #22
Source File: lidarEvasion.py From Cherry-Autonomous-Racecar with MIT License | 6 votes |
def __init__(self): self.evadeSet = False self.controller = XBox360() self.bridge = CvBridge() self.throttle = 0 self.grid_img = None ##self.throttleLock = Lock() print "evasion" rospy.Subscriber("/lidargrid", Image, self.gridCB, queue_size=1) rospy.Subscriber("/cmd_vel", TwistStamped , self.twistCB , queue_size = 1) rospy.Subscriber("/joy", Joy, self.joyCB, queue_size=5) self.pub_img = rospy.Publisher("/steering_img", Image) self.pub_twist = rospy.Publisher("/lidar_twist", TwistStamped, queue_size=1) self.sound = rospy.Publisher("/sound_server/speech_synth", String, queue_size=1) rospy.init_node ('lidar_cmd',anonymous=True) rospy.spin()
Example #23
Source File: dataRecorder.py From Cherry-Autonomous-Racecar with MIT License | 6 votes |
def __init__(self): print "dataRecorder" self.record = False self.twist = None self.twistLock = Lock() self.bridge = CvBridge() self.globaltime = None self.controller = XBox360() ##rospy.Subscriber("/camera/depth/points" , PointCloud2, self.ptcloudCB) rospy.Subscriber("/camera/depth/image_rect_raw_drop", Image, self.depthCB) rospy.Subscriber("/camera/rgb/image_rect_color_drop", Image, self.streamCB) #rospy.Subscriber("/camera/rgb/image_rect_mono_drop", Image, self.streamCB) ##for black and white images see run.launch and look at the drop fps nodes near the bottom rospy.Subscriber("/lidargrid", Image, self.lidargridCB) rospy.Subscriber("/cmd_vel", TwistStamped, self.cmd_velCB) rospy.Subscriber("/joy", Joy ,self.joyCB) self.sound = rospy.Publisher("/sound_server/speech_synth", String, queue_size=1) rospy.init_node('dataRecorder',anonymous=True) rospy.spin()
Example #24
Source File: grasshopper3_driver_operator.py From pylot with Apache License 2.0 | 5 votes |
def __init__(self, camera_stream, camera_setup, topic_name, flags): self._camera_stream = camera_stream self._camera_setup = camera_setup self._topic_name = topic_name self._flags = flags self._logger = erdos.utils.setup_logging(self.config.name, self.config.log_file_name) self._bridge = cv_bridge.CvBridge() self._modulo_to_send = CAMERA_FPS // self._flags.sensor_frequency self._counter = 0 self._msg_cnt = 0
Example #25
Source File: Camera.py From GtS with MIT License | 5 votes |
def __init__(self, ID): self.id = ID self.bridge = CvBridge() self.mat = None #need to facilitate a set of publishers per cf node self.image_pub = rospy.Publisher('cf/%d/image'%self.id, CompressedImage, queue_size=10) ## CALLBACKS ## ## THREADS ##
Example #26
Source File: folder_image_publisher.py From image_recognition with MIT License | 5 votes |
def __init__(self, context): """ :param context: QT context, aka parent """ super(FolderImagePublisherPlugin, self).__init__(context) # Widget setup self.setObjectName('FolderImagePublisherPlugin') self._widget = QWidget() context.add_widget(self._widget) # Layout and attach to widget layout = QHBoxLayout() self._widget.setLayout(layout) self._info = QLineEdit() self._info.setDisabled(True) self._info.setText("Please choose a directory (top-right corner)") layout.addWidget(self._info) self._left_button = QPushButton('<') self._left_button.clicked.connect(partial(self._rotate_and_publish, -1)) layout.addWidget(self._left_button) self._right_button = QPushButton('>') self._right_button.clicked.connect(partial(self._rotate_and_publish, 1)) layout.addWidget(self._right_button) # Set subscriber and service to None self._pub = rospy.Publisher("folder_image", Image, queue_size=1) self._bridge = CvBridge() self._files = collections.deque([])
Example #27
Source File: image_recognition.py From rostensorflow with Apache License 2.0 | 5 votes |
def __init__(self): classify_image.maybe_download_and_extract() self._session = tf.Session() classify_image.create_graph() self._cv_bridge = CvBridge() self._sub = rospy.Subscriber('image', Image, self.callback, queue_size=1) self._pub = rospy.Publisher('result', String, queue_size=1) self.score_threshold = rospy.get_param('~score_threshold', 0.1) self.use_top_k = rospy.get_param('~use_top_k', 5)
Example #28
Source File: detect_aruco.py From flock with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): # ArUco data -- we're using 6x6 ArUco images self._aruco_dict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_6X6_250) self._aruco_parameters = cv2.aruco.DetectorParameters_create() # Initialize ROS rospy.init_node('detect_aruco_node', anonymous=False) # ROS publishers self._image_pub = rospy.Publisher('image_marked', Image, queue_size=10) self._rviz_markers_pub = rospy.Publisher('rviz_markers', MarkerArray, queue_size=10) # ROS OpenCV bridge self._cv_bridge = CvBridge() # ROS transform managers self._tf_listener = tf.TransformListener() self._tf_broadcaster = tf.TransformBroadcaster() # Get base_link => camera_frame transform self._tf_listener.waitForTransform("base_link", "camera_frame", rospy.Time(), rospy.Duration(4)) self._Tcb = tf_to_matrix(self._tf_listener.lookupTransform("base_link", "camera_frame", rospy.Time())) # Now that we're initialized, set up subscriptions and spin rospy.Subscriber("image_raw", Image, self.image_callback) rospy.spin()
Example #29
Source File: test.py From image_recognition with MIT License | 5 votes |
def __init__(self, context): """ TestPlugin class to evaluate the image_recognition_msgs interfaces :param context: QT context, aka parent """ super(TestPlugin, self).__init__(context) # Widget setup self.setObjectName('Test Plugin') self._widget = QWidget() context.add_widget(self._widget) # Layout and attach to widget layout = QVBoxLayout() self._widget.setLayout(layout) self._image_widget = ImageWidget(self._widget, self.image_roi_callback, clear_on_click=True) layout.addWidget(self._image_widget) # Input field grid_layout = QGridLayout() layout.addLayout(grid_layout) self._info = QLineEdit() self._info.setDisabled(True) self._info.setText("Draw a rectangle on the screen to perform recognition of that ROI") layout.addWidget(self._info) # Bridge for opencv conversion self.bridge = CvBridge() # Set subscriber and service to None self._sub = None self._srv = None
Example #30
Source File: follower_p.py From rosbook with Apache License 2.0 | 5 votes |
def __init__(self): self.bridge = cv_bridge.CvBridge() cv2.namedWindow("window", 1) self.image_sub = rospy.Subscriber('camera/rgb/image_raw', Image, self.image_callback) self.cmd_vel_pub = rospy.Publisher('cmd_vel_mux/input/teleop', Twist, queue_size=1) self.twist = Twist()