Objective-C 中框架的水平翻转

发布于 2024-10-13 05:50:12 字数 1421 浏览 6 评论 0原文

我正在尝试为我的程序(流式传输网络摄像头)创建一个过滤器,使框架水平翻转,使网络摄像头充当镜子。

然而,当它编译并运行时,过滤器似乎对它没有任何影响。

代码如下:

CIImage *resultImage = image;
CIFilter *flipFilter = [CIFilter filterWithName:@"CIAffineTransform"];
[flipFilter setValue:resultImage forKey:@"inputTransform"];

NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform scaleXBy:-1.0 yBy:1.0]; //horizontal flip
[flipFilter setValue:flipTransform forKey:@"inputTransform"];

resultImage = [flipFilter valueForKey:@"outputImage"];

奇怪的是,其他过滤器似乎也能工作。例如:

CIFilter * ciEffectFilter = [CIFilter filterWithName:@"CIGloom"];
[ciEffectFilter setDefaults];
CIImage *resultImage = image;
[ciEffectFilter setValue: resultImage forKey:@"inputImage"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 0.75]
                  forKey:@"inputIntensity"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 20]
                  forKey:@"inputRadius"];
resultImage = [ciEffectFilter valueForKey:@"outputImage"];


CIFilter *ciCropFilter = [CIFilter filterWithName:@"CICrop"];
[ciCropFilter setDefaults];
[ciCropFilter setValue: resultImage forKey:@"inputImage"];
[ciCropFilter setValue: [CIVector vectorWithX:50 Y:50 Z:300 W:
                         300] forKey:@"inputRectangle"];

resultImage = [ciCropFilter valueForKey:@"outputImage"];

这与 NSAffineTransform 有关吗?我环顾四周,但没有找到任何答案。 多谢多谢!

I am trying to create a filter for my program (which streams a webcam) which makes the frame flip horizontally, making the webcam act like a mirror.

However, while it compiles and runs, the filter does not seem to have any effect on it.

Here is the code:

CIImage *resultImage = image;
CIFilter *flipFilter = [CIFilter filterWithName:@"CIAffineTransform"];
[flipFilter setValue:resultImage forKey:@"inputTransform"];

NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform scaleXBy:-1.0 yBy:1.0]; //horizontal flip
[flipFilter setValue:flipTransform forKey:@"inputTransform"];

resultImage = [flipFilter valueForKey:@"outputImage"];

Strangely enough, other filters appear to work. For example:

CIFilter * ciEffectFilter = [CIFilter filterWithName:@"CIGloom"];
[ciEffectFilter setDefaults];
CIImage *resultImage = image;
[ciEffectFilter setValue: resultImage forKey:@"inputImage"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 0.75]
                  forKey:@"inputIntensity"];
[ciEffectFilter setValue:[NSNumber numberWithFloat: 20]
                  forKey:@"inputRadius"];
resultImage = [ciEffectFilter valueForKey:@"outputImage"];


CIFilter *ciCropFilter = [CIFilter filterWithName:@"CICrop"];
[ciCropFilter setDefaults];
[ciCropFilter setValue: resultImage forKey:@"inputImage"];
[ciCropFilter setValue: [CIVector vectorWithX:50 Y:50 Z:300 W:
                         300] forKey:@"inputRectangle"];

resultImage = [ciCropFilter valueForKey:@"outputImage"];

Is it something to do with NSAffineTransform? I have looked around, but I have not found any answers.
Thanks heaps!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微暖i 2024-10-20 05:50:12

我不确定这是否是问题所在,但是在您的第一个代码片段中,您为同一个键设置了两个不同的值(您设置了 inputTransform 两次),我认为第一个应该是>inputImage 相反。请尝试以下操作:

CIImage *resultImage = image;
CIFilter *flipFilter = [CIFilter filterWithName:@"CIAffineTransform"];
[flipFilter setValue:resultImage forKey:@"inputImage"];

NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform scaleXBy:-1.0 yBy:1.0]; //horizontal flip
[flipFilter setValue:flipTransform forKey:@"inputTransform"];

resultImage = [flipFilter valueForKey:@"outputImage"];

此外,您可能需要将 X 轴平移图像的宽度

[flipTransform translateXBy:... yBy:0];

I'm not sure if this is the problem, but in your first code snippet you are setting two different values for the same key (you set inputTransform twice), I think the first one should be inputImage instead. Try the following instead:

CIImage *resultImage = image;
CIFilter *flipFilter = [CIFilter filterWithName:@"CIAffineTransform"];
[flipFilter setValue:resultImage forKey:@"inputImage"];

NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform scaleXBy:-1.0 yBy:1.0]; //horizontal flip
[flipFilter setValue:flipTransform forKey:@"inputTransform"];

resultImage = [flipFilter valueForKey:@"outputImage"];

Also, you may need to translate the X axis by the width of the image

[flipTransform translateXBy:... yBy:0];
海之角 2024-10-20 05:50:12
CIImage *cimage = [[CIImage alloc] initWithImage:image];

您没有分配 CIImage Object 。
试试这个代码。

CIImage *cimage = [[CIImage alloc] initWithImage:image];

You are not Allocating CIImage Object .
Try This code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文