c++ - 将原始 IOS 相机数据上传到纹理

标签 c++ ios opengl-es camera render-to-texture

我们在 IOS 上使用 AVCaptureDevice 扫描二维码。我们使用 AVCaptureMetadataOutput 将相机的输出传递给识别二维码的代码,目前我们还在 Open GL View 上将相机显示为单独的 View 。但是,我们现在希望其他图形显示在相机预览上,因此我们希望能够将相机数据加载到我们的 Open GL 纹理之一。

那么,有没有办法从相机获取原始RGB数据

这是我们用来初始化捕获设备和 View 的代码(如下)。

我们如何修改它来访问 RGB 数据,以便我们可以将其加载到我们的 GL 纹理之一?我们正在使用 C++/Objective C

谢谢

肖恩南方

self.captureSession = [[AVCaptureSession alloc] init];

NSError *error;
// Set camera capture device to default and the media type to video.
AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
// Set video capture input: If there a problem initialising the camera, it will give am error.
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];

if (!input) 
{
    NSLog(@"Error Getting Camera Input");
    return;
}
// Adding input souce for capture session. i.e., Camera
[self.captureSession addInput:input];

AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
// Set output to capture session. Initalising an output object we will use later.
[self.captureSession addOutput:captureMetadataOutput];

// Create a new queue and set delegate for metadata objects scanned.
dispatch_queue_t dispatchQueue;
dispatchQueue = dispatch_queue_create("scanQueue", NULL);
[captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];

// Delegate should implement captureOutput:didOutputMetadataObjects:fromConnection: to get callbacks on detected metadata.
[captureMetadataOutput setMetadataObjectTypes:[captureMetadataOutput availableMetadataObjectTypes]];

// Layer that will display what the camera is capturing.

self.captureLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
[self.captureLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

gCameraPreviewView= [[[UIView alloc] initWithFrame:CGRectMake(gCamX1, gCamY1, gCamX2-gCamX1, gCamY2-gCamY1)] retain];
[self.captureLayer setFrame:gCameraPreviewView.layer.bounds];
[gCameraPreviewView.layer addSublayer:self.captureLayer];

UIViewController * lVC = [[[UIApplication sharedApplication] keyWindow] rootViewController];
[lVC.view addSubview:gCameraPreviewView];

最佳答案

您不需要直接访问 rgb 相机帧来将其作为纹理,因为 IOS 支持比您更快的纹理缓存。

- (void) writeSampleBuffer:(CMSampleBufferRef)sampleBuffer ofType:(NSString *)mediaType pixel:(CVImageBufferRef)cameraFrame time:(CMTime)frameTime;

在回调方法中,您可以使用下面的参数和函数生成纹理

  CVOpenGLESTextureCacheCreate(...)
  CVOpenGLESTextureCacheCreateTextureFromImage(...)

关于c++ - 将原始 IOS 相机数据上传到纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45738681/

相关文章:

c++ - 我的程序无法在某些 PC 上运行

c++ - 在文本文件中一起打印 hex 和 int

java - 如何捕获 "Fatal signal 11 (SIGSEGV)"?

ios - 从 UITableViewCell 呈现 UIAlertController

ios - 将多个渲染目标 (MRT) 与多重采样相结合在 iOS 设备上失败,而不是在模拟器上

iphone - OpenGL ES iPhone 中的橡皮擦

C++ 在 PATH 的所有文件中搜索

c++ - 如何读取 infile 中的指令,然后使用 infile 中的参数将函数形状写入 outfile

ios - 使用 Quincy Kit 符号化崩溃日志,给我这个错误

ios - 在两个 UIViewController 堆栈之间转换