本文整理汇总了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)
示例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)
示例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)
"""
示例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)
示例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)
示例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
示例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
示例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))
示例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)
示例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)
示例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)
示例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)
示例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))
示例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)
示例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))