Rotating hundreds of JPEGs in seconds rather than hours

眉间皱痕 提交于 2019-12-05 03:15:48

问题


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.

  • Intel Atom D525 (1,8 Ghz)
  • Mobility Radeon HD 5430 Series
  • 4 GB of RAM
  • SSD Vertility 3

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


回答1:


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. http://linuxmanpages.com/man1/jpegtran.1.php




回答2:


There is a jpeg no-recompression plugin for irfanview which IIRC can rotate and resize images (in simple ways) without recompressing, it can also run an a directory of images - this should be a lot faster

The GPU probably wouldn't help, you are almost certainly I/O limited in opencv, it's not really optomised for high speed file access




回答3:


I'm not an expert in jpeg and compression topics, but as your problem is pretty much as I/O limited as it gets (assuming that you can rotate without heavy de/encoding-related computation), you you might not be able to accelerate it very much on the GPU you have. (Un)Luckily your reference is a pretty slow Atom CPU.

I assume that the Radeon has separate main memory. This means that data needs to be communicated through PCI-E which is the extra latency compared to CPU execution and without hiding you can be sure that it is the bottleneck. This is the most probable reason why your code that uses OpenCV on the GPU is slow (besides the fact that you do two memory-bound operations, transpose & flip, instead of a single one).

The key thing is to hide as much of the PCI-E transfer times with computation as possible by using multiple-buffering. Overlapping transfers both to and from the GPU with computation by making use of the full-duplex capability of PCI-E will only work if the card in question has dual-DMA engines like high-end Radeons or the NVIDIA Quadro/Tesla cards -- which I highly doubt.

If your GPU compute-time (the time it takes the GPU to do the rotation) is lower than the time the transfer takes, you won't be able to fully overlap. The HD 4530 has a pretty slow memory interface with only 12.8 Gb/s peak, and the rotation kernel should be quite memory bound. However, I can only guesstimate, but I would say that if you reach peak PCI-E transfer rate of ~1.5 Gb/s (4x PCI-E AFAIK), the compute kernel will be a few times faster than the transfer and you'll be able to overlap very little. You can simply time the parts separately without requiring elaborate asynchronous code and you can estimate how fast can you get things with an optimum overlap.

One thing you might want to consider is getting hardware which doesn't exhibit PCI-E as a bottleneck, e.g:

  • AMD APU-based system. On these platforms you will be able to page-lock the memory and use it directly from the GPU;
  • integrated GPUs which share main memory with the host;
  • a fast low-power CPU like a mobile Intel Ivy Bridge e.g. i5-3427U which consumes almost as little as the Atom D525 but has AVX support and should be several times faster.


来源:https://stackoverflow.com/questions/11396856/rotating-hundreds-of-jpegs-in-seconds-rather-than-hours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!