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:
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
Post a Comment