本文整理汇总了Python中cv_bridge.CvBridgeError方法的典型用法代码示例。如果您正苦于以下问题:Python cv_bridge.CvBridgeError方法的具体用法?Python cv_bridge.CvBridgeError怎么用?Python cv_bridge.CvBridgeError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv_bridge
的用法示例。
在下文中一共展示了cv_bridge.CvBridgeError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback_image
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def callback_image(data):
# et = time.time()
try:
cv_image = cv_bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError as e:
rospy.logerr('[tf-pose-estimation] Converting Image Error. ' + str(e))
return
acquired = tf_lock.acquire(False)
if not acquired:
return
try:
global scales
humans = pose_estimator.inference(cv_image, scales)
finally:
tf_lock.release()
msg = humans_to_msg(humans)
msg.image_w = data.width
msg.image_h = data.height
msg.header = data.header
pub_pose.publish(msg)
# rospy.loginfo(time.time() - et)
示例2: gCamera
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [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)
示例3: extractInfo
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def extractInfo(self):
try:
while not self.exit:
try:
frame = self.frame_queue.get(block=True, timeout=1)
except queue.Empty:
print("Queue empty")
continue
try:
# Publish new image
msg = self.bridge.cv2_to_imgmsg(frame, 'rgb8')
if not self.exit:
self.image_publisher.publish(msg)
except CvBridgeError as e:
print("Error Converting cv image: {}".format(e.message))
self.frame_num += 1
except Exception as e:
print("Exception after loop: {}".format(e))
raise
示例4: __init__
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [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()
示例5: write_image
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def write_image(bridge, outdir, msg, fmt='png'):
results = {}
image_filename = os.path.join(outdir, str(msg.header.stamp.to_nsec()) + '.' + fmt)
try:
if hasattr(msg, 'format') and 'compressed' in msg.format:
buf = np.ndarray(shape=(1, len(msg.data)), dtype=np.uint8, buffer=msg.data)
cv_image = cv2.imdecode(buf, cv2.IMREAD_ANYCOLOR)
if cv_image.shape[2] != 3:
print("Invalid image %s" % image_filename)
return results
results['height'] = cv_image.shape[0]
results['width'] = cv_image.shape[1]
# Avoid re-encoding if we don't have to
if check_format(msg.data) == fmt:
buf.tofile(image_filename)
else:
cv2.imwrite(image_filename, cv_image)
else:
cv_image = bridge.imgmsg_to_cv2(msg, "bgr8")
cv2.imwrite(image_filename, cv_image)
except CvBridgeError as e:
print(e)
results['filename'] = image_filename
return results
示例6: depthCB
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def depthCB(self, depth):
if self.record == True:
#rospy.loginfo("depth image recieved")
try:
grey = self.bridge.imgmsg_to_cv2(depth)
rospy.loginfo(grey.dtype)
if self.twist is not None:
fnamedepth = None
seq = str(depth.header.seq)
timestamp = str(depth.header.stamp)
with self.twistLock:
fnamedepth = seq + '_' + timestamp + '_' + str(round(self.twist.linear.x,8)) + '_' + str(round(self.twist.angular.z,8))
cv2.imwrite("/home/ubuntu/DepthIMG/"+fnamedepth+".tiff",grey)
except CvBridgeError as x:
print(x)
else:
rospy.loginfo("Not Recording Depth")
示例7: lidargridCB
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def lidargridCB(self, grid):
if self.record == True:
#rospy.loginfo("grid recieved")
try:
cv2lidarImg = self.bridge.imgmsg_to_cv2(grid)
if self.twist is not None:
fnamelidar = None
timestamp = str(grid.header.stamp)
seq = str(grid.header.seq)
with self.twistLock:
fnamelidar = seq + '_' + timestamp + '_' + str(round(self.twist.linear.x,8)) + '_' + str(round(self.twist.angular.z,8))
cv2.imwrite("/home/ubuntu/LidarIMG/"+fnamelidar+".jpg",cv2lidarImg)
except CvBridgeError as r:
print(r)
else:
rospy.loginfo("Not Recording Lidar")
示例8: streamCB
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def streamCB(self, pic):
if self.record == True:
#rospy.loginfo("image recieved")
try:
cv2image = self.bridge.imgmsg_to_cv2(pic)
if self.twist is not None:
fname = None
seq = str(pic.header.seq)
timestamp = str(pic.header.stamp)
with self.twistLock:
fname = seq + '_' + timestamp + '_' + str(round(self.twist.linear.x,8)) + '_' + str(round(self.twist.angular.z,8))
cv2.imwrite("/home/ubuntu/TrainingIMG/"+fname+".jpg",cv2image)
except CvBridgeError as e:
print(e)
else:
rospy.loginfo("Not Recording Webcam")
示例9: depth_callback
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def depth_callback(self, msg):
# create OpenCV depth image using defalut passthrough encoding
try:
depth_image = self.bridge.imgmsg_to_cv2(msg, desired_encoding='passthrough')
except CvBridgeError as e:
print(e)
# using green ball (u, v) position, find depth value of Crazyflie point and divide by 1000
# to change millimeters into meters (for Kinect sensors only)
self.cf_d = depth_image[self.cf_v, self.cf_u] / 1000.0
rospy.loginfo("Depth: x at %d y at %d z at %f", int(self.cf_u), int(self.cf_v), self.cf_d)
# if depth value is zero, use the last non-zero depth value
if self.cf_d == 0:
self.cf_d = self.last_d
else:
self.last_d = self.cf_d
# publish Crazyflie tf transform
self.update_cf_transform (self.cf_u, self.cf_v, self.cf_d)
# This function builds the Crazyflie base_link tf transform and publishes it.
示例10: imageCallback
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def imageCallback(self, msg):
try:
# Convert your ROS Image message to OpenCV
cv2_img = bridge.imgmsg_to_cv2(msg, "rgb8")
if self.first_msg:
shape = cv2_img.shape
min_length = min(shape[0], shape[1])
up_margin = int((shape[0] - min_length) / 2) # row
left_margin = int((shape[1] - min_length) / 2) # col
self.valid_box = [up_margin, up_margin + min_length, left_margin, left_margin + min_length]
print("origin size: {}x{}".format(shape[0],shape[1]))
print("crop each image to a square image, cropped size: {}x{}".format(min_length, min_length))
self.first_msg = False
undistort_image = cv2.undistort(cv2_img, self.camera_matrix, self.distortion_coefficients)
self.valid_img = undistort_image[self.valid_box[0]:self.valid_box[1], self.valid_box[2]:self.valid_box[3]]
except CvBridgeError as e:
print("CvBridgeError:", e)
示例11: _rgbCb
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def _rgbCb(self, msg):
if msg is None:
rospy.logwarn("_rgbCb: msg is None !!!!!!!!!")
try:
# max out at 10 hz assuming 30hz data source
if msg.header.seq % 3 == 0:
cv_image = self._bridge.imgmsg_to_cv2(msg, "rgb8")
# decode the data, this will take some time
# rospy.loginfo('rgb color cv_image shape: ' + str(cv_image.shape) + ' depth sequence number: ' + str(msg.header.seq))
# print('rgb color cv_image shape: ' + str(cv_image.shape))
cv_image = cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB)
rgb_img = cv2.imencode('.jpg', cv_image)[1].tobytes()
# rgb_img = GetJpeg(np.asarray(cv_image))
with self.mutex:
self.rgb_time = msg.header.stamp
self.rgb_img = rgb_img
#print(self.rgb_img)
except CvBridgeError as e:
rospy.logwarn(str(e))
示例12: callback_image
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def callback_image(data):
# et = time.time()
try:
cv_image = cv_bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError as e:
rospy.logerr('[tf-pose-estimation] Converting Image Error. ' + str(e))
return
acquired = tf_lock.acquire(False)
if not acquired:
return
try:
humans = pose_estimator.inference(cv_image, resize_to_default=True, upsample_size=resize_out_ratio)
finally:
tf_lock.release()
msg = humans_to_msg(humans)
msg.image_w = data.width
msg.image_h = data.height
msg.header = data.header
pub_pose.publish(msg)
示例13: get_frames
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def get_frames(self):
cv_image = None
depth_image = None
while cv_image is None and depth_image is None:
try:
cv_image = self.bridge.imgmsg_to_cv2(self.rgb_raw, "bgr8")
except CvBridgeError as e:
print(e)
try:
depth_image_raw = self.bridge.imgmsg_to_cv2(self.depth_raw, "passthrough")
# noinspection PyRedundantParentheses
depth_image = ((255 * depth_image_raw)).astype(np.uint8)
except CvBridgeError as e:
print(e)
if self.debug:
print("Image has been converted.")
return cv_image, depth_image
示例14: _process_image_msg
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def _process_image_msg(self, msg):
""" Process an image message and return a numpy array with the image data
Returns
-------
:obj:`numpy.ndarray` containing the image in the image message
Raises
------
CvBridgeError
If the bridge is not able to convert the image
"""
encoding = msg.encoding
try:
image = self._bridge.imgmsg_to_cv2(msg, encoding)
except CvBridgeError as e:
rospy.logerr(e)
return image
示例15: callback_image
# 需要导入模块: import cv_bridge [as 别名]
# 或者: from cv_bridge import CvBridgeError [as 别名]
def callback_image(self, data):
try:
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError as e:
rospy.logerr('Converting Image Error. ' + str(e))
return
self.frames.append((data.header.stamp, cv_image))