Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. //Buffer is of type CVImageBufferRef, which is what AVFoundation should be giving you
  2. //I assume it is BGRA or RGBA formatted, if it isn't, change CV_8UC4 to the appropriate format
  3.  
  4. CVPixelBufferLockBaseAddress( Buffer, 0 );
  5.  
  6. int bufferWidth = CVPixelBufferGetWidth(Buffer);
  7. int bufferHeight = CVPixelBufferGetHeight(Buffer);
  8.  
  9. unsigned char *pixel = (unsigned char *)CVPixelBufferGetBaseAddress(Buffer);
  10. cv::Mat image = cv::Mat(bufferHeight,bufferWidth,CV_8UC4,pixel); //put buffer in open cv, no memory copied
  11.  
  12. //Process image Here
  13.  
  14. //End processing
  15. CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );
  16.  
  17. for ( uint32_t y = 0; y < height; y++ )
  18. {
  19. for ( uint32_t x = 0; x < width; x++ )
  20. {
  21. bgraImage.at<cv::Vec<uint8_t,4> >(y,x)[1] = 0;
  22. }
  23. }
  24.  
  25. cv::Mat bgraImage = cv::Mat( (int)height, (int)extendedWidth, CV_8UC4, base );
  26. cv::Mat grey = bgraImage.clone();
  27. cv::cvtColor(grey, grey, 44);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement