kinect-kinectv1(gazebo)彩色图和灰度图配准验证

1、kinectv1在gazebo中的配置文件
kinect-kinectv1(gazebo)彩色图和灰度图配准验证_第1张图片
2、在灰度图中选取的轮廓,与彩色图中的对应物体完全吻合
代码:
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2 as cv
import numpy as np

class rgb_depth_get():
def init(self):
self.node_name = “rgb_depth_get”
self.bridge = CvBridge()
rospy.init_node(self.node_name)
rgb_image,depth_image=self.rgb_depth_get()
rgb_image,depth_image = self.rgb_depth_get()#再次读取深度图,刷新图片变量,不然灰度图显示的是之前的图片

    # depth_temp_image=depth_image.copy()
    dst = np.zeros((480,640), np.uint8)

    for i in range(depth_image.shape[0]):
        for j in range(depth_image.shape[1]):
            if depth_image[i][j]<0.68:
                dst[i][j]=0
            else:
                dst[i][j]=255
    outline_img1, contours, hierarchy1 = cv.findContours(dst, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
    cv.drawContours(rgb_image, contours, 1, (0, 255, 0), 1)
    # print rgb_image.shape,depth_image.shape
    # print depth_image
    # print depth_image[276][319]
    cv.imshow("rgb_image",rgb_image)
    # cv.imshow("depth_image",depth_image)
    cv.imshow("dst", dst)
    cv.waitKey(0)


def rgb_depth_get(self):
    ros_rbg_image = rospy.wait_for_message("/camera/rgb/image_rect_color", Image, timeout=None)
    ros_depth_image = rospy.wait_for_message("/camera/depth_registered/image_raw", Image, timeout=None)
    rgb_frame = self.bridge.imgmsg_to_cv2(ros_rbg_image, "bgr8")
    depth_frame = self.bridge.imgmsg_to_cv2(ros_depth_image, "32FC1")
    return rgb_frame,depth_frame

def main():
rgb_depth_get()

if name == ‘main’:
main()

3、结果
kinect-kinectv1(gazebo)彩色图和灰度图配准验证_第2张图片
kinect-kinectv1(gazebo)彩色图和灰度图配准验证_第3张图片

你可能感兴趣的:(kinect)