CvMat to IplImage

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

CvMat to IplImage

touqer
Can anybody please suggest me a method to convert CvMat to IplImage. I have played around with cvGetImage and cvConvertImage and unfortunately they both were not able to give me the required results. Each of these functions give me an Image which has a bluish shade in it. Just to enforce I am not asking for cv::Mat to IplImage or cvMat instead i am asking for 'CvMat to IplImage'

Will appreciate any help.

Regards,
Touqeer

Reply | Threaded
Open this post in threaded view
|

Re: CvMat to IplImage

Francisco Ares
On Tue, Dec 27, 2011 at 9:45 AM, touqer <[hidden email]> wrote:

> **
>
>
> Can anybody please suggest me a method to convert CvMat to IplImage. I
> have played around with cvGetImage and cvConvertImage and unfortunately
> they both were not able to give me the required results. Each of these
> functions give me an Image which has a bluish shade in it. Just to enforce
> I am not asking for cv::Mat to IplImage or cvMat instead i am asking for
> 'CvMat to IplImage'
>
> Will appreciate any help.
>
> Regards,
> Touqeer
>
>  
>

It is straighforward, look here:

http://opencv.itseez.com/modules/core/doc/basic_structures.html#mat

and search for the text IplImage

Francisco
Reply | Threaded
Open this post in threaded view
|

Re: CvMat to IplImage

Shervin Emami
In reply to this post by touqer
To convert from a CvMat to IplImage without copying data around, you can
get access to the pixel array of a CvMat using something like "a->data.fl"
(or whatever datatype your matrix is). Then use cvCreateImageHeader() to
create your IplImage structure and then cvSetData() to specify where the
pixel array is for that image. Just remember that CvMat is usually an array
of 32-bit floats, so if you create an IplImage image accessing the exact
same array of pixels then it also needs to be a 32-bit float image. Then
you can use cvConvert() to convert it to a regular 8-bit uchar image (and
perhaps scale it by 255) if you want to save or display it.

Cheers,
Shervin Emami.
Mobile Computer Vision Engineer, NVIDIA.
http://www.shervinemami.info/openCV.html


On Tue, Dec 27, 2011 at 5:45 AM, touqer <[hidden email]> wrote:

> **
>
>
> Can anybody please suggest me a method to convert CvMat to IplImage. I
> have played around with cvGetImage and cvConvertImage and unfortunately
> they both were not able to give me the required results. Each of these
> functions give me an Image which has a bluish shade in it. Just to enforce
> I am not asking for cv::Mat to IplImage or cvMat instead i am asking for
> 'CvMat to IplImage'
>
> Will appreciate any help.
>
> Regards,
> Touqeer
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: CvMat to IplImage

saleh
In reply to this post by touqer
AoA touqeer,
u cn use it this way:

CvMat yourMatrix;

yourMatrix = ******** // assume you initliaze your cvmat variable //here with some data

IplImage temp = yourMatrix;
IplImage* ptTemp = &temp;

there u go..

regards,
Saleh...

--- In [hidden email], "touqer" <sh.touqeerahmad@...> wrote:
>
> Can anybody please suggest me a method to convert CvMat to IplImage. I have played around with cvGetImage and cvConvertImage and unfortunately they both were not able to give me the required results. Each of these functions give me an Image which has a bluish shade in it. Just to enforce I am not asking for cv::Mat to IplImage or cvMat instead i am asking for 'CvMat to IplImage'
>
> Will appreciate any help.
>
> Regards,
> Touqeer
>


Reply | Threaded
Open this post in threaded view
|

Cannot convert IplImage from 8 bit sign to 8 bit unsign

Wahyudin Permana
Dear all,

I have problem, when I read an image, the img0 type is IPL-DEPTH_8S but, I want to convert it to IPL_DEPTH_8U by cvConvertscale as shown below:

IplImage* img0 = cvLoadImage("test.jpg",CV_LOAD_IMAGE_GRAYSCALE); //force image to be in gray scale
if (!img0) {
printf("Error: Could not open the image file! \n");
exit(1);
}
IplImage* img = cvCreateImage(cvSize(img0->width , img0->height), IPL_DEPTH_8U, img0->nChannels);
    cvConvertScale(img0,img,1,0);

but, when I checked the pixel data, still the value is - something (which is not a 8U), anybody can suggest something for this problem?

many thanks
 
============================================================
Best regards,
Wahyudin Permana Syam
============================================================


________________________________
Reply | Threaded
Open this post in threaded view
|

Cannot convert IplImage from 8 bit sign to 8 bit unsign

Wahyudin Permana
In reply to this post by saleh
Dear all,

I have problem, when I read an image, the img0 type is IPL-DEPTH_8S but, I want to convert it to IPL_DEPTH_8U by cvConvertscale as shown below:

IplImage* img0 = cvLoadImage("test.jpg",CV_LOAD_IMAGE_GRAYSCALE); //force image to be in gray scale
if (!img0) {
printf("Error: Could not open the image file! \n");
exit(1);
}
IplImage* img = cvCreateImage(cvSize(img0->width , img0->height), IPL_DEPTH_8U, img0->nChannels);
    cvConvertScale(img0,img,1,0);

but, when I checked the pixel data, still the value is - something (which is not a 8U), anybody can suggest something for this problem?

many thanks
 
============================================================
Best regards,
Wahyudin Permana Syam
============================================================


________________________________