Skip to content
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

The documentation doesn't specify the input type of patchNaNs #18000

Closed
4 tasks done
nh60211as opened this issue Jul 31, 2020 · 2 comments · Fixed by #18008
Closed
4 tasks done

The documentation doesn't specify the input type of patchNaNs #18000

nh60211as opened this issue Jul 31, 2020 · 2 comments · Fixed by #18008
Labels
Milestone

Comments

@nh60211as
Copy link

nh60211as commented Jul 31, 2020

System information (version)
  • OpenCV => 4.3, 4.4
  • Operating System / Platform => Windows 64 Bit with pre-built library
  • Compiler => Visual Studio 2019
Detailed description

void patchNaNs(InputOutputArray a, double val = 0)
https://docs.opencv.org/4.4.0/d2/de8/group__core__array.html#ga62286befb7cde3568ff8c7d14d5079da

converts the values in input matrix that is NaN or -NaN to val.
However, the documentation doesn't say that the input matrix should be of type float.

It will be caught in debug build with an assert, and crash the program in release build. My bad, it doesn't crash the program. But rather not handled properly in my program.

Steps to reproduce
uint64_t temp64 = 0x7FF0000000000001u;
double not_a_number_double = *((double*)(&temp64));
std::cout << "not_a_number_double: " << not_a_number_double << std::endl;

temp64 = 0xFFF0000000000001u;
double negative_not_a_number_double = *((double*)(&temp64));
std::cout << "negative_not_a_number_double: " << negative_not_a_number_double << std::endl;

Mat mu3(Size(3, 3), CV_64FC1, Scalar(not_a_number_double));
std::cout << "mu3 before patchNaNs: " << mu3 << std::endl;
cv::patchNaNs(mu3, 0.0); // error occurred at here 
std::cout << "mu3 after patchNaNs: " << mu3 << std::endl;

Mat mu4(Size(3, 3), CV_64FC1, Scalar(negative_not_a_number_double));
std::cout << "mu4 before patchNaNs: " << mu4 << std::endl;
cv::patchNaNs(mu4, 0.0);
std::cout << "mu4 after patchNaNs: " << mu4 << std::endl;
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc
@mshabunin
Copy link
Contributor

There is an assertion:

CV_Assert( _a.depth() == CV_32F );

It does not crash in release mode, it throws an exception. It is responsibility of caller to catch an exception. We can fix documentation though.

@nh60211as
Copy link
Author

Thank you for the reply. The program doesn't crash at that point. I have edited it in the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants