-
Notifications
You must be signed in to change notification settings - Fork 9
/
pcl_multi_object_recognition.cpp
84 lines (67 loc) · 2.75 KB
/
pcl_multi_object_recognition.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
#include <thread>
#include "find_function.h"
#include "OpenniStreamer.h"
#include "Visualizer.h"
int
main (int argc, char** argv)
{
// Parse input and set algorithm variables
ParseCommandLine (argc, argv);
pcl::PointCloud<PointType>::Ptr scene (new pcl::PointCloud<PointType> ());
pcl::PointCloud<PointType>::Ptr complete_scene (new pcl::PointCloud<PointType> ());
std::vector<float> * filters = new std::vector<float>();
std::vector<int> * icp_iterations = new std::vector<int>();
// Load the input model (n models but for now only one is used)
std::vector < pcl::PointCloud < PointType > ::Ptr > model_list = ReadModels (argv, *filters, *icp_iterations);
if (model_list.size () == 0) {
std::cout << " no models loaded " << std::endl;
return 1;
}
// Check if an oni file is specified as input or if the camera stream has to be used and initialize the correct stream.
OpenniStreamer * openni_streamer;
if(!oni_file.empty())
openni_streamer = new OpenniStreamer(oni_file);
else
openni_streamer = new OpenniStreamer();
// Initialize all the fundamental datastructures
int num_threads = model_list.size();
Visualizer visualizer;
Semaphore s(num_threads);
std::vector<std::thread> thread_list(num_threads);
std::vector<ClusterType> found_models(num_threads);
ErrorWriter e;
int frame_index;
// Read first frame and launch the threads
if(!openni_streamer->HasDataLeft())
exit(0);
scene = openni_streamer->GetCloud();
copyPointCloud (*scene, *complete_scene);
frame_index = openni_streamer->GetFrameIndex();
for(int i = 0; i < num_threads; ++i)
thread_list[i] = std::thread(FindObject, model_list[i], std::ref(scene), std::ref(s), std::ref(found_models), i, filters->at(i), icp_iterations->at(i), std::ref(e), std::ref(frame_index));
// Start the main detection loop
// 1- wait for the threads to find all the objects
// 2- visualize the scene and the found models
// 3- read a new scene
// 4- wake up threads
while(!visualizer.viewer_.wasStopped ()){
//wait for the threads to complete
s.Wait4threads();
//Visualizing the model, scene and the estimated model position
SetViewPoint (complete_scene);
visualizer.Visualize (model_list, found_models, complete_scene);
// Grab a frame and create the pointcloud checking in case if the oni stream is finished
if(!openni_streamer->HasDataLeft())
break;
scene = openni_streamer->GetCloud();
frame_index = openni_streamer->GetFrameIndex();
copyPointCloud (*scene, *complete_scene);
// Wake up the threads
s.Notify2threads();
}
// Notifies all the threads top stop and waits for them to join
s.SetStop();
for(int i = 0; i < num_threads; ++i)
thread_list[i].join();
return (0);
}