2009-10-12 50 views
0

我正在使用Mac OS X,10.6如何设置图像透视

如何设置任何图像的图像透视图?

我不想使用CoreImage。

是否有可能通过NSAffineTransforms来做到这一点。

Regards, Dhana。

+1

我想不出一个_single_理由不使用CoreImage。 – 2009-10-12 18:10:57

+0

显然,使用配置项时,操作系统遇到大图像(大于4000 x 2500像素)的问题。请参阅:http://stackoverflow.com/questions/1553793/coreimage-patches-problems-in-10-6虽然这应该在问题中提到。 – VoidPointer 2009-10-13 12:05:37

回答

0

您不能用仿射变换表示透视变换。但是,在CoreImage中,您可以使用ImageUnit(CoreImage的名称代表您通常称为“过滤器”的名称)对图像(以及许多其他很酷的东西)进行透视变换。

请参阅CIPerspectiveTransform并查看CoreImage开发人员指南中的section about CoreImage Filters。这应该让你去。

基本上你做的是...

perspectiveTransform = [CIFilter filterWithName:@"CIPerspectiveTransform"]; 
[perspectiveTransform setDefaults]; 
[perspectiveTransform setValue: myCIImage forKey: @"inputImage"]; 
[perspectiveTransform setValue: myToLeft forKey: @"inputTopLeft"]; 
// ... also set inputTopRight, inputBottomLeft and inputBottomRight 
// if you have the coordinates of the corner points you can create 
// CIVector instances with 
// + (CIVector *)vectorWithX:(CGFloat)x Y:(CGFloat)y 
// ... 
result = [perspectiveTransform valueForKey: @"outputImage"]; 
+0

是的,使用CoreImage过滤器工作正常。 但是会出现下面提到的缺陷。 http://stackoverflow.com/questions/1553793/coreimage-patches-problems-in-10-6 所以我想避免使用它来摆脱bug。 – Dhanaraj 2009-10-12 13:31:17

+0

对不起。我读过你想要使用CoreImage,而不是你明确不想使用它。 – VoidPointer 2009-10-12 13:37:27

1

对于不使用CoreImage的解决方案,你需要自己实现转型。它不能作为仿射变换来完成。 This paper解释了这个过程相当不错。

如果您自己无法编写代码,则可以查看实现透视变换的其他第三方库。其中一个选项是ImageMagick。他们提供透视变换作为命令行工具,他们还有一个C API,您可以使用它来在您自己的程序中获得相同的功能。

+0

感谢VP。 有没有办法解决10.6中CoreImage的补丁问题? – Dhanaraj 2009-10-13 05:58:00

+1

您是否尝试禁用硬件渲染?参见:http://stackoverflow.com/questions/1553793/coreimage-patches-problems-in-10-6/1554740#1554740 – VoidPointer 2009-10-13 12:07:32

0

处理图像透视的另一种方法是使用Core Animation应用具有透视的3D转换。你可以把你的图像放在CALayer中(作为图层的内容),或者将你的NSImageView分层。我描述了如何创建透视CATransform3D并将其应用于this answer中的图层,但关键是将CATransform3D的m34元素设置为负值以创建透视效果。迈克李在这here有一个写法,以及一些sample code