0
votes

Whenever i read a colored image with 3 channels via cv::imread; its data alignment is a bit awkward (neither a byte nor an integer) and slows me down when i read a single pixel data on GPU memory. And it seems cv::Mat class's logic behind the alignment is a bit different than what i had initially thought. It does not add an extra byte between two pixels in a single row in order to have each pixel in a row started at every 4 bytes; but rather it pads some extra bytes at the END of each row for which any row may start at every 4 bytes boundary.

What should i do to pack each pixel data into a single unsigned integer? Is there a built-in method in OpenCV so that i do not have to use logical OR operation for packing each pixel data one by one?

Kind Regards.

1
What about using BYTE an assume 3 times the number of pixels?Micka
To use a single INT i would convert to BGRA and just ignore the alpha channel!Micka
You do this conversion after you read the data? How? Is there a method in cv::Mat to do that conversion?iliTheFallen
cv::cvtColor(yourMat, newMat, CV_BGR2BGRA); but this operation might be slower than similar operations on the GPU ;)Micka

1 Answers

1
votes

You can convert the pixel format from BGR to BGRA

See this example.