-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support OpenNI2 devices without RGB #1174
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
#include <pcl/visualization/pcl_visualizer.h> | ||
#include <pcl/visualization/boost.h> | ||
#include <pcl/visualization/image_viewer.h> | ||
#include <pcl/visualization/common/float_image_utils.h> | ||
#include <pcl/console/print.h> | ||
#include <pcl/console/parse.h> | ||
#include <pcl/console/time.h> | ||
|
@@ -119,8 +120,10 @@ class OpenNI2Viewer | |
OpenNI2Viewer (pcl::io::OpenNI2Grabber& grabber) | ||
: cloud_viewer_ (new pcl::visualization::PCLVisualizer ("PCL OpenNI2 cloud")) | ||
, image_viewer_ () | ||
, depth_viewer_ () | ||
, grabber_ (grabber) | ||
, rgb_data_ (0), rgb_data_size_ (0) | ||
, xyz_data_ (0), xyz_data_size_ (0) | ||
{ | ||
} | ||
|
||
|
@@ -152,6 +155,17 @@ class OpenNI2Viewer | |
} | ||
} | ||
|
||
|
||
void | ||
depth_callback (const boost::shared_ptr<pcl::io::openni2::DepthImage>& depth) | ||
{ | ||
FPS_CALC ("depth callback"); | ||
|
||
boost::mutex::scoped_lock lock (depth_mutex_); | ||
depth_ = depth; | ||
|
||
} | ||
|
||
void | ||
keyboard_callback (const pcl::visualization::KeyboardEvent& event, void*) | ||
{ | ||
|
@@ -189,20 +203,34 @@ class OpenNI2Viewer | |
boost::signals2::connection image_connection; | ||
if (grabber_.providesCallback<void (const boost::shared_ptr<pcl::io::openni2::Image>&)>()) | ||
{ | ||
image_viewer_.reset (new pcl::visualization::ImageViewer ("PCL OpenNI image")); | ||
image_viewer_.reset (new pcl::visualization::ImageViewer ("PCL OpenNI2 image")); | ||
image_viewer_->registerMouseCallback (&OpenNI2Viewer::mouse_callback, *this); | ||
image_viewer_->registerKeyboardCallback (&OpenNI2Viewer::keyboard_callback, *this); | ||
boost::function<void (const boost::shared_ptr<pcl::io::openni2::Image>&) > image_cb = boost::bind (&OpenNI2Viewer::image_callback, this, _1); | ||
image_connection = grabber_.registerCallback (image_cb); | ||
} | ||
|
||
bool image_init = false, cloud_init = false; | ||
boost::signals2::connection depth_connection; | ||
if (grabber_.providesCallback<void (const boost::shared_ptr<pcl::io::openni2::DepthImage>&)>()) | ||
{ | ||
depth_viewer_.reset (new pcl::visualization::ImageViewer ("PCL OpenNI2 Depth")); | ||
depth_viewer_->registerMouseCallback (&OpenNI2Viewer::mouse_callback, *this); | ||
depth_viewer_->registerKeyboardCallback (&OpenNI2Viewer::keyboard_callback, *this); | ||
boost::function<void (const boost::shared_ptr<pcl::io::openni2::DepthImage>&) > depth_cb = boost::bind (&OpenNI2Viewer::depth_callback, this, _1); | ||
depth_connection = grabber_.registerCallback (depth_cb); | ||
} | ||
|
||
|
||
|
||
|
||
bool image_init = false, cloud_init = false, depth_init = false; | ||
|
||
grabber_.start (); | ||
|
||
while (!cloud_viewer_->wasStopped () && (image_viewer_ && !image_viewer_->wasStopped ())) | ||
while (!cloud_viewer_->wasStopped () && ((image_viewer_ && !image_viewer_->wasStopped ()) || ( depth_viewer_ && !depth_viewer_->wasStopped ()))) | ||
{ | ||
boost::shared_ptr<pcl::io::openni2::Image> image; | ||
boost::shared_ptr<pcl::io::openni2::DepthImage> depth; | ||
CloudConstPtr cloud; | ||
|
||
cloud_viewer_->spinOnce (); | ||
|
@@ -260,32 +288,66 @@ class OpenNI2Viewer | |
image_viewer_->spinOnce (); | ||
|
||
} | ||
} | ||
|
||
if (depth_mutex_.try_lock ()) | ||
{ | ||
depth_.swap (depth); | ||
depth_mutex_.unlock (); | ||
} | ||
|
||
if (depth) | ||
{ | ||
if (!depth_init && cloud && cloud->width != 0) | ||
{ | ||
depth_viewer_->setPosition (cloud->width, 0); | ||
depth_viewer_->setSize (cloud->width, cloud->height); | ||
depth_init = !depth_init; | ||
} | ||
|
||
unsigned char* data = pcl::visualization::FloatImageUtils::getVisualImage ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the indentation here |
||
reinterpret_cast<const unsigned short*> (depth->getData ()), | ||
depth->getWidth (), depth->getHeight (), | ||
std::numeric_limits<unsigned short>::min (), | ||
std::numeric_limits<unsigned short>::max () / 10, | ||
true); | ||
|
||
depth_viewer_->addRGBImage ( data, depth->getWidth (), depth->getHeight ()); | ||
|
||
depth_viewer_->spinOnce (); | ||
|
||
} | ||
} | ||
grabber_.stop (); | ||
|
||
cloud_connection.disconnect (); | ||
image_connection.disconnect (); | ||
depth_connection.disconnect (); | ||
if (rgb_data_) | ||
delete[] rgb_data_; | ||
} | ||
|
||
boost::shared_ptr<pcl::visualization::PCLVisualizer> cloud_viewer_; | ||
boost::shared_ptr<pcl::visualization::ImageViewer> image_viewer_; | ||
boost::shared_ptr<pcl::visualization::ImageViewer> depth_viewer_; | ||
|
||
pcl::io::OpenNI2Grabber& grabber_; | ||
boost::mutex cloud_mutex_; | ||
boost::mutex image_mutex_; | ||
boost::mutex depth_mutex_; | ||
|
||
CloudConstPtr cloud_; | ||
boost::shared_ptr<pcl::io::openni2::Image> image_; | ||
boost::shared_ptr<pcl::io::openni2::DepthImage> depth_; | ||
unsigned char* rgb_data_; | ||
unsigned char* xyz_data_; | ||
unsigned rgb_data_size_; | ||
unsigned xyz_data_size_; | ||
}; | ||
|
||
// Create the PCLVisualizer object | ||
boost::shared_ptr<pcl::visualization::PCLVisualizer> cld; | ||
boost::shared_ptr<pcl::visualization::ImageViewer> img; | ||
boost::shared_ptr<pcl::visualization::ImageViewer> dep; | ||
|
||
/* ---[ */ | ||
int | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete the extra line returns (there are a few across your pull request)