简体   繁体   中英

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; extra bytes cause mat to load wrong. If I send byte array ( width: 4-8-12-16-20 etc) It's not a problem because width and stride is equal. 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: 在此处输入图片说明

24 width image loaded (Correctly): 在此处输入图片说明

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 . It lets you tell OpenCV how many bytes are in each row (including padding).

You'll also have to check if the byte array you're using as input has any added padding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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