当前位置: 首页>>代码示例>>Python>>正文


Python cv_bridge.CvBridge方法代码示例

本文整理汇总了Python中cv_bridge.CvBridge方法的典型用法代码示例。如果您正苦于以下问题:Python cv_bridge.CvBridge方法的具体用法?Python cv_bridge.CvBridge怎么用?Python cv_bridge.CvBridge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv_bridge的用法示例。


在下文中一共展示了cv_bridge.CvBridge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gCamera

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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) 
开发者ID:DJTobias,项目名称:Cherry-Autonomous-Racecar,代码行数:19,代码来源:gCamera.py

示例2: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
def __init__(self, args):
        self.index = 0
        if len(sys.argv) > 1:
            self.index = int(sys.argv[1])
        rospy.init_node('save_img')
        self.bridge = CvBridge()

        while not rospy.is_shutdown():
            raw_input()

            data = rospy.wait_for_message('/camera1/usb_cam/image_raw', Image)

            try:
                cv_image = self.bridge.imgmsg_to_cv2(data, "passthrough")
            except CvBridgeError as e:
                print(e)

            print "Saved to: ", base_path+str(self.index)+".jpg"
            cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB, cv_image)
            cv2.imwrite(join(base_path, "frame{:06d}.jpg".format(self.index)), cv_image)#*255)
            self.index += 1
        rospy.spin() 
开发者ID:SudeepDasari,项目名称:visual_foresight,代码行数:24,代码来源:save_images_from_topic.py

示例3: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
def __init__(self, topic_data, opencv_tracking=False, save_videos=False):
        self._tracking_enabled, self._save_vides = opencv_tracking, save_videos

        self._latest_image = LatestObservation(self._tracking_enabled, self._save_vides)

        self._is_tracking = False
        if self._tracking_enabled:
            self.box_height = 80

        self.bridge = CvBridge()
        self._is_first_status, self._status_sem = True, Semaphore(value=0)
        self._cam_height, self._cam_width = None, None
        self._last_hash, self._num_repeats = None, 0
        if self._save_vides:
            self._buffers = []
            self._saving = False

        self._topic_data = topic_data
        self._image_dtype = topic_data.dtype
        rospy.Subscriber(topic_data.name, Image_msg, self.store_latest_im)
        logging.getLogger('robot_logger').debug('downing sema on topic: {}'.format(topic_data.name))
        self._status_sem.acquire()
        logging.getLogger('robot_logger').info("Cameras {} subscribed: stream is {}x{}".format(self._topic_data.name, self._cam_width, self._cam_height)) 
开发者ID:SudeepDasari,项目名称:visual_foresight,代码行数:25,代码来源:camera_recorder.py

示例4: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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 
开发者ID:OpenAgricultureFoundation,项目名称:openag_cv,代码行数:21,代码来源:ObjectMeasurer.py

示例5: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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...") 
开发者ID:OpenAgricultureFoundation,项目名称:openag_cv,代码行数:19,代码来源:MaskPlantTray.py

示例6: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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...") 
开发者ID:OpenAgricultureFoundation,项目名称:openag_cv,代码行数:25,代码来源:Merger.py

示例7: _setup_image

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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") 
开发者ID:RethinkRobotics,项目名称:intera_sdk,代码行数:19,代码来源:head_display.py

示例8: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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() 
开发者ID:DJTobias,项目名称:Cherry-Autonomous-Racecar,代码行数:18,代码来源:lidarEvasion.py

示例9: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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() 
开发者ID:DJTobias,项目名称:Cherry-Autonomous-Racecar,代码行数:20,代码来源:dataRecorder.py

示例10: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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() 
开发者ID:DJTobias,项目名称:Cherry-Autonomous-Racecar,代码行数:20,代码来源:runModel.py

示例11: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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) 
开发者ID:cong,项目名称:ros_tensorflow,代码行数:21,代码来源:ros_tensorflow_mnist.py

示例12: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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...") 
开发者ID:PacktPublishing,项目名称:Learning-Robotics-using-Python-Second-Edition,代码行数:24,代码来源:cv_bridge_demo.py

示例13: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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) 
开发者ID:shunchan0677,项目名称:Tensorflow_in_ROS,代码行数:19,代码来源:tensorflow_in_ros_mnist.py

示例14: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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) 
开发者ID:alexsax,项目名称:midlevel-reps,代码行数:19,代码来源:goggle.py

示例15: __init__

# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridge [as 别名]
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 
开发者ID:ildoonet,项目名称:ros-video-recorder,代码行数:27,代码来源:recorder.py


注:本文中的cv_bridge.CvBridge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。