[英]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.