-
Notifications
You must be signed in to change notification settings - Fork 769
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
Conversation
RGB images are much oversampled than depth images. More sampling precision on RGB would have little improvement.
3 is just hardcoded |
Good point about |
Any test reports from Windows or MacOS? I'm reluctant to merge this otherwise. |
Thanks for your work on this. I tested on MacOS 10.9.5. Registration seems to work, although I get some noise at the bottom of the image. Also I get a crash on exit, which might not be related, but I don't get it with the latest 585d4c4 upstream/master. Thread 0 Crashed:: Dispatch queue: com.apple.main-thread |
The noise:
Need a memset here, and probably it's not a good idea to define a huge array on stack. The crash is a race condition, discussed in #212. |
Thanks! memset and the xlz@c6f6e57 commit mentioned in #212 indeed fixed both issues. |
Thanks for testing - instead of memset, I've modified the inner loop to also set skipped pixels to zero, so we don't need to memset everything to zeroes which will get overwritten anyway. |
Thanks. This also solves the issue. |
FTBFS with MSVC 2013 here:
Error C2057: expected constant expression |
Ooops, OK (a bit surprising, but as you said, it's probably a better idea to move the buffer to the heap anyway). I'll fix that ASAP. |
Also, this line causes stack overflow with MSVC:
After replacing this and registered with heap allocation, it works correctly on Windows. |
Now that is somewhat surprising, why should this line be an issue? IMHO it should be valid C++, can you post a stacktrace? |
The stack overflow happens upon entering main(). Probably because |
Ah, OK. I would have assumed the default stack is a lot bigger, but it's fixed now. |
I had to add And it seems that default stack is 1 MB :) |
Also fixed, now using |
Works great 👍 |
@@ -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]; |
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.
OK, since everything works as expected across all major platforms, I'll merge this tomorrow; additional features will be added via separate PRs. Thanks for contributing, everyone! |
This are the results I am getting from the registration: i) noticeable radial distortion in the closet. Shouldn't the depth data be undistorted first? ii) pixel duplication, you can see my hand and the pen appear two times. Is this normal? Shouldn't registration be a bijection? Camera calibration parameters used are those returned by the lib. I'm quite newbie on this subject so I might be missing something. |
|
@floe Thanks. I'd say it looks like the depth isn't undistorted but the color is "distorted" so that it matches the depth. I've superimposed the three images (registration, depth, and IR) as layers on this [1] Gimp file. You can play a little with the transparency and the layer order. [1] https://www.dropbox.com/s/t2nnf737jvt4b3y/IR_DEPTH_REGISTERED.xcf?dl=0 |
@JuantAldea good point, got it backwards myself. Nice example, thanks! |
add convenience method & sample code for registration
So is this working as intended? Shouldn't the depth be undistorted? |
As far as we know, the parameters stored in the device are specific for this operation only, i.e. mapping color onto depth. Unless @sh0 knows about some more internals (such as the tables at the end of DepthCameraParamsResponse), this is all we can currently support without external calibration. |
Got it, thanks. |
Actually, maybe I was posting too soon: in theory, the parameters for standalone depth undistortion should be there, too. I'll re-read the old discussion in #41 tomorrow. |
I was obviously posting this too late at night yesterday evening, of course it's possible to undistort the depth image separately - that's exactly what I added undistort_map for in the first place :-) |
I'm trying to do a face detection with the Protonect.cpp code. I need to apply a haarclassifier on the registered image. I tried with opencv haarcascade class
dev->stop(); but I kept getting a member error |
Thanks! I seem to have some preliminary results on a face detection algorithm using haarcascades my code here. |
Thanks again @larshg and @xlz for your sample code. I've rewritten it to not use OpenCV, as we probably want to remove that dependency at some point (see also the PR by @christiankerl). Also, I have not yet implemented the depth buffer from @xlz's example, will do that soon.