Help converting IplImage2Bitmap!!!

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Help converting IplImage2Bitmap!!!

epcdomingos
Hi forum!
I´m continuing the development of the eyetracking tool!
However, I´m still facing problems in the conversion from IplImage to Bitmap, in order to show the processed images in a GUI.
The problem is this:

->If I´m converting a 3 channel image, everything runs smooth...The image is converted from bitmap to iplimage, it is processed with opencv functions, and finally it´s converted from iplimage to bitmap in order to be showed in the picture box.

->But if I´m converting a gray image (1 channel image), the result is not the expected: 6 smaller gray images appear together inside the picture box (note that I managed the picturebox properties to center the image ,to avoid this problem!).

In order to solve this, I tried to use cvMerge, in order to  "fool" the conversion (giving it allways a 3 channel IplImage image), but still continued to get the same result.
I used it before doing the conversion from IplImage2Bitmap :

cvMerge(img1channel, img1channel, img1channel,cvCreateImage(cvSize(hW, hH), 8, 1), img3channel);

So anyone have had the same problem? Could you help me? I´m trying to solve this for 6 hours , and I´m getting crazy....

(I want to attach the sample of the code, but currently that option is not available...)

help me please ;)

Best Reagards
Eduardo


Reply | Threaded
Open this post in threaded view
|

Re: Help converting IplImage2Bitmap!!!

Matthias Schmieder
Hi,

I don't know with what algorithm you do convert your IplImage to a bitmap, but in the most cases the IplImage has to be in the IPL_DEPTH_8U format to get processed correctly. This means that all values inside the array have to be normalized values between 0 and 255.

Also your usage of the cvMerge function is kind of odd and definitely will cause some memory leakages. If you try to merge only three channels the fourth parameter has to be set to NULL. In your case you're allocating memory that will never be released. The the correct function call should look like this:

cvMerge(img1channel, img1channel, img1channel,NULL, img3channel);
If your algorithm works for other three channel images it should work on your 'img3channel'-image. What you can do is check whether the bit-depth is different of if the image is show correctly using opencv specific functions like

cvNamedWindow("anyWindow");
cvShowImage("anyWindow",img3channel);
cvWaitKey(0);
Are you sure, that you've allocated the 'img3channel' correctly? I'm not entirely sure, but I think the image has to be pre-allocated with the correct size and bit depth. So the complete call of the functions should look anything like this

// pre-allocate rgb image
IplImage* img3channel = cvCreateImage(cvGetSize(img1channel),img1channel->depth,3);

// merge one channel images to three channel rgb image
cvMerge(img1channel, img1channel, img1channel,NULL, img3channel);

// show image with opencv
cvNamedWindow("anyWindow");
cvShowImage("anyWindow",img3channel);
cvWaitKey(0);
Hope this will help you to come any further...


Greetings
Matthias

epcdomingos wrote
Hi forum!
I´m continuing the development of the eyetracking tool!
However, I´m still facing problems in the conversion from IplImage to Bitmap, in order to show the processed images in a GUI.
The problem is this:

->If I´m converting a 3 channel image, everything runs smooth...The image is converted from bitmap to iplimage, it is processed with opencv functions, and finally it´s converted from iplimage to bitmap in order to be showed in the picture box.

->But if I´m converting a gray image (1 channel image), the result is not the expected: 6 smaller gray images appear together inside the picture box (note that I managed the picturebox properties to center the image ,to avoid this problem!).

In order to solve this, I tried to use cvMerge, in order to  "fool" the conversion (giving it allways a 3 channel IplImage image), but still continued to get the same result.
I used it before doing the conversion from IplImage2Bitmap :

cvMerge(img1channel, img1channel, img1channel,cvCreateImage(cvSize(hW, hH), 8, 1), img3channel);

So anyone have had the same problem? Could you help me? I´m trying to solve this for 6 hours , and I´m getting crazy....

(I want to attach the sample of the code, but currently that option is not available...)

help me please ;)

Best Reagards
Eduardo