Ask Your Question

lakshmen's profile - activity

2017-11-16 10:15:53 -0600 received badge  Nice Question (source)
2017-10-05 02:29:53 -0600 received badge  Student (source)
2014-04-20 06:47:39 -0600 marked best answer Getting point cloud data from the kinect

hi guys, i am new to kinect. I need point cloud data from the depth camera in kinect. Any of you have any idea how to go about doing it? i am using ROS diamondback and Ubuntu.

2014-01-28 17:22:30 -0600 marked best answer How does cloud_to_laserscan.cpp work

I have some more qns regarding cloud_to_scan.cpp. the post was previously posted[http://answers.ros.org/question/1561/doubts-about-pointcloud-to-laser-scan] but it was not answered. I am in need of urgent help.

Qn 1)if (output->ranges[index] * output->ranges[index] > range_sq) output->ranges[index] = sqrt(range_sq);, what is this statement trying to do.. not that sure...

qn 2) is the x, y and z in metres?or what are the units for the x,y and z?

qn 3) why is the angle = -atan2(x,z) and not angle = -atan2(z,x)

2014-01-28 17:22:28 -0600 marked best answer From Laserscan to obstacle avoidance

I have got the laser scan from the kinect using the openni_driver. Now i would like to use it for obstacle avoidance. For obstacle avoidance, i am using vector field histogram. Any suggestions or directions i could take?

2014-01-28 17:22:26 -0600 marked best answer Doubts about pointcloud to laser scan

I was referred to this code previously. I have some doubts about this code, like to clarify some of them.

#include "ros/ros.h"
#include "pluginlib/class_list_macros.h"
#include "nodelet/nodelet.h"
#include "sensor_msgs/LaserScan.h"
#include "pcl/point_cloud.h"
#include "pcl_ros/point_cloud.h"
#include "pcl/point_types.h"
#include "pcl/ros/conversions.h"




namespace pointcloud_to_laserscan
{
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;

class CloudToScan : public nodelet::Nodelet
{
public:
  //Constructor
  CloudToScan(): min_height_(0.10), max_height_(0.15), u_min_(100), u_max_(150), output_frame_id_("/openi_depth_frame")
  {
  };

private:
  virtual void onInit()
  {
    ros::NodeHandle& nh = getNodeHandle();
    ros::NodeHandle& private_nh = getPrivateNodeHandle();

    private_nh.getParam("min_height", min_height_);
    private_nh.getParam("max_height", max_height_);

    private_nh.getParam("row_min", u_min_);
    private_nh.getParam("row_max", u_max_);

    private_nh.getParam("output_frame_id", output_frame_id_);
    pub_ = nh.advertise<sensor_msgs::LaserScan>("scan", 10);
    sub_ = nh.subscribe<PointCloud>("cloud", 10, &CloudToScan::callback, this);
  };

  void callback(const PointCloud::ConstPtr& cloud)
  {
    sensor_msgs::LaserScanPtr output(new sensor_msgs::LaserScan());
    NODELET_DEBUG("Got cloud");
    //Copy Header
    output->header = cloud->header;
    output->header.frame_id = output_frame_id_;
    output->angle_min = -M_PI/2;
    output->angle_max = M_PI/2;
    output->angle_increment = M_PI/180.0/2.0;
    output->time_increment = 0.0;
    output->scan_time = 1.0/30.0;
    output->range_min = 0.45;
    output->range_max = 10.0;

    uint32_t ranges_size = std::ceil((output->angle_max - output->angle_min) / output->angle_increment);
    output->ranges.assign(ranges_size, output->range_max + 1.0);

    //pcl::PointCloud<pcl::PointXYZ> cloud;
    //pcl::fromROSMsg(*input, cloud);

    for (PointCloud::const_iterator it = cloud->begin(); it != cloud->end(); ++it)
    {
      const float &x = it->x;
      const float &y = it->y;
      const float &z = it->z;

    /*    for (uint32_t u = std::max((uint32_t)u_min_, 0U); u < std::min((uint32_t)u_max_, cloud.height - 1); u++)
      for (uint32_t v = 0; v < cloud.width -1; v++)
      {
        //NODELET_ERROR("%d %d,  %d %d", u, v, cloud.height, cloud.width);
        pcl::PointXYZ point = cloud.at(v,u); ///WTF Column major?
        const float &x = point.x;
        const float &y = point.y;
        const float &z = point.z;
    */  

      if ( std::isnan(x) || std::isnan(y) || std::isnan(z) )
      {
        NODELET_DEBUG("rejected for nan in point(%f, %f, %f)\n", x, y, z);
        continue;  
      }
      if (-y > max_height_ || -y < min_height_)
      {
        NODELET_DEBUG("rejected for height %f not in range (%f, %f)\n", x, min_height_, max_height_);
        continue;
      }
      double angle = -atan2(x, z);
      if (angle < output->angle_min || angle > output->angle_max)
      {
        NODELET_DEBUG("rejected for angle %f not in range (%f, %f)\n", angle, output->angle_min, output->angle_max);
        continue;
      }
      int index = (angle - output->angle_min) / output->angle_increment;
      //printf ("index xyz( %f %f %f) angle %f index %d\n", x, y, z, angle, index);
      double range_sq = z*z+x*x;
      if (output->ranges[index] * output->ranges[index] > range_sq)
        output->ranges[index] = sqrt(range_sq);


      }

    pub_.publish(output);
  }


  double min_height_, max_height_;
  int32_t u_min_, u_max_;
  std::string output_frame_id_;

  ros::Publisher pub_;
  ros::Subscriber sub_;

};


PLUGINLIB_DECLARE_CLASS(pointcloud_to_laserscan, CloudToScan, pointcloud_to_laserscan::CloudToScan, nodelet::Nodelet);
}

1) where does the M_PI/2 in the angle_min and angle_max come from?

2) why is it range_sq = x^2 + z^2? shldnt it be range_sq = y^2 + z^2?

correct me if i am wrong.. if x is the horizontal and y is the vertical, then z shld be in the negative direction(coming out of the image ... (more)

2014-01-28 17:22:26 -0600 marked best answer Problem launching pointcloud to laserscan

I am not able to launch the pointcloud to laserscan. I did this following steps:

1)launched the openni_camera by typing roslaunch openni_camera openni_node.launch

2)launched the pointcloud to laserscan by typing roslaunch pointcloud_to_laserscan kinect_laser.launch

3)ran rviz by typing rosrun rviz rviz

I am able to see the point cloud but I am not able to see the laser_scan. I was referring to this question,http://answers.ros.org/question/417/how-to-setup-pointcloud_to_laserscan. I am supposed to see /scan topic but i am not able to see it.

Am i supposed to change /openni_depth_frame?

Or what steps i shld take? Any suggestions?

Just like to check with you all.. is this sometime like this i should get?C:\fakepath\Screenshot-RViz-1.png

2014-01-28 17:22:25 -0600 marked best answer From point cloud to laser scan

Hi i can get the point cloud data from the OpenNI driver now, like to convert it into a laser scan.How do you do it? Any suggestions or directions that i can take?

2014-01-28 17:22:24 -0600 marked best answer Publishing data using OpenNI

Hi guys,

Although, i am able to find the depth pointer and find the depth value. Now i need to publish the data and want to visualize the point cloud in Rviz. I have written a code and would like to have your opinions.

    /* OpenCV Includes */
#include "opencv2\opencv.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

/* OpenNI Includes */
#include <XnCppWrapper.h>
#include <XnOpenNI.h>
#include <XnLog.h>
#include <XnOS.h>

/* PCL Includes */
#include "pcl/ModelCoefficients.h"
#include "pcl/console/parse.h"
#include "pcl/console/print.h"
#include "pcl/io/pcd_io.h"
#include "pcl/point_types.h"
#include <pcl/features/cvfh.h>
#include <pcl/features/vfh.h>
#include <pcl/features/normal_3d.h>
#include "pcl/filters/extract_indices.h"
#include "pcl/filters/passthrough.h"
#include "pcl/filters/statistical_outlier_removal.h"
#include "pcl/kdtree/kdtree.h"
#include "pcl/sample_consensus/method_types.h"
#include "pcl/sample_consensus/model_types.h"
#include "pcl/segmentation/sac_segmentation.h"
#include "pcl/segmentation/extract_clusters.h"
#include <boost/filesystem.hpp>

/* ROS Includes */
#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>

#define SAMPLE_XML_PATH "C:/Program Files (x86)/OpenNI/Data/SamplesConfig.xml"
#define X_RES 640
#define Y_RES 480
#define MAX_DEPTH 10000

using namespace std;
using namespace xn;
using namespace pcl::console;

/* Globals */
Context         context;
ImageGenerator      g_image;
DepthGenerator      d_image;
ImageMetaData       g_imageMD;
EnumerationErrors   errors;
XnStatus        nRetVal = XN_STATUS_OK;
unsigned short      depth[MAX_DEPTH];
char *depth_data;

/* Typedefs */
typedef pcl::PointCloud<pcl::PointXYZRGBNormal> PointCloud;

void raw2depth(){
  for (int i=0; i<MAX_DEPTH; i++) {
  float v = (float)i/MAX_DEPTH;//for visualization purposes only
  v = powf(v, 2);
  v = v*36*256;
  depth[i] = v;
  }
}

void depth2rgb(const XnDepthPixel* Xn_disparity){
  for (int i=0; i<307200; i++) {
    int pval = depth[Xn_disparity[i]];
    int lb = pval & 0xff;
    switch (pval>>8) {
      case 0:
        depth_data[3*i+0] = 255;
        depth_data[3*i+1] = 255;
        depth_data[3*i+2] = 255-lb;
        break;
      case 1:
        depth_data[3*i+0] = 255;
        depth_data[3*i+1] = lb;
        depth_data[3*i+2] = 0;
        break;
      case 2:
        depth_data[3*i+0] = 255-lb;
        depth_data[3*i+1] = 255;
        depth_data[3*i+2] = 0;
        break;
      case 3:
        depth_data[3*i+0] = 0;
        depth_data[3*i+1] = 255;
        depth_data[3*i+2] = lb;
        break;
      case 4:
        depth_data[3*i+0] = 0;
        depth_data[3*i+1] = 255-lb;
        depth_data[3*i+2] = 255;
        break;
      case 5:
        depth_data[3*i+0] = 0;
        depth_data[3*i+1] = 0;
        depth_data[3*i+2] = 255-lb;
        break;
      default:
        depth_data[3*i+0] = 0;
        depth_data[3*i+1] = 0;
        depth_data[3*i+2] = 0;
        break;
    }
  }
}


void rgbdInit(){
  //Initialize context object
  nRetVal = context.Init();
  if (nRetVal != XN_STATUS_OK){
    print_error("Failed to initialize context: %s\n", xnGetStatusString(nRetVal));
  }

  // Create a DepthGenerator node
  nRetVal = d_image.Create(context);
  if (nRetVal != XN_STATUS_OK){
    print_error("Failed to create depth generator: %s\n", xnGetStatusString(nRetVal));
  }

  // Create a ImageGenerator node
  nRetVal = g_image.Create(context);
  if (nRetVal != XN_STATUS_OK){
    print_error("Failed to create image generator: %s\n", xnGetStatusString(nRetVal));
  }

  // Make it start generating data
  nRetVal = context.StartGeneratingAll();
  if (nRetVal != XN_STATUS_OK){
    print_error("Failed generating data: %s\n", xnGetStatusString(nRetVal));
  }

/*  //Sync the DepthGenerator with the ImageGenerator
  nRetVal = d_image.GetFrameSyncCap().FrameSyncWith(g_image);
  if (nRetVal ...
(more)
2014-01-28 17:22:24 -0600 marked best answer Problem with opencv2

i need to include the following files:

#include "opencv2\opencv.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

but i always get this error. Opencv2\opencv.hpp: No such file or directory

what shld i do?

will adding this line <depend package="opencv2"/> solve the problem?

2014-01-28 17:22:23 -0600 marked best answer Problem setting fixed frame in Rviz.

I am already able to publish the data, in the sense that when i type the rostopic hz -> i get the topic that i am publishing. But have difficulty visualizing the data and moreover, i can't select anything under fixed frame and target frame.there is a global warning saying that is no tf data and that Fixed Frame does not exist. I now know i need to have to a launch file that converts static_transform_publisher from /world to /kinect_depth and set the fixed frame to /kinect_depth.

1)i am not sure where to add this file to?

2) there is a statement args = " 0 0 1.10 -1.57 0 -1.57 /world /kinect_rgb 10" what does the 10 stand for and what are the other values(such as 0, 1.1) for?

having those two questions answered, i got a few more to ask( i apologise if the qns are wrong)..

3) what should i type to launch the kinect_camera. is it roslaunch kinect_camera kinect_with_tf.launch? if so, it is wrong to type roscore only? 4) must u have always have a launch file? can u work without a launch file?

5)is better to use tf::transformbroadcaster or it is better to use just launch file?

Please pardon me for the qns.. i am newbie in ROS, point cloud. Any help would be much appreciated.. thanks...

for env | grep ROS i get

ROS_ROOT=/opt/ros/diamondback/ros
ROS_PACKAGE_PATH=/opt/ros/diamondback/stacks:/home/user/workspace
ROS_MASTER_URI=http://localhost:11311
2014-01-28 17:22:18 -0600 marked best answer How to obtain the R and T of the kinect camera?

I am not sure how to obtain the Rotation(R) and Translation(T) matrices for the kinect camera. How can i find it?

2014-01-28 17:22:18 -0600 marked best answer How to construct the point cloud data from the depth data

I have already acheived the depth data from the Kinect using the openkinect driver. I have already got the data for the x, y and z of the point cloud.Now, I need to plot point cloud data and would like to visualize it in rviz.How do i go about doing it?

Any help would be appreciated..

2014-01-28 17:22:15 -0600 marked best answer Getting Point cloud data from Openni driver

Previously, I posted how to get started on the point cloud data for the Openni. Many of you posted that i need to get through the tutorials for ROS to have a better understanding. I have done that now.One posted this code(for the subscriber) for me... which was very helpful.I have some qns on this code: 1) We need to have both a publisher and subscriber node for the Kinect in order to get point cloud data.Am i right to say that? 2) how do u get the depth data from the point cloud data?

Really need of help. I am sorry if i ask stupid questions.

    #include <ros/ros.h>
    #include <pcl_ros/point_cloud.h>
    #include <sensor_msgs/PointCloud2.h>

using namespace ros;
using namespace sensor_msgs;

class processPoint {
    NodeHandle nh;
    Subscriber sub;

public:
    processPoint() {
        sub = nh.subscribe<sensor_msgs::PointCloud2>("/camera/rgb/points", 1, &processPoint::processCloud, this);
    }

    ~processPoint() {   
     }

    void processCloud( const sensor_msgs::PointCloud2ConstPtr& cloud );
};

void processPoint::processCloud( const sensor_msgs::PointCloud2ConstPtr& cloud ) {

}

int main(int argc, char **argv) {

    init(argc, argv, "processPoint");

    processPoint processPoint;

    Rate spin_rate(1);

    while( ok() ) {
        spinOnce();

        spin_rate.sleep();
    }
}
2014-01-28 17:22:14 -0600 marked best answer Problem with installing the Openni_kinect

when i try to install the openni_kinect, i face a few problems...

when i type: rosinstall ~/openni_kinect PATH_TO_EXISTING_ROS_TREE 'http://www.ros.org/wiki/openni_kinect?action=AttachFile&do=get&target=openni_kinect.rosinstall'

i get this as the answer: E: rosinstall operating on /home/user/openni_kinect from specifications in rosinstall files PATH_TO_EXISTING_ROS_TREE, http://www.ros.org/wiki/openni_kinect... ahhhh error opening file: [Errno 2] No such file or directory: '/home/user/drivers/PATH_TO_EXISTING_ROS_TREE' Usage: rosinstall PATH [ ...] [URI]...

rosinstall: error: None

what should i do?

2014-01-28 17:22:12 -0600 marked best answer Kinect Depth calculation

Sorry guys, i am desperate for answer. That is why i didn't follow the rules of this website. I sincerly apologise. For this code, i have come up with a better one. float cx = 320.0; float cy = 240.0; float minDistance = -10; float scaleFactor = 0.0021;

for (int v=0, n=0 ; v<480 ; v++) 
    {
        for (int u=0 ; u<640 ; u++, n++)
        {
                Vec3f result;
                result.x = float(((u - cx) * t_gamma[depth[n]]+ minDistance)   * scaleFactor * (cx/cy));
                result.y = float(((v - cy) * t_gamma[depth[n]]+ minDistance)   * scaleFactor);
                result.z = float(t_gamma[depth[n]]);


        }

    }   


// OS X requires GLUT to run on the main thread
gl_threadfunc(NULL);


return 0;

} is this code better? i have tried to save the depth data but all the data is zero. I don't know where is the problem?

2014-01-28 17:22:11 -0600 marked best answer Vector field histogram.

Any of you have used vector field histogram?I am trying to combine the Kinect and the vector field histogram but not sure how to do it. Any help would be appreciated.