warpAffine produces erroneous output on large images
I am using getRotationMatrix2D to rotate an image, passing the rotation matrix into warpAffine. On small images (e.g. 4465x1745 or smaller) the output is what I expect. Larger images (e.g. 14882x5815) give weird results. The same image scaled down gives expected results. Interestingly, reading the input image as grayscale allows warpAffine to process the image, even with large dimensions.
Code:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
#define READ_COLOR 1
#define READ_BW 0
int main(int argc, char *argv[])
{
Mat mat, out;
int len;
if (argc != 3) {
cerr << "Usage: " << *argv << " input-img output-img" << endl;
return -1;
}
mat = imread(argv[1], READ_COLOR);
if (!mat.data)
return -1;
Point2i pt(0, 0);
Mat r = getRotationMatrix2D(pt, 10, 1);
if (!r.data)
return -1;
warpAffine(mat, out, r, mat.size());
if (!imwrite(argv[2], out)) {
cerr << "!! error writing " << argv[2] << endl;
return -1;
}
return 0;
}
Image as input (download Original Size):
http://www.flickr.com/photos/fourcornersschool/10124677703/sizes/l/
When loaded with color in a large size I get the following result (post-processed with Graphics Magick to 30% scale due to upload size limitations):
Zoomed into somewhere near the center, for clarity, the image looks like this:
Telling imread to load as grayscale, the following image is produced (scaled as before with GM to 25%):
I built OpenCV with the following:
cmake28 -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=ON -D WITH_OPENCL=OFF -D WITH_TBB=ON ../opencv.git/
Build information:
General configuration for OpenCV 2.4.8.2 =====================================
Version control: 2.4.8.2
Platform:
Host: Linux 2.6.32-431.3.1.el6.x86_64 x86_64
CMake: 2.8.11.2
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: RELEASE
C/C++:
Built as dynamic libs?: YES
C++ Compiler: /usr/bin/c++ (ver 4.4.7)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/bin/cc
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release):
Linker flags (Debug):
Precompiled headers: YES
OpenCV modules:
To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu nonfree contrib stitching superres ts videostab
Disabled: world
Disabled by dependency: -
Unavailable: androidcamera dynamicuda java ocl python
GUI:
QT: NO
GTK+ 2.x: YES (ver 2.20 ...