當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。