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



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

senario 1:

如果您设置为camera_default其始终后置摄像头。

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

塞纳里奥2:

如果您使用的是AVCaptureDeviceInput类:

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

您可以根据需要进行设置。

如果我理解正确的话,您在 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云。如果您有任何其他想法,请告诉我,谢谢!

最新更新