iOS 图像处理(失真)
我最初考虑到 CoreImage 来解决这个问题(因为我还需要进行面部识别),但不幸的是,我意识到 iPhone 上尚未包含 CI 失真滤镜。
我尝试深入研究 GLImageProcessing、CImg 和 ImageMagick,尽管我在找到学习这些内容的起点时遇到了很多困难。
考虑到市面上有很多会造成图像失真的应用程序,我知道这并不是一件非常困难的事情。
我不懂 C 或 C++,除非绝对必要,否则没有时间学习这些语言。如果这些库之一是处理此任务的权威库,那么就有必要。
有人有使用这些库的经验吗?
有没有专门针对 iOS5 介绍此内容的书籍?
我找到的资源:
GLImageProcessing 示例项目 https://developer.apple.com/library/ios/ #samplecode/GLImageProcessing/Introduction/Intro.html
ImageMagick &魔法棒 http://www.imagemagick.org/script/magick-wand.php
简单的 iPhone 图像处理 http://code.google.com/p/simple-iphone-image-处理/
I initially approached this issue with CoreImage in mind (because I also need to do facial recognition), but realized that, unfortunately, the CI Distortion filters are not yet included on the iPhone.
I attempted to dive into GLImageProcessing, CImg, and ImageMagick, though I've had a lot of trouble finding a starting point for learning any of these.
Given the number of apps out there that do image distortion, I know this can't be incredibly difficult.
I don't know C or C++, and don't have the time to learn those languages unless absolutely necessary. It would become necessary if one of those libraries is the definitive library for handling this task.
Does anyone have experience with any of these libraries?
Any books out there that cover this for iOS5 specifically?
Resources I've found:
GLImageProcessing sample project
https://developer.apple.com/library/ios/#samplecode/GLImageProcessing/Introduction/Intro.htmlImageMagick & MagickWand
http://www.imagemagick.org/script/magick-wand.phpSimple iPhone image processing
http://code.google.com/p/simple-iphone-image-processing/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如你所说,Core Image 目前的功能在 iOS 上有点有限。特别是,缺少像桌面上那样的自定义内核令人失望。您列出的其他替代方案(GLImageProcessing 除外,它无法执行此类过滤)都是 CPU 密集型库,对于在移动设备上进行实时过滤来说速度太慢。
不过,我可以向您推荐一个名为 GPUImage 的开源框架,我刚刚推出了它,因为我无法'找不到可以让您实现自定义效果的东西。顾名思义,GPUImage 使用 OpenGL ES 2.0 着色器对静态图像和视频进行 GPU 加速处理。您可以使用它们编写自己的自定义效果,因此您应该能够做您能想到的任何事情。该框架本身是 Objective-C 的,并且有一个相当简单的界面。
作为失真过滤器的示例,以下着色器(基于 Danny Pflughoeft 的答案 中的代码)执行某种操作鱼眼效果:
这会在视频流上产生这种效果:
在我的基准测试中, GPUImage 处理图像的速度比 iPhone 4 上的 Core Image 快 4 倍(比 CPU 处理速度快 6 倍),处理视频的速度比 Core Image 快 25 倍(比 CPU 上的处理快 70 倍)。即使在最坏的情况下,它的处理速度也与 Core Image 相匹配。
该框架仍然相当新,因此我现在拥有的库存过滤器的数量很少,但我很快就会添加更多。同时,您可以编写自己的自定义失真着色器来处理您的图像,并且所有内容的源代码都可供您根据需要进行调整。 我的介绍性文章详细介绍了如何在您的应用程序中使用它。
As you say, the current capabilities of Core Image are a little limited on iOS. In particular, the lack of custom kernels like you find on the desktop is disappointing. The other alternatives you list (with the exception of GLImageProcessing, which wouldn't be able to do this kind of filtering) are all CPU-bound libraries and would be much too slow for doing live filtering on a mobile device.
However, I can point you to an open source framework called GPUImage that I just rolled out because I couldn't find something that let you pull off custom effects. As its name indicates, GPUImage does GPU-accelerated processing of still images and video using OpenGL ES 2.0 shaders. You can write your own custom effects using these, so you should be able to do just about anything you can think of. The framework itself is Objective-C, and has a fairly simple interface.
As an example of a distortion filter, the following shader (based on the code in Danny Pflughoeft's answer) does a sort of a fisheye effect:
This produces this kind of effect on a video stream:
In my benchmarks, GPUImage processes images 4X faster than Core Image on an iPhone 4 (6X faster than CPU-bound processing) and video 25X faster than Core Image (70X faster than on the CPU). In even the worst case I could throw at it, it matches Core Image for processing speed.
The framework is still fairly new, so the number of stock filters I have in there right now is low, but I'll be adding a bunch more soon. In the meantime, you can write your own custom distortion shaders to process your images, and the source code for everything is available for you to tweak as needed. My introductory post about it has a little more detail on how to use this in your applications.