iOS: Get pixel-by-pixel data from camera

后端 未结 2 1139
悲&欢浪女
悲&欢浪女 2020-12-01 04:47

I\'m aware of AVFoundation and its capture support (not too familiar though). However, I don\'t see any readily-accessible API to get pixel-by-pixel data (RGB-per-pixel or s

相关标签:
2条回答
  • 2020-12-01 05:34
     lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
     float luminance = dot(textureColor.rgb, W);
    
     mediump vec2 p = textureCoordinate;
     if (p.x == 0.2 && p.x<0.6 && p.y > 0.4 && p.y<0.6) {
         gl_FragColor = vec4(textureColor.r * 1.0, textureColor.g * 1.0, textureColor.b * 1.0, textureColor.a);
     } else {
       gl_FragColor = vec4(textureColor.r * 0.0, textureColor.g * 0.0, textureColor.b * 0.0, textureColor.a *0.0);
     }
    
    0 讨论(0)
  • 2020-12-01 05:40

    AV Foundation can give you back the raw bytes for an image captured by either the video or still camera. You need to set up an AVCaptureSession with an appropriate AVCaptureDevice and a corresponding AVCaptureDeviceInput and AVCaptureDeviceOutput (AVCaptureVideoDataOutput or AVCaptureStillImageOutput). Apple has some examples of this process in their documentation, and it requires some boilerplate code to configure.

    Once you have your capture session configured and you are capturing data from the camera, you will set up a -captureOutput:didOutputSampleBuffer:fromConnection: delegate method, where one of the parameters will be a CMSampleBufferRef. That will have a CVImageBufferRef within it that you access via CMSampleBufferGetImageBuffer(). Using CVPixelBufferGetBaseAddress() on that pixel buffer will return the base address of the byte array for the raw pixel data representing your camera frame. This can be in a few different formats, but the most common are BGRA and planar YUV.

    I have an example application that uses this here, but I'd recommend that you also take a look at my open source framework which wraps the standard AV Foundation boilerplate and makes it easy to perform image processing on the GPU. Depending on what you want to do with these raw camera bytes, I may already have something you can use there or a means of doing it much faster than with on-CPU processing.

    0 讨论(0)
提交回复
热议问题