本文整理汇总了Python中sensor_msgs.msg.CompressedImage.data方法的典型用法代码示例。如果您正苦于以下问题:Python CompressedImage.data方法的具体用法?Python CompressedImage.data怎么用?Python CompressedImage.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor_msgs.msg.CompressedImage
的用法示例。
在下文中一共展示了CompressedImage.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback_right_with_3D
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
def callback_right_with_3D(self, ros_data):
'''Callback function of subscribed topic.
Here images get converted and features detected'''
self.right_header = ros_data.header.stamp.secs
#### direct conversion to CV2 ####
np_arr = np.fromstring(ros_data.data, np.uint8)
image_np = cv2.imdecode(np_arr, 1)
# convert np image to grayscale
gray_image = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
if self.right_header == self.left_header and self.group_4_recieved:
s_t = time.clock()
print self.right_header, self.left_header
self.group_4_recieved = False
left_gray = cv2.cvtColor(self.left_image, cv2.COLOR_BGR2GRAY)
group_4_out = self.group_4
# PointCloudPose()
# group_4_out.header = self.group_4.header
#std_msgs/Int16 pose_id
#std_msgs/Int16 pose_id_max
#sensor_msgs/CompressedImage image_left
#sensor_msgs/CompressedImage image_right
#geometry_msgs/Pose spin_center_pose
#sensor_msgs/PointCloud2 carmine_pointcloud
#geometry_msgs/Pose carmine_pose
#sensor_msgs/PointCloud2 bumblebee_pointcloud
#geometry_msgs/Pose bumblebee_pose_left
#geometry_msgs/Pose bumblebee_pose_right
msg = CompressedImage()
msg.header.stamp = rospy.Time.now()
msg.format = "jpeg"
msg.data = np.array(cv2.imencode('.jpg', left_gray)[1]).tostring()
# Publish new image
group_4_out.image_left = msg
msg = CompressedImage()
msg.header.stamp = rospy.Time.now()
msg.format = "jpeg"
msg.data = np.array(cv2.imencode('.jpg', gray_image)[1]).tostring()
# Publish new image
group_4_out.image_right = msg
#group_4_out.bumblebee_pointcloud = pcloud
self.pub_group.publish(group_4_out)
print "save time", time.clock() - s_t
示例2: stream
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
"""
示例3: callback
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例4: grabAndPublish
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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))
示例5: publish
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例6: __init__
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例7: grabAndPublish
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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
示例8: ros_compressed_from_numpygray
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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
示例9: handle_pkt
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例10: pubOriginal
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例11: sendTestImage
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例12: cv2_to_compressed_ros
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例13: pubOrig
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
def pubOrig(self, args=None):
image_msg_out = CompressedImage()
image_msg_out.header.stamp = rospy.Time.now()
image_msg_out.format = "png"
image_msg_out.data = np.array(cv2.imencode('.png',
self.original_image)[1]).tostring()
self.pub_image.publish(image_msg_out)
rospy.loginfo("Publishing original image")
示例14: processImage
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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)
示例15: stream
# 需要导入模块: from sensor_msgs.msg import CompressedImage [as 别名]
# 或者: from sensor_msgs.msg.CompressedImage import data [as 别名]
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))