Search code examples
openglgraphicsopencvopenclimage-rotation

Rotating hundreds of JPEGs in seconds rather than hours


We have hundreds of images which our computer gets at a time and we need to rotate and resize them as fast as possible. Rotation is done by 90, 180 or 270 degrees.

Currently we are using the command line tool GraphicsMagick to rotate the image. Rotating the images (5760*3840 ~ 22MP) takes around 4 to 7 seconds.

The following python code sadly gives us equal results

import cv
img = cv.LoadImage("image.jpg")
timg = cv.CreateImage((img.height,img.width), img.depth, img.channels) # transposed image

# rotate counter-clockwise
cv.Transpose(img,timg)
cv.Flip(timg,timg,flipMode=0)
cv.SaveImage("rotated_counter_clockwise.jpg", timg)

Is there a faster way to rotate the images using the power of the graphics card? OpenCL and OpenGL come to mind but we are wondering whether a performance increase would be noticable.

The hardware we are using is fairly limited as the device should be as small as possible.

The software is debian 6 with official (closed source) radeon drivers.


Solution

  • you can perform a lossless rotation that will just modify the EXIF section. This will rotate your pictures faster.

    and have a look at jpegtran utility which performs lossless jpeg modifications. https://linux.die.net/man/1/jpegtran