简体   繁体   English

OpenCV无法从字节数组加载位图(具有额外的跨步字节)

[英]OpenCV Cant load Bitmap (with extra stride bytes) from byte array

I have problem. 我有问题。 When I'm loading mat from byte array there is a big problem; 当我从字节数组加载mat时,有一个大问题; extra bytes cause mat to load wrong. 多余的字节会导致mat加载错误。 If I send byte array ( width: 4-8-12-16-20 etc) It's not a problem because width and stride is equal. 如果我发送字节数组(宽度:4-8-12-16-20等),这不是问题,因为宽度和步幅相等。 But If I byte array with extra stride bytes Image is corrupted. 但是,如果我使用额外的跨步字节字节数组,则图像已损坏。 Is there a way to make it right ? 有没有办法做到这一点?

Function that I'm using: 我正在使用的功能:

Mat bytesToMat(byte * bytes,int height,int width)
{
    Mat image = Mat(height,width,CV_8UC3,bytes).clone(); // make a copy
    return image;
}

Example) 例)

23 width image loaded as: 23宽度图像加载为: 在此处输入图片说明

24 width image loaded (Correctly): 已加载24宽度图像(正确): 在此处输入图片说明

The link format was messed up in the comment, so I'll write an answer. 链接格式在注释中弄乱了,所以我要写一个答案。

See the constructor step and steps parameters in the documentation . 请参阅文档中的构造函数stepsteps参数。 It lets you tell OpenCV how many bytes are in each row (including padding). 它可以让您告诉OpenCV每行多少字节(包括填充)。

You'll also have to check if the byte array you're using as input has any added padding. 您还必须检查用作输入的字节数组是否添加了任何填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM