0

I am using CVPixelBuffer as data from camera, and I wanted to get specific pixel e.g.(0,100) and its corresponding colour as RGB.

I have tried multiple ways such as retrieving data by the Base Address and the code as below:

        var address = CVPixelBufferGetBaseAddress(framePixelBuffer)
        var bytesPerRow = CVPixelBufferGetBytesPerRow(framePixelBuffer)
      
        var c = CVPixelBufferGetWidth(framePixelBuffer)
        var p = address?.assumingMemoryBound(to: UInt8.self)
        let index = 0*1 + 100*bytesPerRow
        let b = p![index]
        let g = p![index+1]
        let r = p![index+2]

But seems its not the correct RGB data which I have check multiple times with active camera

burnsi
  • 6,194
  • 13
  • 17
  • 27
7wiCey
  • 3
  • 2

0 Answers0