首页 文章

如何在vuforia sdk中捕获iOS上的AR视图

提问于
浏览
0

我正在使用vuforia SDK来增强现实应用程序 . 问题是当尝试捕获当前相机帧时,它总是给出黑色图像

2 回答

  • 0

    Senario 1:

    如果你设置camera_default它总是后置摄像头 .

    如果你想要前置摄像头:CAMERA_FRONT

    Senario 2:

    如果你使用AVCaptureDeviceInput类:

    AVCaptureDeviceDiscoverySession *discoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:allTypes mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack];
    

    你可以根据你的要求设置 .

  • 0

    如果我理解正确,你在Vuforia中获得了当前的 Frame 对象,但是将其转换为UIImage对象并且图像是黑色的 . 所以我认为问题是PIXEL_FORMAT你没有设置好 .

    这是我从 Frame 对象获取UIImage对象:

    - (UIImage *)createUIImage:(const Vuforia::Image *)image
    {
        int width = image->getWidth();
        int height = image->getHeight();
        int bitsPerComponent = 8;
        int bitsPerPixel = Vuforia::getBitsPerPixel(Vuforia::RGB888);
        int bytesPerRow = image->getBufferWidth() * bitsPerPixel / bitsPerComponent;
        CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
        CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaNone;
        CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
    
        CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, image->getPixels(), Vuforia::getBufferSize(width, height, Vuforia::RGB888), NULL);
    
        CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
        UIImage *result = [UIImage imageWithCGImage:imageRef];
    
        CGDataProviderRelease(provider);
        CGColorSpaceRelease(colorSpaceRef);
        CGImageRelease(imageRef);
    
        return result;
    }
    

    Vuforia::Image 对象来自 const Vuforia::Image *image = frame.getImage(i);

    你可能注意到我设置的像素格式是 Vuforia::RGB888 ,你不应该忘记在制作截图之前设置相同的格式 Vuforia::setFrameFormat(Vuforia::RGB888, true);

    我使用此方法获取用户定义目标(UDT)图像并上传到Vuforia Cloud . 如果您有任何其他想法,请告诉我,谢谢!

相关问题