翻转Quicktime预览&捕获

时间:2009-05-04 14:09:40

标签: objective-c cocoa quicktime

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

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

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

任何提示?

3 个答案:

答案 0 :(得分:10)

没有什么能像复活旧问题一样。无论如何,我来到这里,几乎找到了我想要的东西,感谢Brian Webster,但是如果有人在寻找批发解决方案,请在将您的课程设置为QTCaptureView实例的代表后尝试此操作:

- (CIImage *)view:(QTCaptureView *)view willDisplayImage:(CIImage *)image {
//mirror image across y axis
return [image imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
}

答案 1 :(得分:3)

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

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];
...

答案 2 :(得分: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