CVPixelBufferRef RDB 및 YUV 제거

2451 단어

꺼내기


-(int) getImageData:(const CVImageBufferRef&) imageBuffer senddata:(unsigned char)data { int w,h,linesizey,linesizeuv; unsigned char srcy=NULL; unsigned char* srcu=NULL; unsigned char* srcv=NULL;
CVPixelBufferLockBaseAddress(imageBuffer, 0);
int count=CVPixelBufferGetPlaneCount(imageBuffer);
//printf("CVPixelBufferGetPlaneCount=%d
",count); if (CVPixelBufferIsPlanar(imageBuffer)) { w = CVPixelBufferGetWidth(imageBuffer); h = CVPixelBufferGetHeight(imageBuffer); // printf("w: %d,h: %d.
",w,h); linesizey = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0); linesizeuv = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 1); // printf("CVPixelBufferGetBytesPerRowOfPlane is ok.
"); srcy = (unsigned char*) CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0); srcu = (unsigned char*) CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 1); srcv = (unsigned char*) CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 2); memcpy(data,srcy,720*1280); memcpy(data+720*1280,srcu,720*1280/4); memcpy(data+720*1280*5/4,srcv,720*1280/4); // printf("CVPixelBufferGetBaseAddressOfPlane is ok.
"); } else { printf("CVPixelBufferIsPlanar error
"); return -1; } return 0;

}

RGB 체크 아웃

  • (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer,0); size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); uint8_t src_buff = (uint8_t)CVPixelBufferGetBaseAddress(imageBuffer); CVPixelBufferUnlockBaseAddress(imageBuffer, 0); RGBPixel *pixelData = (RGBPixel *)src_buff; int len = bytesPerRow * height; for(int i=0; i
      RGBPixel pixel = pixelData[i/4];
      
      int a = 0;
      int r = pixel.red;
      int g = pixel.green;
      int b = pixel.blue;
    
      NSLog(@"first values = r:%d g:%d b:%d", r, g, b);
      
      a = src_buff[i+3];
      r = src_buff[i+2];
      g = src_buff[i+1];
      b = src_buff[i];
    
      NSLog(@"second values = r:%d g:%d b:%d", r, g, b);
    
    }

  • }
    http://www.bubuko.com/infodetail-526746.html

    좋은 웹페이지 즐겨찾기