dot_2_3d.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('blob3d')
00003 import rospy
00004 from cv_bridge import CvBridge
00005 from sensor_msgs.msg import PointCloud2, Image, CameraInfo, PointField
00006 from projector_interface._point_cloud import read_points_np, create_cloud_np
00007 import image_geometry
00008 import numpy as np
00009 import cv2, cv
00010 
00011 blobs = []
00012 depth = None
00013 depth_header = None
00014 bridge = None
00015 point = None
00016 model = None
00017 
00018 def process(im):
00019     # convert to Luv
00020     imluv = cv2.cvtColor(im, cv.CV_RGB2Luv)
00021     # get channels
00022     l,u,v = cv2.split(imluv)
00023     r,g,b = cv2.split(im)
00024     minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(0.9*v + 0.1*g)
00025     # minG, maxG, minLocG, maxLocG = cv2.minMaxLoc(g)
00026     return maxLoc
00027 
00028 def image_cb(msg):
00029     global point
00030     im = np.asarray(bridge.imgmsg_to_cv(msg, "passthrough"))
00031     point = process(im)
00032 
00033 def depth_cb(msg):
00034     global depth, depth_header
00035     depth = np.asarray(bridge.imgmsg_to_cv(msg, "passthrough"))
00036     depth_header = msg.header
00037     
00038 def info_cb(msg):
00039     global model
00040     tmp_model = image_geometry.PinholeCameraModel()
00041     tmp_model.fromCameraInfo(msg)
00042     model = tmp_model
00043 
00044 if __name__ == '__main__':
00045     rospy.init_node('dot_2_3d')
00046     bridge = CvBridge()
00047     rospy.Subscriber('image', Image, image_cb)
00048     rospy.Subscriber('depth_image', Image, depth_cb)
00049     rospy.Subscriber('camera_info', CameraInfo, info_cb)
00050     cloud_pub = rospy.Publisher('dot_cloud', PointCloud2)
00051     
00052     fields = [
00053         PointField('x', 0, PointField.FLOAT32, 1),
00054         PointField('y', 4, PointField.FLOAT32, 1),
00055         PointField('z', 8, PointField.FLOAT32, 1)
00056     ]
00057     
00058     rate = rospy.Rate(10)
00059     while not rospy.is_shutdown():
00060         if (not point) or (depth is None) or (model is None):
00061             continue
00062         blob_pts = []
00063         point3 = np.array(model.projectPixelTo3dRay(point)) * depth[point[1],point[0]]
00064         blob_pts.append(point3)
00065         
00066         out_cloud = create_cloud_np(depth_header, fields, np.array(blob_pts))
00067         cloud_pub.publish(out_cloud)
00068         rate.sleep()


blob3d
Author(s): robotics
autogenerated on Mon Oct 6 2014 10:21:51