當前位置: 首頁>>代碼示例>>Python>>正文


Python msg.CompressedImage類代碼示例

本文整理匯總了Python中sensor_msgs.msg.CompressedImage的典型用法代碼示例。如果您正苦於以下問題:Python CompressedImage類的具體用法?Python CompressedImage怎麽用?Python CompressedImage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CompressedImage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: callback

  def callback(self, ros_data):
    #### direct conversion to CV2 ####
    np_arr = np.fromstring(ros_data.data, np.uint8)
    image_np = cv2.imdecode(np_arr, cv2.CV_LOAD_IMAGE_COLOR)
    
    #(rows,cols,channels) = image_np.shape
    #image_np = image_np[0:64, 0:480] 

    #equ = cv2.equalizeHist(image_np)
    #res = np.hstack((image_np,equ))

    #### Feature detectors using CV2 #### 
    # "","Grid","Pyramid" + 
    # "FAST","GFTT","HARRIS","MSER","ORB","SIFT","STAR","SURF", "GridFAST"
    #method = "GridFAST"
    #feat_det = cv2.FeatureDetector_create(method)
    #time1 = time.time()

    # convert np image to grayscale
    #featPoints = feat_det.detect( cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY))
    #time2 = time.time()
    #if VERBOSE :
    #  print '%s detector found: %s points in: %s sec.'%(method, len(featPoints),time2-time1)

    #for featpoint in featPoints:
    #  x,y = featpoint.pt
    #  cv2.circle(image_np,(int(x),int(y)), 3, (0,0,255), -1)

    #### Create CompressedIamge ####
    msg = CompressedImage()
    msg.header.stamp = rospy.Time.now()
    msg.format = "jpeg"
    msg.data = np.array(cv2.imencode('.jpg', image_np)[1]).tostring()
    # Publish new image
    self.image_pub.publish(msg)
開發者ID:RoboticProjacLaser,項目名稱:src,代碼行數:35,代碼來源:celuiQuiMarchePas.py

示例2: grabFrame

def grabFrame(event):
   msg = CompressedImage()
   msg.header.frame_id = frame_id
   msg.format = "jpeg"
   resp, msg.data = http.request("http://" + host + request)
   msg.header.stamp = rospy.Time.now()
   pub.publish(msg)
開發者ID:MorS25,項目名稱:mjpeg_network_camera,代碼行數:7,代碼來源:polled_camera.py

示例3: stream

  def stream(self):
    url = 'http://%s:%[email protected]%s/mjpg/video.mjpg' % (self.axis.username, self.axis.password, self.axis.hostname)
    #url = url + "?resolution=%dx%d" % (self.axis.width, self.axis.height)
    fp = urllib.urlopen(url)

    while True:
      boundary = fp.readline()

      header = {}
      while 1:
        line = fp.readline()
        if line == "\r\n": break
        line = line.strip()

        parts = line.split(": ", 1)
        header[parts[0]] = parts[1]

      content_length = int(header['Content-Length'])

      img = fp.read(content_length)
      line = fp.readline()
      
      msg = CompressedImage()
      msg.header.stamp = rospy.Time.now()
      msg.header.frame_id = self.axis_frame_id
      msg.format = "jpeg"
      msg.data = img

      self.axis.pub.publish(msg)

      """
開發者ID:hkaraoguz,項目名稱:axis_cameraHK,代碼行數:31,代碼來源:axis.py

示例4: publish

 def publish(self, raw_img):
     msg = CompressedImage()
     msg.header.stamp = rospy.Time.now()
     msg.format = "jpeg"
     msg.data = np.array(cv2.imencode(".jpg", raw_img)[1]).tostring()
     # TODO compile sensor_msg error , use String instead
     self.image_pub.publish(msg.data)
開發者ID:rli9,項目名稱:slam,代碼行數:7,代碼來源:image_publisher.py

示例5: __init__

    def __init__(self):
        # Get the ~private namespace parameters from command line or launch file.
        self.UDP_IP = rospy.get_param('~UDP_IP', '192.168.50.37') #get_ip.get_local()
        #if self.UDP_IP != 'localhost':
        #    self.UDP_IP = int(self.UDP_IP)
        self.UDP_PORT = int(rospy.get_param('~UDP_PORT', '49155'))

        # Create a dynamic reconfigure server.
        #self.server = DynamicReconfigureServer(ConfigType, self.reconfigure)
        
        # create ros::Publisher to send Odometry messages
        cam_pub = rospy.Publisher('image_raw/compressed', CompressedImage)

        #crappy test
        t = True
        while not rospy.is_shutdown():
            #crappy test continued
            if t:
                print "Camera Running"
            t = False

            udp_string = self.receive_packet()
            jpg_string = self.parse_string(udp_string)

            cam_msg = CompressedImage()
            cam_msg.header.stamp = rospy.Time.now() #YOYOYOYO - should be from robot time
            cam_msg.format = "jpeg"
            cam_msg.data = jpg_string

            cam_pub.publish(cam_msg)
開發者ID:mattjrush,項目名稱:tankbot,代碼行數:30,代碼來源:cam_pub.py

示例6: grabAndPublish

    def grabAndPublish(self,stream,publisher):
        # Grab image from stream
        stream.seek(0)
        img_data = stream.getvalue()

        if self.uncompress:
            # Publish raw image
            data = np.fromstring(img_data, dtype=np.uint8)
            image = cv2.imdecode(data, 1)
            image_msg = self.bridge.cv2_to_imgmsg(image)
        else:
            # Publish compressed image only
            image_msg = CompressedImage()
            image_msg.data = img_data
            image_msg.format = "jpeg"
            
        image_msg.header.stamp = rospy.Time.now()
        # Publish 
        publisher.publish(image_msg)
        # Clear stream
        stream.seek(0)
        stream.truncate()

        if not self.has_published:
            rospy.loginfo("[%s] Published the first image." %(self.node_name))
            self.has_published = True
開發者ID:71ananab,項目名稱:Software,代碼行數:26,代碼來源:camera_node_continuous.py

示例7: ros_compressed_from_numpygray

def ros_compressed_from_numpygray(np_arr):
    msg = CompressedImage()
    msg.header.stamp = rospy.Time.now()
    msg.format = "jpeg"
    np_arr = 255*(1.0*np_arr/np.max(np_arr))
    msg.data = np.array(cv2.imencode('.jpg', np.array(np_arr, dtype = np.uint8))[1]).tostring()
    return msg
開發者ID:ChuangWang-Zoox,項目名稱:Software,代碼行數:7,代碼來源:LEDDetector.py

示例8: grabAndPublish

    def grabAndPublish(self,stream,publisher):
        while not self.update_framerate and not self.is_shutdown and not rospy.is_shutdown(): 
            yield stream
            # Construct image_msg
            # Grab image from stream
            stamp = rospy.Time.now()
            stream.seek(0)
            stream_data = stream.getvalue()
            # Generate compressed image
            image_msg = CompressedImage()
            image_msg.format = "jpeg"
            image_msg.data = stream_data

            image_msg.header.stamp = stamp
            image_msg.header.frame_id = self.frame_id
            publisher.publish(image_msg)
                        
            # Clear stream
            stream.seek(0)
            stream.truncate()
            
            if not self.has_published:
                rospy.loginfo("[%s] Published the first image." %(self.node_name))
                self.has_published = True

            rospy.sleep(rospy.Duration.from_sec(0.001))
開發者ID:Duckietown-NCTU,項目名稱:Software,代碼行數:26,代碼來源:camera_node_sequence_kuo.py

示例9: handle_pkt

def handle_pkt(pkt=None):
    ts_begin_loc = pkt.find(begin_timestamp_marker)
    ts_end_loc = pkt.find(end_timestamp_marker)

    if ts_begin_loc == -1 or ts_end_loc == -1:
        #something's fishy, discard jpeg
        print "JPEG discarded, malformed data"
        return 
        
    ts = float(pkt[ts_begin_loc+len(begin_timestamp_marker):ts_end_loc])
	
#    if ts > last_ts:
#	last_ts = ts
#    else:
#	return

    pkt = pkt[ts_end_loc+len(end_timestamp_marker):]

    print "{} bytes of JPEG recvd".format(len(pkt))
    msg = CompressedImage()
    msg.header.stamp  = rospy.Time(tango_clock_offset + float(ts))
    msg.header.frame_id = camera_name
    msg.data = pkt
    msg.format = 'jpeg'
    pub_camera.publish(msg)
開發者ID:DhashS,項目名稱:tango_ros_bridge,代碼行數:25,代碼來源:image_server.py

示例10: sendTestImage

 def sendTestImage(self):
     img_name = '0'+str(self.sent_image_count)+'_orig.'+self.test_image_format
     test_img = cv2.imread(self.test_image_path+img_name)
     msg = CompressedImage()
     msg.header.stamp = rospy.Time.now()
     msg.format = self.test_image_format
     msg.data = np.array(cv2.imencode('.'+self.test_image_format, test_img)[1]).tostring()
     self.pub_test_image.publish(msg)
開發者ID:71ananab,項目名稱:Software,代碼行數:8,代碼來源:virtual_mirror_joewl_tester_node.py

示例11: pubOriginal

    def pubOriginal(self, msg):
        compressed_img_msg = CompressedImage()
        compressed_img_msg.format = "png"
        compressed_img_msg.data = np.array(cv2.imencode(".png", self.testImageOrig)[1]).tostring()

        # compressed_img_msg.header.stamp = msg.header.stamp
        # compressed_img_msg.header.frame_id = msg.header.frame_id
        self.pub_raw.publish(compressed_img_msg)
開發者ID:hangzhaomit,項目名稱:Software,代碼行數:8,代碼來源:virtual_mirror_tester_node.py

示例12: processImage

    def processImage(self, image_msg):
        image_cv = self.bridge.imgmsg_to_cv2(image_msg)

        #### Create CompressedIamge ####
        msg = CompressedImage()
        msg.header.stamp = rospy.Time.now()
        msg.format = "jpeg"
        msg.data = np.array(cv2.imencode('.jpg', image_cv)[1]).tostring()
        self.pub_image_comp.publish(msg)
開發者ID:sparrowcat,項目名稱:racecar22,代碼行數:9,代碼來源:echo_compressed.py

示例13: stream

	def stream(self):
		"""
			Reads and process the streams from the camera	
		"""		 
		try:
			#If flag self.enable_auth is 'True' then use the user/password to access the camera. Otherwise use only self.url
			if self.enable_auth:
				req = urllib2.Request(self.url, None, {"Authorization": self.auth })
			else:
				req = urllib2.Request(self.url)
				
			fp = urllib2.urlopen(req, timeout = self.timeout)
			#fp = urllib2.urlopen(req)

			while self.run_camera and not rospy.is_shutdown():
				
				boundary = fp.readline()
				
				header = {}
				
				while not rospy.is_shutdown():
					line = fp.readline()
					#print 'read line %s'%line
					if line == "\r\n": break
					line = line.strip()
					#print line
					parts = line.split(": ", 1)
					header[parts[0]] = parts[1]

				content_length = int(header['Content-Length'])
				#print 'Length = %d'%content_length
				img = fp.read(content_length)
				line = fp.readline()
				
				msg = CompressedImage()
				msg.header.stamp = rospy.Time.now()
				msg.header.frame_id = self.axis_frame_id
				msg.format = "jpeg"
				msg.data = img
				# publish image
				self.compressed_image_publisher.publish(msg)
				
				cimsg = self.cinfo.getCameraInfo()
				cimsg.header.stamp = msg.header.stamp
				cimsg.header.frame_id = self.axis_frame_id
				# publish camera info
				self.caminfo_publisher.publish(cimsg)
				
				#print self.real_fps
				self.last_update = datetime.datetime.now()
				self.error_reading = False
				self.image_pub_freq.tick()
						
		except urllib2.URLError,e:
			self.error_reading = True
			self.error_reading_msg = e
			rospy.logerr('Axis:stream: Camera %s (%s:%d). Error: %s'%(self.camera_id, self.hostname, self.camera_number, e))
開發者ID:RobotnikAutomation,項目名稱:axis_camera,代碼行數:57,代碼來源:axis_node.py

示例14: cv2_to_compressed_ros

 def cv2_to_compressed_ros(self, img):
     try:
         msg = CompressedImage()
         msg.header.stamp = rospy.Time.now()
         msg.format = "jpeg"
         msg.data = np.array(cv2.imencode('.jpg', img)[1]).tostring()
         return msg
     except CvBridgeError as e:
         rospy.logerr(e)
開發者ID:soulslicer,項目名稱:FYP-Code,代碼行數:9,代碼來源:Ros.py

示例15: pubImage

 def pubImage(self):
     filename = '0'+str(self.num_sent)+'_orig.png'
     image = cv2.imread(self.im_dir+filename)
     msg = CompressedImage()
     msg.header.stamp = rospy.Time.now()
     msg.format = 'png'
     msg.data = np.array(cv2.imencode('.png', image)[1]).tostring()
     self.pub_fake_images.publish(msg)
     rospy.loginfo("[%s] Image %s published" %(self.node_name,filename))
開發者ID:71ananab,項目名稱:Software,代碼行數:9,代碼來源:virtual_mirror_catliu_tester_node.py


注:本文中的sensor_msgs.msg.CompressedImage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。