Repository navigation
Closed
Description
System information (version)
- OpenCV => master ( c729fbd )
- Operating System / Platform => Debian (Raspbian) 9.3 / Raspberry Pi 3
- Compiler => GCC 4.9.2 / Clang 3.7.0
Detailed description
- The following tests fails from
opencv_test_calib3d
[==========] 89 tests from 46 test cases ran. (472539 ms total)
[ PASSED ] 86 tests.
[ FAILED ] 3 tests, listed below:
[ FAILED ] Calib3d_SolveP3P.accuracy
[ FAILED ] Calib3d_SolvePnPRansac.accuracy
[ FAILED ] Calib3d_SolvePnP.accuracy
3 FAILED TESTS
- On the other hand, when building with GCC, this doesn't happen
[==========] 89 tests from 46 test cases ran. (410682 ms total)
[ PASSED ] 89 tests.
- I reported similar behavior ( Calib3d_SolvePnP.accuracy is too unstable based on random seed #9187 ) but this was based on unstable
srand, so it's independent for this case. - This time, same code, same data, same platform, but different compiler.
- Since we have a reference from gcc, I traced back where the data differs and trace backed to here in ap3p.cpp
complex<double> complex2 = 2 * q4 / sqrt_2m;
- I added some
printfand found weird behvior of complex
GCC(expected behavior) |Clang (weird behavior)
=========================|=========================
q4 :-0.00130684 |q4 :-0.00130684
2 * q4 :(-0.00261369,0) |2 * q4 :(-0.00261369,0)
sqrt_2m :(0.00617747,0) |sqrt_2m :(0.00617747,0)
complex2:(-0.4231,0) |complex2:(-0.00261369,0)
- It seems division of
complex<double>has something wrong. - From this part, the data was different, and concluded as a massive number of failure.
- Just to make sure, I wrote a small code to check the behaviour.
- Even for the simplest following code, the result differs between the compiler
#include <iostream>
#include <cmath>
#include <complex>
int main(int argc, char**argv)
{
std::complex<double> a(-0.00261369, 0);
std::complex<double> b(0.00617747, 0);
std::complex<double> c = a / b;
std::cout << "a" << a << std::endl;
std::cout << "b" << b << std::endl;
std::cout << "c" << c << std::endl;
return 0;
}
=========GCC=========
a(-0.00261369,0)
b(0.00617747,0)
c(-0.4231,0)
=========Clang=======
a(-0.00261369,0)
b(0.00617747,0)
c(-0.00261369,0)
=====GCC Version=====
g++ (Raspbian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=====Clang Version===
Raspbian clang version 3.7.0-4~bpo8+1 (tags/RELEASE_370/final) (based on LLVM 3.7.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
- I also tried on wandbox but this issue did not reproduce. I didn't use any suspicious clang, I installed clang using
apt - I added a workaround using
ifdefin this code, and avoided the issue. - I'll send PR later.
Steps to reproduce
- run
opencv_test_calib3don Raspbian on Raspberry Pi 3, using clang
Metadata
Metadata
Assignees
Labels
No labels
Activity
alalek commentedon Mar 12, 2018
BTW, Can't reproduce with Clang 3.8 on TX-1 (aarch64, Ubuntu 16.04).
Output:
tomoaki0705 commentedon Mar 12, 2018
Yeah, that's one reason I raised this issue.
Which approach should we take ?
Probably we need more information, and I'll take a look, but how do you think @alalek ?
alalek commentedon Mar 13, 2018
Workaround is fine, but I believe we should adjust condition: simple "clang" is too wide.
It would be nice to add clang version check and/or target platform ("defined(arm) && !defined(aarch64) && !defined(ANDROID)" ?)
You could try to use some defines from this command (run it on RPi3):
tomoaki0705 commentedon Mar 13, 2018
I added some of your suggestions
I wasn't sure about
ANDROID, does it get build using LLVM ? I'm not sure about that point.if so, I'll add
ANDROIDin the condition, too.alalek commentedon Mar 13, 2018
__armlooks strange and almost not used:__arm__should be fine.Android NDK deprecates GCC toolchains - they switching to clang.
Version condition doesn't look really good (2.0-2.7 pass, 2.8+ doesn't, 3.0-3.7 pass again), this would be better with less questions:
tomoaki0705 commentedon Mar 13, 2018
Thank you !
I updated the PR