核心图像CIPerspectiveTransform过滤器:如何使用CIVectors? [英] Core Image CIPerspectiveTransform Filter: How to use CIVectors?

查看:183
本文介绍了核心图像CIPerspectiveTransform过滤器:如何使用CIVectors?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在网上找到任何文档,清楚地解释了如何正确实现Core Image的CIPerspectiveTransform过滤器。特别是,当为 inputTopLeft 设置CIVector值时, inputTopRight inputBottomRight inputBottomLeft ,这些向量对图像做了什么? (即,这些矢量如何扭曲我的图像背后的数学是什么?)

I am having a very hard time finding any documentation online that clearly explains how to implement Core Image's CIPerspectiveTransform filter properly. In particular, when setting CIVector values for inputTopLeft, inputTopRight, inputBottomRight, and inputBottomLeft, what are these vectors doing to the image? (I.e., what is the math behind how these vectors warp my image?)

目前这是我正在使用的代码。它没有崩溃,但它没有显示图像:

Currently this is the code I am using. It doesn't crash, but it doesn't show an image:

CIImage *myCIImage = [[CIImage alloc] initWithImage:self.image];
CIContext *context = [CIContext contextWithOptions:nil];
CIFilter *filter = [CIFilter filterWithName:@"CIPerspectiveTransform" keysAndValues:@"inputImage", myCIImage, @"inputTopLeft", [CIVector vectorWithX:118 Y:484], @"inputTopRight", [CIVector vectorWithX:646 Y:507], @"inputBottomRight", [CIVector vectorWithX:548 Y:140], @"inputBottomLeft", [CIVector vectorWithX:155 Y:153], nil];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *transformedImage = [UIImage imageWithCGImage:cgimg];
[self setImage:transformedImage];
CGImageRelease(cgimg);

其他需要注意的事项可能很重要:

Other things to note that might be important:


  • 我的UIImageView(75pts x 115点)已经通过awakeFromNib初始化,并且已经有一个与之关联的图像(151px x 235px)。

  • My UIImageView (75pts x 115 pts) is already initialized via awakeFromNib and already has an image (151px x 235px) associated with it.

上面的代码是在UIImageView的 - (void)touchesMoved :( NSSet *)触及withEvent:(UIEvent *)事件函数中实现的。我希望能够根据屏幕坐标调整图像的视角,使其看起来像是在3D空间中移动。

The above code is being implemented in the UIImageView's - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event function. The hope is that I'll be able to adjust the perspective of the image based on screen coordinates so it looks like the image is moving in 3D space.

此代码适用于iPhone应用程序。

This code is for an iPhone app.

同样,我想问的问题是各种参数向量是什么但是,我可能会问错误的问题。

Again, the question I think I am asking is what the various parameter vectors do, but I may be asking the wrong question.

以下帖子非常相似,但是询问为什么他的图像消失了,而不是如何使用CIVerspectiveTransform的CIVectors。它也很少受到牵引,也许是因为它过于笼统:
如何我可以使用CIPerspectiveTransform过滤器

The following post is very similar but is asking why his image disappears rather than how to use CIVectors for CIPerspectiveTransform. It also has received very little traction, perhaps because it is too general: How I can use CIPerspectiveTransform filter

推荐答案

正如我对链接问题发表评论时,CIPerspectiveTransform是在iOS 5.1的Core Image的iOS实现中不可用。这就是为什么你和其他提问者没有看到任何图像的结果,因为很可能你的CIFilter是零。

As I commented on the linked question, CIPerspectiveTransform is not available in the iOS implementation of Core Image as of iOS 5.1. That's why you and the other asker weren't seeing any image as a result, because most likely your CIFilter was nil.

如果你只是想实现一种形式的透视在图像上,有两种不同的快速方式在iOS上执行此操作,正如我在此答案中所述。一种是在UIImageView的图层上简单地使用正确的CATransform3D ,但这只对显示有用,而不是用于图像调整。

If you just want to implement a form of perspective on an image, there are two different fast ways of doing this on iOS, as I describe in this answer. One is to simply use the right kind of CATransform3D on the layer of a UIImageView, but this is only useful for display, not for image adjustment.

第二种方法是在OpenGL ES中使用适当的3-D变换矩阵来操纵图像。正如我在上面链接的答案中指出的那样,我有一个包含所有这些内容的开源框架, FilterShowcase示例中有一个将透视应用于传入视频的示例。您可以轻松地将视频输入替换为图像,并在应用透视效果后从中获取图像。

The second way is to manipulate the image using an appropriate 3-D transformation matrix in OpenGL ES. As I indicate in the above-linked answer, I have an open source framework that wraps all this, and the FilterShowcase sample there has an example of applying a perspective to incoming video. You can easily swap out the video input with your image, and grab an image from that after the perspective effect is applied.

这篇关于核心图像CIPerspectiveTransform过滤器:如何使用CIVectors?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆