Reputation: 3125
I have an array of pixel data that makes up an image. The data is in the format:
vector<FColor> ColorBuffer;
where FColor is a struct like this:
struct FColor
{
uint8 B;
uint8 G;
uint8 R;
uint8 A;
};
I have the image size (Width, Height).
What i need to do is convert this data to a cv::Mat.
I am trying:
cv::Mat tester = cv::Mat(Width, Height, CV_8UC3);
for (int i = 0; i < Width; i++)
{
for (int j = 0; j < Height; j++)
{
cv::Vec3d px(ColorBuffer[i + j].B, ColorBuffer[i + j].G, ColorBuffer[i + j].R);
tester.at<cv::Vec3d>(j, i) = px;
}
}
But this gives me a scrambled image. Where am I going wrong here? Should i be using something else in place of cv::Vec3d
? Or do i have the logic wrong?
Upvotes: 1
Views: 527
Reputation: 8851
The index for a point inside ColorBuffer
seems to be incorrect, instead of
ColorBuffer[i + j]
you should use something like
ColorBuffer[i + j*Width]
Upvotes: 1