Blur-detection-with-FFT-in-C
Blur-detection-with-FFT-in-C copied to clipboard
When I run this project, the result shows -nan why?
Sorry to hear. I don't have a clue. Just run the repro on a clean RPi4 with OpenCV 4.4 and no problem at all. As you know -nan indicates a floating-point overflow or underflow. Mostly this type of error is generated by a division by zero. Without further information, it is impossible to say what is causing your error.
Thank you for your reply. I run the project with OpenCV 3.6, Cllion IDE. Example image is the Lena.jpg file in your project. Maybe I use a different version of OpenCV which caused this error?
------------------ 原始邮件 ------------------ 发件人: "Qengineering/Blur-detection-with-FFT-in-C" <[email protected]>; 发送时间: 2020年9月25日(星期五) 晚上6:04 收件人: "Qengineering/Blur-detection-with-FFT-in-C"<[email protected]>; 抄送: "1126197571"<[email protected]>;"Author"<[email protected]>; 主题: Re: [Qengineering/Blur-detection-with-FFT-in-C] When I run this project, the result shows -nan why? (#1)
Sorry to hear. I don't have a clue. Just run the repro on a clean RPi4 with OpenCV 4.4 and no problem at all. As you know -nan indicates a floating-point overflow or underflow. Mostly this type of error is generated by a division by zero. Without further information, it is impossible to say what is causing your error.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
I'v never tested the project with OpenCV 3.6, only with version 4.x in Code::Blocks. Clion software surely must do the job also. In fact the whole cpp is not really rocked science. I would start debugging by commenting most lines and let only the first lines be compiled. See where you get the error. Be aware about #defines line DFT_SCALE, these may very well be renamed in OpenCV 4. Please check.
@Qengineering Hi,
I have the same Naan error with opencv 4
any idea ?
Sorry to hear. NAN indicates an illegal floating-point operation. Think of a division by zero, or in case of this example a log of zero. The log is taken at line 75, cv::log(invFFT,logFFT);
For testing, comment this line out and see if the error happens again.
If not the case, then you have tried a take a log from a completely black image (invFFT
holds no pixels >0)
Hi @Qengineering
When comment the line 75 than result.val[0] is 0 .
@Qengineering opencv version: 4.5.1
@Qengineering FYI same code is working at raspi4 but not working at i9 linux ubuntu desktop . compile is -- The CXX compiler identification is GNU 10.2.0
FYI
@Qengineering
One more thing Desktop has Gpu , opencv compiled with GPU (2080txi)
is it caused to fourierTransform Nan result ?
@Qengineering
I tried also opencv 4.4 same as yours. Same Nan Problem (x86 desktop)
one possiblity is the compiler, what si yours version? any difference
W've use gcc 8.3.0 with Raspberry Pi 4 and Jetson Nano. Both no problem. OpenCV with CUDA (GPU) on the Jetson Nano, without GPU on the RPi 4.
Your NAN problem is caused by some floating point instruction. Try to figure out where it happens. Run the example with the supported Lena images. It should give the same results as given on GitHub, When crashing, start with commenting out all instructions except the first one where Lena is loaded. Next, do only the forward FFT, then the reverse FFT and so on.
Because you have also problems with the same code (Blur detection) in the Face recognition example, I'm very worried about the quality of the images. It looks if they are mutated somewhere along the way, causing to be filled with zero's or other illegal values.
One of the last things you should worried about is OpenCV version differences. The latest versions are all identical when it comes to the used algorithms in the examples here. Only the cv::dnn part has major changes.
In raspberry pi its working corrctly (Rasbian)
But Ubuntu 20.04 gcc-8 / gcc-9 or clang-10 with opencv 4.5 its always gives 0 "zero" result for all example images.
This is really strange.
Which Ubuntu? On a Raspberry Pi 4 installed? Or on a x86_64 machine?
@Qengineering
I try to convert eigen not it look working. Please look below code:
` Eigen::MatrixXf b_cmp(128, 128);
cv2eigen(invFFT, b_cmp);
auto loga = b_cmp.log();
cv::log(invFFT,logFFT);
//std::cout << logFFT << std::endl;
eigen2cv(b_cmp, logFFT);
logFFT *= 20;
//std::cout << logFFT << std::endl;
//result = numpy.mean(img_fft)
cv::Scalar result= cv::mean(logFFT);`
I dont know result is making sense..
If you conver all tot he eigen it will work in all architecture I assume.
best
@Qengineering ubuntu 20.04 x86 mahine give always NaN .
cv::log(invFFT,logFFT);
is the problmatic line I suspect.
OpenCv compiled with Gpu .
Fixed bug causing the NAN output.
@Qengineering
Thanks its resolved.
But what caused this ? old code working on RPi but not on x86 ? Compiler behaviour ?
Best
Indeed, I think it must be the compiler. You name it.