Ask Your Question
0

cvSetData( pImgEmbed, data, m_width ) doesn't work! Anybody Help!

asked 2012-09-05 03:34:30 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

IplImage* gray;
BYTE* data;
int m_width;
int m_height;

IplImage * pImgEmbed = NULL;

char*filename=argc==2?argv[1]:(char*)"14.bmp";
gray=cvLoadImage(filename,0);
data=(uchar *)gray->imageData;
          m_width=gray->width;
          m_height=gray->height;

pImgEmbed=cvCreateImageHeader(cvSize(m_width, m_height), IPL_DEPTH_8U, 1);

cvSetData( pImgEmbed, data, m_width );

Now ,I think pImgEmbed is a IplImage image ,but I can't use

cvNamedWindow("window");
cvShowImage("window", pImgEmbed);

to show it,Why?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-09-05 06:09:23 -0600

AlexanderShishkov gravatar image

It is strange. This code is working for me:

int main( int argc, char** argv )
{
IplImage* gray;
uchar* data;
int m_width;
int m_height;

IplImage * pImgEmbed = NULL;

char filename[] = "baboon.jpg";
gray=cvLoadImage(filename,0);
data=(uchar *)gray->imageData;
          m_width=gray->width;
          m_height=gray->height;

pImgEmbed=cvCreateImageHeader(cvSize(m_width, m_height), IPL_DEPTH_8U, 1);

cvSetData( pImgEmbed, data, m_width );
cvNamedWindow("sample");
cvShowImage("sample", pImgEmbed);
cvWaitKey(0);
return 0;
}

What version of OpenCV do you use? What OS?

edit flag offensive delete link more

Comments

Thank you very much! You are very helpful! I am so careless! Those codes are I pick up from my program.But I don't notes the line ,so I very silly, to create pImgEmbed imageheader before give m_width and m_height value.Then I check the codes again and again ,just found out pImgEmbed->widthstep is 0.

winne gravatar imagewinne ( 2012-09-06 02:59:20 -0600 )edit

Question Tools

Stats

Asked: 2012-09-05 03:34:30 -0600

Seen: 5,451 times

Last updated: Sep 05 '12