-
Notifications
You must be signed in to change notification settings - Fork 770
add convenience method & sample code for registration #226
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
Changes from all commits
a2b72c6
e635ce8
c333cae
2c48445
e9b337c
b81e081
5cb1092
42c9eaa
18674e3
769fa80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
#include <libfreenect2/libfreenect2.hpp> | ||
#include <libfreenect2/frame_listener_impl.h> | ||
#include <libfreenect2/threading.h> | ||
#include <libfreenect2/registration.h> | ||
|
||
bool protonect_shutdown = false; | ||
|
||
|
@@ -76,6 +77,9 @@ int main(int argc, char *argv[]) | |
std::cout << "device serial: " << dev->getSerialNumber() << std::endl; | ||
std::cout << "device firmware: " << dev->getFirmwareVersion() << std::endl; | ||
|
||
libfreenect2::Registration* registration = new libfreenect2::Registration(dev->getIrCameraParams(), dev->getColorCameraParams()); | ||
unsigned char* registered = NULL; | ||
|
||
while(!protonect_shutdown) | ||
{ | ||
listener.waitForNewFrame(frames); | ||
|
@@ -87,6 +91,10 @@ int main(int argc, char *argv[]) | |
cv::imshow("ir", cv::Mat(ir->height, ir->width, CV_32FC1, ir->data) / 20000.0f); | ||
cv::imshow("depth", cv::Mat(depth->height, depth->width, CV_32FC1, depth->data) / 4500.0f); | ||
|
||
if (!registered) registered = new unsigned char[depth->height*depth->width*rgb->bytes_per_pixel]; | ||
registration->apply(rgb,depth,registered); | ||
cv::imshow("registered", cv::Mat(depth->height, depth->width, CV_8UC3, registered)); | ||
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. This line should also handle 3 or 4 bytes per pixel? 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. Now that I think about it, it would probably be better to switch to 4 BPP anyway and use the extra channel to add depth data. That would make filtering a lot easier, and would probably also be faster than shifting around single bytes. 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. This line can be generalized when JPEG decoders of 4-byte output are added. |
||
|
||
int key = cv::waitKey(1); | ||
protonect_shutdown = protonect_shutdown || (key > 0 && ((key & 0xFF) == 27)); // shutdown on escape | ||
|
||
|
@@ -99,5 +107,8 @@ int main(int argc, char *argv[]) | |
dev->stop(); | ||
dev->close(); | ||
|
||
delete[] registered; | ||
delete registration; | ||
|
||
return 0; | ||
} |
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.
Given that the depth frame size is already known to be 512x424 if I recall correctly, is there any reason to not to allocate outside of the loop?
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.
Depending on the color frame decoder, rgb->bits_per_pixel is either 3 or 4, so I'd like to keep it consistent.