位图不正确;这怎么可能
我正在尝试用 C++ 代码分析车牌。重点不是如何快速到达那里,因为我想亲自创建此 C++ 代码并学习如何创建该代码。
问题:
位图文件中的字节不相加!位图文件: http://ictmdeklerk.nl/cor.bmp
为什么它们不相加:
我正在使用 24 位位图图像(*.BMP 文件)。我知道位图是用 BMPFILEHEADER 和 BMPINFOHEADER 构建的,它们总共消耗 54 个字节。
现在,图像宽 1350 像素,高 740 像素,即 999000 像素。
由于文件是 24 位,因此每个像素有 3 个字节。图像需要 999000 * 3 = 2997000 字节。但是BMPINFOHEADER中的图像大小(biSizeImage)表示图像是2998480字节!文件大小实际上是 2.998.534 字节 - 54 个标头字节 = 2.998.480。所以头部仍然是54字节。那里没有额外的元数据。当我将每个像素除以 2.998.480 / 3 字节时,我得到 999493,33 个像素!它甚至不是一个整数!
这让我发疯。 Windows 如何知道如何在不移动像素或颜色或任何其他内容的情况下显示此图像?
谁能解释一下这些额外的像素/字节来自哪里?以及如何应对他们?
提前致谢!
I am trying to analyze license plates with C++ code. The point is NOT how to get there fast, because I want to go to the process of creating this C++ code myself and learning how to.
Problem:
The bytes in the bitmap file don't add up! The bitmap file:
http://ictmdeklerk.nl/cor.bmp
Why they dont add up:
I am using 24 bit bitmap images (*.BMP files). I know the bitmap is constructed with the BMPFILEHEADER, and BMPINFOHEADER, which togehter consume 54 bytes.
Now, the image is 1350 pixels wide and 740 pixels high, which results in 999000 pixels.
Because the file is 24 bit, there are 3 bytes per pixel. 999000 * 3 = 2997000 bytes neccessary for the image. But the image size (biSizeImage) in the BMPINFOHEADER says the image is 2998480 bytes! The file size is 2.998.534 bytes - 54 header bytes = 2.998.480 indeed. So the header is still 54 bytes. No extra meta data there. When I divide 2.998.480 / 3 bytes per pixel I get 999493,33 pixels! It is not even a round number!
It is driving me insane. How does windows ever know how to show this image without shifting pixels or colors or anything?
Can anyone explain me where these extra pixels/bytes come from? And how to deal with them?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BMP 文件将每行填充到 4 字节边界。
您的图像为
(1350 像素宽)x(每像素 3 字节)= 每行 4050 字节。
4050 不能被 4 整除,但 4052 可以被 4 整除,因此每行添加 2 个字节(2 * 740 = 1480 字节)作为图像的填充。
因此,文件大小为 2997000 图像字节 + 54 字节标头 + 1480 字节行填充 = 2998534 字节,这是实际文件大小。
BMP files pad each row to 4-byte boundaries.
Your image is
(1350px wide) x (3 bytes per pixel) = 4050 bytes per row.
4050 is not divisible by 4, but 4052 is so 2 bytes for every row (2 * 740 = 1480 bytes) are added as padding to your image.
The file size is therefore 2997000 image bytes + 54 bytes header + 1480 bytes row padding = 2998534 bytes, which is the actual file size.