Last active
December 20, 2015 07:19
-
-
Save gcpantazis/6092838 to your computer and use it in GitHub Desktop.
OpenCV, rotate an image 180 degrees.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/gpu/gpu.hpp> | |
#include <opencv2/imgproc/imgproc.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
using namespace cv; | |
int main(int argc, char* argv[]) | |
{ | |
Mat src_img, dst_img; | |
gpu::GpuMat src_gpu, dst_gpu; | |
src_img = imread("my_image.jpg"); | |
if (src_img.empty()) { | |
printf("error: can not load image...\n"); | |
return -1; | |
} | |
// Create a destination to paint the source into. | |
dst_img.create(src_img.size(), src_img.type()); | |
// Push the images into the GPU | |
src_gpu.upload(src_img); | |
dst_gpu.upload(dst_img); | |
// Rotate in the GPU! | |
gpu::rotate(src_gpu, dst_gpu, src_gpu.size(), 180, src_gpu.size().width, src_gpu.size().height); | |
// Download the rendered GPU data back to CPU | |
dst_gpu.download(dst_img); | |
// ... so that it can be written with imwrite. | |
imwrite("./COOL.png", dst_img); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For 180 degree rotations you should just use a transpose and flip command. It's 10x faster than the arbitrary rotation you are using now.