Adding/subtracting a scalar to Mat results in garbled output in 64bit (Bug #1460)
Description
I have the following code:
Mat image(256, 256, CV_8UC1); image.setTo(128); Mat result = image - 64; imwrite("subtract_test.png", result);
I am expecting to see a image filled with level 64, but I get the following on Mac OS X 10.7 64bit:
[[Image(http://img16.imageshack.us/img16/6124/subtracttest.png)]]
It happens in both release and debug build. I compiled OpenCV from trunk as-is with CMake and the provided compiler:
~ $ gcc -v Using built-in specs. Target: i686-apple-darwin11 Configured with: ... Thread model: posix gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
Associated revisions
Merge pull request #1460 from ilya-lavrenov:ocl_divUp
History
Updated by Michal Kottman over 13 years ago
I found out that the bug also manifests itself on Ubuntu 11.04 64bit (although a bit more "cleanly"):
[[Image(http://img513.imageshack.us/img513/3371/subtracttestubuntu.png)]]
The same happens when adding a value, i.e.:
Mat result = image + 64;
However, multiplication and division work OK.
I suspect this might be a 64bit issue, but I do not have a 32bit machine to test whether it also happens in 32bit builds.
Updated by Vadim Pisarevsky over 13 years ago
I can not reproduce this bug on MacOSX 10.6 (do not have 10.7 yet), GCC 4.2.1, debug and release mode. The images come out clean. Can you check a different compiler or OS?
- Status changed from Open to Done
- (deleted custom field) set to worksforme
Updated by rolfans - about 13 years ago
This error is there in OpenCV 2.3.1 for both Linux 64 and windows 64 for a 8 bit image.
- Status changed from Done to Cancelled
- (deleted custom field) deleted (
worksforme)
Updated by Luis Díaz Más about 13 years ago
Replying to [comment:3 rolfans]:
This error is there in OpenCV 2.3.1 for both Linux 64 and windows 64 for a 8 bit image.
I didn't have the problem in my Debian Lenny system with kernel 2.6.32-5-amd64. I've tried with Debug (-Wall -Wextra -g3 -O0) and Release (-Wall -DNDEBUG -O2) modes. I attach the code tested.
$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
Updated by rolfans - about 13 years ago
The test code works fine on both windows 32bit and linux 64. I do not get where or what causes the error, could be some memory corruption from somewhere else, have tried to compile OpenCV with and without IPP, and that makes no difference. The image is from cvSaveImage on windows, and it might be that it is the saving that does something strange.
Updated by rolfans - about 13 years ago
Found out what caused the error: a call to the cvUseOptimized(). I have not found out why.
Updated by Vadim Pisarevsky about 13 years ago
ok, so I'm lowering priority of the bug, since there should be very specific conditions to reproduce it