使用 kCVPixelFormatType_32BGRA 在 AVCaptureVideoData 处填充
我试图通过 tcp 将图像发送到服务器,首先从相机获取缓冲区,然后将缓冲区转换为灰度,最后将缓冲区发送到服务器。 一切工作正常,但问题是服务器接收到的图像不是 100% 正常,看起来有一些填充我在转换时没有使用,所有图像或多或少都比下一个图像多或少。 我使用下一个代码来获取图像: VImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
uint8_t * baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
图片在这里 http://s3.subirimagenes.com:81/imagen/previo /thump_6421684image001.png
I´m trying to send a image through tcp to a server, firts getting the buffer from the camera and then converting to grayScale the buffer, finally I send the buffer to the server.
All is working fine, but the problem is that the image that the server receive it is not 100 % okay, it looks like there is some padding that I dind´t use at the conversion, all the images are more or less than the next.
I use the next code to get the image:
VImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
uint8_t * baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
the image is here http://s3.subirimagenes.com:81/imagen/previo/thump_6421684image001.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能获得的唯一填充是每行像素 - 您应该使用类似以下内容的内容:
而不是假设一条扫描线在内存中的某个位置结束,然后下一条扫描线立即开始。
也就是说,图像的顶部显然是正确的,而且我还没有看到间距不等于 width*bytesPerPixel 的实例,因此即使您没有,它也不太可能在实践中引起您的问题没有正确地做到这一点。
检查您的图像,看起来损坏的区域包含工作区域各种片段的副本,因此我认为问题与填充无关 - 这是某种更迟钝的内存管理或传输错误。你检查过那方面的事情吗?
The only padding you may get is per row of pixels — you should use something like:
Rather than assuming, one way or another, that one scanline ends somewhere in memory and then the next immediately starts.
That said, the top portion of your image is clearly correct and I've yet to see an instance where pitch wasn't equal to width*bytesPerPixel, so it'd be unlikely to be causing your problem in practice even if you haven't done that correctly.
Inspecting your image, it looks like the broken region contains copies of various fragments of the working region, so I don't think the problem is padding related — it's some sort of more obtuse memory management or transmission error. Have you checked that side of things?