Retrieving and visualizing Point Cloud from a kinect v1 [closed]

asked 2019-04-05 20:11:05 -0500

JavierRubioR gravatar image

updated 2019-04-05 21:43:14 -0500

jayess gravatar image

Hello guys, thanks in advance.

Im new to point cloud and first of all i need to complete a program able to retrieve some point cloud in real time with my kinect and to visualize them. I found some tutorials using OpeNNI Grabber, but the one I found It gives me the point cloud inversed. I would like to get a program that retrieve Point Cloud without the use of a grabber so i can learn better how to manage with Point Clouds. Anyways im posting the code im using but that doesnt work

#include <opencv2/highgui/highgui.hpp>
#include <pcl/io/openni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <pcl/console/parse.h>
#include <boost/shared_ptr.hpp>
#include <pcl/visualization/pcl_visualizer.h>

#include <iostream>

using namespace std;
using namespace pcl;

PointCloud<PointXYZRGBA>::Ptr cloudptr(new PointCloud<PointXYZRGBA>); // A cloud that will store colour info.
PointCloud<PointXYZ>::Ptr fallbackCloud(new PointCloud<PointXYZ>);    // A fallback cloud with just depth data.
pcl::visualization::PCLVisualizer::Ptr viewer;

Grabber* openniGrabber;                                               // OpenNI grabber that takes data from the device.
unsigned int filesSaved = 0;                                          // For the numbering of the clouds saved to disk.
bool saveCloud(false), noColor(false);                                // Program control.


void
printUsage(const char* programName)
{
        cout << "Usage: " << programName << " [options]"
                 << endl
                 << endl
                 << "Options:\n"
                 << endl
                 << "\t<none>     start capturing from an OpenNI device.\n"
                 << "\t-v FILE    visualize the given .pcd file.\n"
                 << "\t-h         shows this help.\n";
}

// This function is called every time the device has new data.
void
grabberCallback(const PointCloud<PointXYZRGBA>::ConstPtr& cloud)
{
        if (!viewer->wasStopped())

                viewer->addPointCloud (cloud, "sample cloud",0);


        if (saveCloud)
        {
                stringstream stream;
                stream << "inputCloud" << filesSaved << ".pcd";
                string filename = stream.str();
                if (io::savePCDFile(filename, *cloud, true) == 0)
                {
                        filesSaved++;
                        cout << "Saved " << filename << "." << endl;
                }
                else PCL_ERROR("Problem saving %s.\n", filename.c_str());

                saveCloud = false;
        }
}

// For detecting when SPACE is pressed.
void
keyboardEventOccurred(const visualization::KeyboardEvent& event,
                                          void* nothing)
{
        if (event.getKeySym() == "space" && event.keyDown())
                saveCloud = true;
}

// Creates, initializes and returns a new viewer.
boost::shared_ptr<visualization::PCLVisualizer>createViewer()
{

        pcl::visualization::PCLVisualizer::Ptr v (new pcl::visualization::PCLVisualizer ("3D Viewer"));
        v->addCoordinateSystem(1.0);
        v->registerKeyboardCallback(keyboardEventOccurred);
        v->resetCameraViewpoint("cloudreset");


        return (v);
}




int
main(int argc, char** argv)
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);


        if (console::find_argument(argc, argv, "-h") >= 0)
        {
                printUsage(argv[0]);
                return -1;
        }

        bool justVisualize(false);
        string filename;
        if (console::find_argument(argc, argv, "-v") >= 0)
        {
                if (argc != 3)
                {
                        printUsage(argv[0]);
                        return -1;
                }

                filename = argv[2];
                justVisualize = true;
        }
        else if (argc != 1)
        {
                printUsage(argv[0]);
                return -1;
        }

        // First mode, open and show a cloud from disk.
        if (justVisualize)
        {
                // Try with color information...
                try
                {
                }
                catch (PCLException e1)
                {
                        try
                        {
                                // ...and if it fails, fall back to just depth.
                                io::loadPCDFile<PointXYZ>(filename.c_str(), *fallbackCloud);

                        }
                        catch (PCLException e2)
                        {
                                return -1;
                        }

                        noColor = true;
                }

                cout << "Loaded " << filename << "." << endl;
                if (noColor)
                        cout << "This cloud has no RGBA color information present." << endl;
                else cout << "This cloud has RGBA color information present." << endl;
        }
        // Second mode, start fetching and displaying frames from the device.
        else
        {
                openniGrabber = new OpenNIGrabber();
                if (openniGrabber == 0)
                        return -1;
                boost::function ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason PCL Question: The PCL community prefers to answer questions at http://www.pcl-users.org/ by gvdhoorn
close date 2019-04-06 03:04:58.028012

Comments

This would appear to be a non-ROS question, but a PCL one. This forum is for ROS-related questions, and as we currently already have 45000+ questions, we need to keep on-topic.

gvdhoorn gravatar imagegvdhoorn ( 2019-04-06 03:06:04 -0500 )edit