将infg CImg lib 与Qt 结合使用可以更快地调整图像大小。值得去挖掘吗?
我的项目是将大量 (30000) 小 jpeg 图像 (400*300) 批量调整为 15 种不同的目标尺寸(比源尺寸小)。
我首先创建了一个基于 CImg 和 libjpg 的多线程命令行工具来批量处理图像。并且在我的 4*2 核 Ubuntu 记事本上发挥了作用(20 分钟)。
现在,客户想要该工具的 GUI,带有进度条、预计时间、预览……等等!并希望它也能在 Windows 上运行。他想要一位形象经理。
我开始将纯 C++ 命令行移植到 Qt 及其 QImage 类(QtConcurrent::run 用于多线程),这里的问题是:在同一台机器上,它在 Windows 7 x64 上运行速度慢了 3 倍(大约 50 分钟)!
那么如何使用 Qt 读取图像并使用 CImg 调整图像大小呢?它会跑得更快吗?
My project is to batch resize a big number (30000) of small jpeg images (400*300) to 15 different destination sizes (which are smaller than the source).
I first created a multi-threded command line tool based on CImg and libjpg to batch process the images. And is worked as a charm on my 4*2 cores Ubuntu notepad (20 minutes).
Now the client wants a GUI for the tool, with progress bars, estimated time, previews, ... and so on! And want it to work on Windows too. He wants a sort of image manager.
I started porting the pure C++ command line to Qt and its QImage class (QtConcurrent::run for multi-threading), and here the problem : On the same machine it runs 3 times slower on Windows 7 x64 (about 50 minutes)!
So how to use Qt for reading images and CImg for resizeing them? And will it run faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我所做的:
代替:
它的运行速度快了 2 到 3 倍
Here is what I have done :
instread of :
It runs 2 to 3 times faster
如果不进行测量就很难判断它是否会运行得更快(尽管我猜是这样),但这仍然是一个好主意。
为您的命令行工具创建一个界面(API 而不是 GUI),在 Qt 中构建 gui 部分并从中调用图像调整大小后端的 API。
无论如何,这对于应用程序开发来说是一个很好的(我什至将其称为基本原则)设计。对于这样一个小项目,有时有点矫枉过正,但由于您已经拥有“后端”部分,无论如何都可以。
If it will run faster is difficult to tell without measuring (though I would guess it is), but it is nonetheless a good idea.
Create a interface (API not GUI) for your command line tool, build the gui parts in Qt and call the API of your image resizing backend from it.
This is a good (I would even call it a fundamental principle) design for application development anyway. For such a small project it is sometimes overkill, but since you already have the "backend" part anyways your fine.