Ask Your Question
0

Initialize Mat with color data

asked 2014-04-29 10:21:31 -0600

Gunter gravatar image

Hello, I'm trying to initialize a Mat with BGR data. I'm getting a strange results.

I do this all the time: Mat image(Size(cols, rows), CV_8UC1, (void*) inputData, Mat::AUTO_STEP);

But when I do it with a color image the output mat is not correct (its offset in all of BGR data, vertical and horizontal dimensions).

Even if I trim the code to:

Mat image2 = Mat(Size(imageIn.cols, imageIn.rows), imageIn.type(), imageIn.data, Mat::AUTO_STEP);

image2 is not imageIn.

imageIn.type() is CV_8UC3.

What am I doing wrong?

Thanks for your help,

Gunter

edit retag flag offensive close merge delete

Comments

Hi,i think you should chek the size of your source image ,especially column number,It should be quadruple to show image.for example.your source image size is 21x21,you should declare new image size 21x24.Then you fill data one pixel by one pixel. The other is seted to zero,

wuling gravatar imagewuling ( 2014-04-29 18:56:33 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-04-30 01:56:43 -0600

FLY gravatar image

If you first image is

Mat img = imread("lena.jpg");

then your 2nd image should be like

Mat img2 = Mat(img.size(),img.type());
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-29 10:21:31 -0600

Seen: 712 times

Last updated: Apr 30 '14