-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenni_viewer.cpp
121 lines (103 loc) · 3.1 KB
/
openni_viewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/search/search.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/convex_hull.h>
#include <pcl/surface/concave_hull.h>
#include <pcl/surface/gp3.h>
#include <pcl/io/openni_camera/openni_driver.h>
#include "Calibrator.h"
#include "RobotDetector.h"
//#include "typedefs.h"
#include <iostream>
using namespace pcl::search;
using namespace openni_wrapper;
using namespace pcl;
using namespace std;
#define STREAM_FROM_CAMERA
class SimpleOpenNIViewer
{
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
Calibrator calibrator;
RobotDetector robotDetector;
bool Calibrated;
void DoProcessings(const PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud)
{
// viewer.showCloud (Cloud);
if(!Calibrated)
{
calibrator.SetCloud(cloud);
Calibrated = calibrator.Calibrate();
robotDetector.setCalibrationConfigs(calibrator.getPlane(),calibrator.getLandmark());
}
if(Calibrated)
{
robotDetector.SetCloud(cloud);
robotDetector.Detect();
boost::function<void (pcl::visualization::PCLVisualizer&)> f =
boost::bind (&RobotDetector::Debug3D, robotDetector, _1);
viewer.runOnVisualizationThreadOnce (f);
}
}
void cloud_cb_(const PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud)
{
if (!viewer.wasStopped())
{
DoProcessings(cloud);
//viewer.showCloud (cloud);
//cv::Mat frameRGB=cv::Mat(cloud->width,cloud->height,CV_8UC3);
//XYZRGB2IPL(cloud, frameRGB);
//IplImage *imagen = new IplImage(frameRGB);
// pcl::io::savePCDFileASCII ("testXYZRGB.pcd", *cloud);
}
}
void run ()
{
Calibrated = false;
#ifdef STREAM_FROM_CAMERA
OpenNIDriver &driver = OpenNIDriver::getInstance();
unsigned int deviceNum = driver.getNumberDevices();
pcl::Grabber** interface = new pcl::Grabber*[deviceNum];
for(int i=0;i<deviceNum;i++)
{
char a[2];
a[0] = '1' + i;
a[1] = 0;
interface[i] = new pcl::OpenNIGrabber(string("#") + string(a),pcl::OpenNIGrabber::OpenNI_VGA_30Hz,pcl::OpenNIGrabber::OpenNI_VGA_30Hz);
}
boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
for(int i=0;i<deviceNum;i++)
{
interface[i]->registerCallback(f);
interface[i]->start();
}
#else
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr Cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile<pcl::PointXYZRGBA> ("RobotOnCross.pcd", *Cloud);
// Cloud = smoothPointCloud(Cloud,0.01,3);
DoProcessings(Cloud);
viewer.showCloud (robotDetector.RobotCloud);
RobotDetector robotDetector(Cloud);
robotDetector.Detect();
#endif
while (!viewer.wasStopped())
{
boost::this_thread::sleep (boost::posix_time::seconds (1));
}
#ifdef STREAM_FROM_CAMERA
for(int i=0;i<deviceNum;i++)
interface[i]->stop ();
#endif //STREAM_FROM_CAMERA
}
pcl::visualization::CloudViewer viewer;
};
int main()
{
SimpleOpenNIViewer v;
v.run ();
return 0;
}