繁体   English   中英

以CIImage访问OpenGL纹理

[英]Access an OpenGL texture as a CIImage

我正在尝试将相机纹理的参考传递到xcode中,以便随后将其用于面部检测。 我尝试过的大多数方法都使我感到困惑,但我认为我与当前的方法很接近。

我统一获得纹理ID,并将其通过插件传递:

[DllImport("__Internal")]

public static extern void SendBackground(int id, int width, int height);



//in Update

Texture bg_Img = GetComponentInChildren<VideoTextureBehaviour>().GetTexture(); //this is from Vuforia

int texture_Id = bg_Img.GetNativeTextureID();

SendBackground(texture_Id, bg_Img.width, bg_Img.height);

xcode可以很好地接收纹理ID,然后尝试从OpenGL访问它并将其获取到CIImage

- (void) DetectFaces:(int)tex_id :(int)width :(int)height

{

    glGenTextures(1, (GLuint)&tex_id);

    glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id);



    CIImage *image = [[CIImage alloc]  initWithTexture:(GLuint)tex_id size:CGSizeMake(width, height) flipped:YES colorSpace: (CGColorSpaceRef) kCGColorSpaceModelRGB];

}

当前,最后一行在运行时导致错误的访问异常。 我需要将纹理获取到CIImage,以便可以在其上使用iOS本机CIDetector代码。

您的色彩空间有问题,当需要CGColorSpaceRef时,您正在传递CGColorSpaceModel。

尝试以下方法:

CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CIImage *image = [[CIImage alloc]  initWithTexture:(GLuint)tex_id size:CGSizeMake(width, height) flipped:YES colorSpace:(CGColorSpaceRef)kCGColorSpaceModelRGB];
...
CGColorSpaceRelease(cs); // Release the color space when you no longer need it

虽然可能还有其他问题,但是对我来说这绝对是不正确的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM