-
Notifications
You must be signed in to change notification settings - Fork 187
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
How to convert the signed 16 bit output into a disparity value? #67
Comments
Self closing, for some reason I thought the output called for a 16bit signed. Just realized its Unsigned. |
Reopening to focus on the scale value. |
This is what I landed on through experimentation, is this correct?
|
Hi, @mcelhennyi In subpixel mode, the output disparity value is scaled by With OpenCV, you can convert all pixels by Related issue: #21 Regards, |
Thanks for the reply, And just for confirmation, the fractional part is stored in the SUBPIXEL_SHIFT MSBs? |
Hi, @mcelhennyi
The fractional part is stored in the int mask = (1 << SUBPIXEL_SHIFT) - 1; // 0x0f
unsigned short output_value = ...;
int fractional_part = output_value & mask;
int integer_part = output_value >> SUBPIXEL_SHIFT; Regards, |
@atakagi-fixstars When I use the LSB version like you mentioned, I get very large (>maxDisparity) disparity values after I do the shifting. However when I use the MSB like I mentioned above, I get accurate disparity values. Here is my LSB code and MSB code: Here my
The output Here is the fractional from the MSB version: And here is the fractional from the LSB version: They appear to have a similar shaped output but the scale of the LSB variant is way off. In this case, the center point of the image has no fractional part (0) and an This is what I get when I remove the integer part being divided by the scale:
changes to this:
So the question is: |
Maybe it is invalid disparity value( This is sample code to get the floating point disparity value and check if it is invalid. int SUBPIXEL_SCALE = 16;
unsigned short output_disparity_u16 = ...; // maybe contains invalid value 65520
short output_disparity_s16 = (short)output_disparity_u16 ; // invalid value changes to -16
float output_disparity_32f = (float)output_disparity_s16 / SUBPIXEL_SCALE; // invalid value changes to -1
bool is_invalid = output_disparity_32f < 0.f;
The libSGM implements subpixel computation with LSB fractional part. At this line the integer part is shifted up, and at this line the fractional part is added. Maybe something is wrong with your operations. Regards, |
Oh I see now, I was shifting AND scaling. But now I realize dividing by 16 is the same as shifting by 4 bits and break the parts down manually. Thanks for the help. |
I have gotten this library to work with my point cloud conversion code when using the 8-bit output. I would like to get the 16-bit signed output to work for better precision, but cant understand the scale value.
I have noticed other implementations using unsigned 16 bit outputs with a scale value division on each short of the disparity image to get the disparity value in float form. What is the correct conversion for this library, I cannot seem to find this in other issues, docs or code.
Thanks!
The text was updated successfully, but these errors were encountered: