ios - Broken cv:Mat from CMSampleBufferRef when using AVCaptureSessionPresetPhoto -


i using code create cv::mat cmsamplebufferref. works fine avcapturesessionpreset's (high, medium, low) when use avcapturesessionpresetphoto outputs garbled image.

- (cv::mat) matfromsamplebuffer:(cmsamplebufferref) samplebuffer {     cvimagebufferref pixelbuffer = cmsamplebuffergetimagebuffer(samplebuffer);      cvpixelbufferlockbaseaddress( pixelbuffer, 0 );      int bufferwidth = cvpixelbuffergetwidth(pixelbuffer);     int bufferheight = cvpixelbuffergetheight(pixelbuffer);     unsigned char *pixel = (unsigned char *)cvpixelbuffergetbaseaddress(pixelbuffer);      cv::mat mat(bufferheight,bufferwidth,cv_8uc4,pixel);      cvpixelbufferunlockbaseaddress( pixelbuffer, 0 );      return mat; } 

when use avcapturesessionpresetphoto produces:

garbled

but other profiles create cv:mat fine. can help?

solved, missing step size in bytes:

- (cv::mat) matfromsamplebuffer:(cmsamplebufferref) samplebuffer {     cvimagebufferref pixelbuffer = cmsamplebuffergetimagebuffer(samplebuffer);      cvpixelbufferlockbaseaddress( pixelbuffer, 0 );      int bufferwidth = cvpixelbuffergetwidth(pixelbuffer);     int bufferheight = cvpixelbuffergetheight(pixelbuffer);     int bytesperrow = cvpixelbuffergetbytesperrow(pixelbuffer);     unsigned char *pixel = (unsigned char *)cvpixelbuffergetbaseaddress(pixelbuffer);      cv::mat mat(bufferheight,bufferwidth,cv_8uc4,pixel,bytesperrow);      cvpixelbufferunlockbaseaddress( pixelbuffer, 0 );      return mat; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -