Kinect v2 - PCD save error.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Kinect v2 - PCD save error.

AIS_stain
This post was updated on .
Hello. I am PCL user in Korea.
My OS is windows 8.1, and PCL version is 1.8.0, visual studio 2013
community.

I'm using kinect v2, and grabber for kinect2.
(grabber site : http://unanancyowen.com/en/pcl-kinectv2-with-grabber/)

And... I have some issue.

Kinect v2 is working well. it can visualize, and update everytime.
<http://www.pcl-users.org/file/t499195/kinect_is_working_-_well.png

but I'm fail to save visualized data to PCD data...
Actually, it saved. But PCD data is empty.
<http://www.pcl-users.org/file/t499195/PCD_is_empty.png

But save data is successfully copyed.
<http://www.pcl-users.org/file/t499195/copy_is_working.png

I'm so confused... PCL tutorial is wrong? or Grabber is not working?
But Kinect is Visualizing well. I think Kinect is not an issue...

I don't know how can i use it...
I have to save PCD data to model, scene pcd data... and using PCD data to 3D
object recognition...

and my code is here.
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS

#include "stdafx.h"

#include "kinect2_grabber.h"

// Simple OpenNI viewer that also allows to write the current scene to a .pcd
// when pressing SPACE.

#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>

#include <iostream>

using namespace std;
using namespace pcl;

PointCloud<PointXYZRGB>::Ptr cloudptr(new PointCloud<PointXYZRGB>); // A cloud that will store color info.
PointCloud<PointXYZRGB>::Ptr fallbackCloud(new PointCloud<PointXYZRGB>);    // A fallback cloud with just depth data.
boost::shared_ptr<visualization::CloudViewer> viewer;                 // Point cloud viewer object.
Grabber* openni2Grabber;                                               // 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(true);                                // Program control.
int test = 0;


// This function is called every time the device has new data.
void
grabberCallback(const PointCloud<PointXYZRGB>::ConstPtr& cloud)
{
       
        if (!viewer->wasStopped()){
                viewer->showCloud(cloud);
        }
       
        if (test == 1) cout << "grabber call back in" << endl;


        if (saveCloud)
        {
                cout << "save trigger on" << endl;
               
                stringstream stream;
                stream << "inputCloud" << filesSaved << ".pcd";
                string filename = stream.str();

                pcl::PointCloud<pcl::PointXYZRGB> cloud2;
                copyPointCloud(*cloud, cloud2);
                //*cloud2 = *cloud;
               
                cloud2.width = cloud->width;
                cloud2.height = cloud->height;
                cloud2.is_dense = false;
                cloud2.points.resize(cloud2.width * cloud2.height);
               
                if (pcl::io::savePCDFileASCII("001.pcd", *cloud) == 0) // savePCDFileASCII - 예제 참조 필요.
                {
                        cout << "cloud  : width, height, is_dense, size" << "      " << cloud->width << "      " << cloud->height << "      " << cloud->is_dense << "      " << cloud->size() << endl << endl;
                        cout << "cloud2 : width, height, is_dense, size" << "      " << cloud2.width << "      " << cloud2.height << "      " << cloud2.is_dense << "      " << cloud2.size() << endl << endl;
                        filesSaved++;
                        //cout << "Saved " << filename << "." << endl;
                        cout << "Saved 001.pcd" << endl;
                }
                else {
                        cout << "save error" << endl;
                }

                saveCloud = false;
        }

}

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

// Creates, initializes and returns a new viewer.
boost::shared_ptr<visualization::CloudViewer>
createViewer()
{
        boost::shared_ptr<visualization::CloudViewer> v
        (new visualization::CloudViewer("kinect 2 viewer"));
        v->registerKeyboardCallback(keyboardEventOccurred);

        return (v);
}

int
main(int argc, char** argv)
{
        openni2Grabber = new Kinect2Grabber();
       

        if (openni2Grabber == 0)
        {
                cout << "grabber error" << endl;
        }

        if(test ==1) cout << "Grabber set" << endl;
                boost::function<void(const PointCloud<PointXYZRGB>::ConstPtr&)> f = boost::bind(&grabberCallback, _1);

        openni2Grabber->registerCallback(f);
        if (test == 1) cout << "register call back end" << endl;

        viewer = createViewer();
        openni2Grabber->start();

        // Main loop.
        while (1) {
                if (!viewer->wasStopped() ==0) break;
                boost::this_thread::sleep(boost::posix_time::milliseconds(30));
        }
        openni2Grabber->stop();
}
Reply | Threaded
Open this post in threaded view
|

Re: Kinect v2 - PCD save error.

Sérgio Agostinho

Is this just happening with point clouds coming from the grabber? Can you get a valid PCD file with a handcrafted point cloud? Does this tutorial generate a valid pcd file at the end for instance?

Cheers



_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Kinect v2 - PCD save error.

AIS_stain
Hello.
thank you for your reply
i'm sure it can. I had some test.
if i use tutorial, saveFilePCD is working very well.

But if i use saveFilePCD to get Kinect v2 cloud data, it doesn't work.

Output PCD data is Empty. Header and cloud info is gone.

But using PCL, Kinect v2's FOV can be visualized.
so... Kinect v2 is fine...

I think pcl's io - PCD writer has some issue... it can't get header info
from visualizing pointer variable.

Please help me...

regards.



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Kinect v2 - PCD save error.

Sérgio Agostinho
> I think pcl's io - PCD writer has some issue... it can't get header info
> from visualizing pointer variable.
I would be somewhat surprised if this was the case. It's a method almost
everyone uses every now and then.

>
> I think pcl's io - PCD writer has some issue... it can't get header info
> from visualizing pointer variable.
Did you compile PCL with debug symbols? I don't think you're gonna see
much without those.

> Please help me...
I don't there's much help I can provide other than recommend to compile
everything in debug mode, stop your debugger right before you save the
file and then run things step by step checking each variable's content.
At some point you'll bump into the problem.

Cheers




_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

signature.asc (836 bytes) Download Attachment