2

我需要水平翻转一些我正在预览和捕捉的视频。A-la iChat,我有一个网络摄像头,希望它看起来好像用户在照镜子。

我正在预览 Quicktime 视频QTCaptureView。我的捕获是逐帧完成的(出于我不会进入的原因),例如:

imageRep = [NSCIImageRep imageRepWithCIImage: [CIImage imageWithCVImageBuffer: frame]];
image = [[NSImage alloc] initWithSize: [imageRep size]];
[image addRepresentation: imageRep];
[movie addImage: image forDuration: someDuration withAttributes: someAttributes];

有小费吗?

4

3 回答 3

10

没有什么比复活一个老问题更重要的了。无论如何,我来到这里,几乎找到了我要寻找的东西,这要归功于 Brian Webster,但是如果有人正在寻找批发解决方案,请在将您的类设置为QTCaptureView实例的代表后尝试以下操作:

- (CIImage *)view:(QTCaptureView *)view willDisplayImage:(CIImage *)image {
//mirror image across y axis
return [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
}
于 2010-01-03T07:51:17.473 回答
3

您可以通过获取从捕获中获取的 CIImage 并通过核心图像过滤器运行它来翻转图像来做到这一点。然后,您会将生成的图像传递给您的图像代表,而不是原始图像。代码看起来像:

CIImage* capturedImage = [CIImage imageWithCVImageBuffer:buffer];
NSAffineTransform* flipTransform = [NSAffineTransform transform];
CIFilter* flipFilter;
CIImage* flippedImage;

[flipTransform scaleByX:-1.0 y:1.0]; //horizontal flip
flipFilter = [CIImage filterWithName:@"CIAffineTransform"];
[flipFilter setValue:flipTransform forKey:@"inputTransform"];
[flipFilter setValue:capturedImage forKey:@"inputImage"];
flippedImage = [flipFilter valueForKey:@"outputImage"];
imageRep = [NSCIImageRep imageRepWithCIImage:flippedImage];
...
于 2009-05-04T15:32:17.770 回答
0

试试这个!它会将过滤器应用于 CaptureView,但不会应用于输出视频。

- (IBAction)Vibrance:(id)sender
{
    CIFilter* CIVibrance = [CIFilter filterWithName:@"CIVibrance" keysAndValues:
                            @"inputAmount", [NSNumber numberWithDouble:2.0f],
                            nil];
    mCaptureView.contentFilters = [NSArray arrayWithObject:CIVibrance];
}

顺便说一句,您可以从此参考应用任何过滤器:https ://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html

于 2013-02-08T12:24:58.443 回答