使用 kCVPixelFormatType_32BGRA 在 AVCaptureVideoData 处填充

发布于 2024-11-07 22:00:25 字数 493 浏览 0 评论 0原文

我试图通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再可℃爱ぅ一点好了 2024-11-14 22:00:25

您可能获得的唯一填充是每行像素 - 您应该使用类似以下内容的内容:

/* ... */
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);

for(interesting values of y)
{
    uint8_t *pointerToThisLine = baseAddress + bytesPerRow*y;
}

而不是假设一条扫描线在内存中的某个位置结束,然后下一条扫描线立即开始。

也就是说,图像的顶部显然是正确的,而且我还没有看到间距不等于 width*bytesPerPixel 的实例,因此即使您没有,它也不太可能在实践中引起您的问题没有正确地做到这一点。

检查您的图像,看起来损坏的区域包含工作区域各种片段的副本,因此我认为问题与填充无关 - 这是某种更迟钝的内存管理或传输错误。你检查过那方面的事情吗?

The only padding you may get is per row of pixels — you should use something like:

/* ... */
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);

for(interesting values of y)
{
    uint8_t *pointerToThisLine = baseAddress + bytesPerRow*y;
}

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文