How to fill data is Ipl image structure

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

How to fill data is Ipl image structure

Naveen-10
Hello,

 

I have to push some image data in IPl image structure and then display it.

 

I have created

 IplImage* dest=cvCreateImage(size,8,1);`

And I am filling data like this

*dest->imageData++=tval;

Were tval is unsigned int.

 

But when I am trying to display the image

cvNamedWindow("destination",1);

cvShowImage("destination",dest);

 

it crashes.

 

When I try to see data in destination it shows garbage.

 

 

NK

 



[Non-text portions of this message have been removed]

Reply | Threaded
Open this post in threaded view
|

Re: How to fill data is Ipl image structure

ahmed Sokar
What about using opencv functions


IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
CvScalar s;
s=cvGet2D(img,i,j); // get the (i,j) pixel value
printf("intensity=%f\n",s.val[0]);
s.val[0]=111;
cvSet2D(img,i,j,s); // set the (i,j) pixel value

Check this link
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00053000000000000000






________________________________
From: Naveen <[hidden email]>
To: [hidden email]
Sent: Thu, February 25, 2010 2:44:07 PM
Subject: [OpenCV] How to fill data is Ipl image structure

 
Hello,

I have to push some image data in IPl image structure and then display it.

I have created

IplImage* dest=cvCreateImage( size,8,1) ;`

And I am filling data like this

*dest->imageData+ +=tval;

Were tval is unsigned int.

But when I am trying to display the image

cvNamedWindow( "destination" ,1);

cvShowImage( "destination" ,dest);

it crashes.

When I try to see data in destination it shows garbage.

NK

[Non-text portions of this message have been removed]


 


     

[Non-text portions of this message have been removed]

Reply | Threaded
Open this post in threaded view
|

Re: How to fill data is Ipl image structure

Robin Hewitt
In reply to this post by Naveen-10
operator precedence? I'm not sure, but should this be
*(dest->imageData+ +)=tval;


- Robin



________________________________
From: Naveen <[hidden email]>
To: [hidden email]
Sent: Thu, February 25, 2010 4:44:07 AM
Subject: [OpenCV] How to fill data is Ipl image structure

 
Hello,

I have to push some image data in IPl image structure and then display it.

I have created

IplImage* dest=cvCreateImage( size,8,1) ;`

And I am filling data like this

*dest->imageData+ +=tval;

Were tval is unsigned int.

But when I am trying to display the image

cvNamedWindow( "destination" ,1);

cvShowImage( "destination" ,dest);

it crashes.

When I try to see data in destination it shows garbage.

NK

[Non-text portions of this message have been removed]


 


     

[Non-text portions of this message have been removed]

Reply | Threaded
Open this post in threaded view
|

Re: How to fill data is Ipl image structure

Jean-Pierre Landry
Not even sure that it's still a good idea to go incrementing directly
the IplImage's 'imageData' pointer...  I would have done the
incrementing on a copy of it so it's still pointing at the image data
beginning after the loop...

Robin Hewitt wrote:

> operator precedence? I'm not sure, but should this be
> *(dest->imageData+ +)=tval;
>
>
> - Robin
>
>
>
> ________________________________
> From: Naveen <[hidden email]>
> To: [hidden email]
> Sent: Thu, February 25, 2010 4:44:07 AM
> Subject: [OpenCV] How to fill data is Ipl image structure
>
>  
> Hello,
>
> I have to push some image data in IPl image structure and then display it.
>
> I have created
>
> IplImage* dest=cvCreateImage( size,8,1) ;`
>
> And I am filling data like this
>
> *dest->imageData+ +=tval;
>
> Were tval is unsigned int.
>
> But when I am trying to display the image
>
> cvNamedWindow( "destination" ,1);
>
> cvShowImage( "destination" ,dest);
>
> it crashes.
>
> When I try to see data in destination it shows garbage.
>
> NK
>
> [Non-text portions of this message have been removed]
>
>
>  
>
>
>      
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> Change settings: http://www.yahoogroups.com/mygroups, select
>    Get Emails (get all posts)
>    Daily Digest (one summary email per day)
>    Read on the web (read posts on the web only)Or Unsubscribe by mailing [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to fill data is Ipl image structure

Frank Lamosa
A couple of points to look at.

First, the image data is 8 bit (char/unsigned char)  since that is the
data type you specified in cvCreateImage but you are attempting to write
an unsigned int value.

Second, you are incrementing the pointer, which means that you will end
up with the image data pointer pointing to the end of the image, so when
it tries to read the image, it will go beyond the end of the image data
array (since the pointer is assumed to be the beginning of the image
data - and not the end, as it is).

Therefore, when cvShowImage tries to access the image, it will try to
read invalid data.



Jean-Pierre Landry wrote:

> Not even sure that it's still a good idea to go incrementing directly
> the IplImage's 'imageData' pointer...  I would have done the
> incrementing on a copy of it so it's still pointing at the image data
> beginning after the loop...
>
> Robin Hewitt wrote:
>  
>> operator precedence? I'm not sure, but should this be
>> *(dest->imageData+ +)=tval;
>>
>>
>> - Robin
>>
>>
>>
>> ________________________________
>> From: Naveen <[hidden email]>
>> To: [hidden email]
>> Sent: Thu, February 25, 2010 4:44:07 AM
>> Subject: [OpenCV] How to fill data is Ipl image structure
>>
>>  
>> Hello,
>>
>> I have to push some image data in IPl image structure and then display it.
>>
>> I have created
>>
>> IplImage* dest=cvCreateImage( size,8,1) ;`
>>
>> And I am filling data like this
>>
>> *dest->imageData+ +=tval;
>>
>> Were tval is unsigned int.
>>
>> But when I am trying to display the image
>>
>> cvNamedWindow( "destination" ,1);
>>
>> cvShowImage( "destination" ,dest);
>>
>> it crashes.
>>
>> When I try to see data in destination it shows garbage.
>>
>> NK
>>
>> [Non-text portions of this message have been removed]
>>
>>
>>  
>>
>>
>>      
>>
>> [Non-text portions of this message have been removed]
>>
>>
>>
>> ------------------------------------
>>
>> Change settings: http://www.yahoogroups.com/mygroups, select
>>    Get Emails (get all posts)
>>    Daily Digest (one summary email per day)
>>    Read on the web (read posts on the web only)Or Unsubscribe by mailing [hidden email]
>>    
>
>
>
> ------------------------------------
>
> Change settings: http://www.yahoogroups.com/mygroups, select
>    Get Emails (get all posts)
>    Daily Digest (one summary email per day)
>    Read on the web (read posts on the web only)Or Unsubscribe by mailing [hidden email]
> Yahoo! Groups Links
>
>
>
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: How to fill data is Ipl image structure

Robin Hewitt
In reply to this post by Jean-Pierre Landry
Yes. you're right. I should have caught that as well.

- Robin




________________________________
From: Jean-Pierre Landry <[hidden email]>
To: [hidden email]
Sent: Thu, February 25, 2010 12:11:04 PM
Subject: [OpenCV] Re: How to fill data is Ipl image structure

 
Not even sure that it's still a good idea to go incrementing directly
the IplImage's 'imageData' pointer...  I would have done the
incrementing on a copy of it so it's still pointing at the image data
beginning after the loop...

Robin Hewitt wrote:

> operator precedence? I'm not sure, but should this be
> *(dest->imageData+ +)=tval;
>
>
> - Robin
>
>
>
> ____________ _________ _________ __
> From: Naveen <naveen.koul@ lge.com>
> To: OpenCV@yahoogroups. com
> Sent: Thu, February 25, 2010 4:44:07 AM
> Subject: [OpenCV] How to fill data is Ipl image structure
>
>
> Hello,
>
> I have to push some image data in IPl image structure and then display it.
>
> I have created
>
> IplImage* dest=cvCreateImage( size,8,1) ;`
>
> And I am filling data like this
>
> *dest->imageData+ +=tval;
>
> Were tval is unsigned int.
>
> But when I am trying to display the image
>
> cvNamedWindow( "destination" ,1);
>
> cvShowImage( "destination" ,dest);
>
> it crashes.
>
> When I try to see data in destination it shows garbage.
>
> NK
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------ --------- --------- ------
>
> Change settings: http://www.yahoogroups.com/mygroups, select
>    Get Emails (get all posts)
>    Daily Digest (one summary email per day)
>    Read on the web (read posts on the web only)Or Unsubscribe by mailing OpenCV-unsubscribe@ yahoogroups. com


 


     

[Non-text portions of this message have been removed]

Reply | Threaded
Open this post in threaded view
|

Re: How to fill data is Ipl image structure

Naveen-10
In reply to this post by Frank Lamosa
Hello,

 

 You are right tval is int but I have typecasted it for unsigned char.

What ever you have written is correct. The pointer gets incremented and
reaches at the last . may be that is why it is crashing.

What is  best alternative to fix this. Shld I create an copy then increment
that, or allocate different memory. But if I allocate different memory how I
view the buffer by cv ShowImage.

 

Thanks & Regards,
NK





  _____  

size=2 width="100%" align=center tabindex=-1>

From: [hidden email] [mailto:[hidden email]] On Behalf Of
Frank Lamosa
Sent: Friday, February 26, 2010 3:04 AM
To: Jean-Pierre Landry
Cc: [hidden email]
Subject: Re: [OpenCV] Re: How to fill data is Ipl image structure

 

 

A couple of points to look at.

First, the image data is 8 bit (char/unsigned char) since that is the
data type you specified in cvCreateImage but you are attempting to write
an unsigned int value.

Second, you are incrementing the pointer, which means that you will end
up with the image data pointer pointing to the end of the image, so when
it tries to read the image, it will go beyond the end of the image data
array (since the pointer is assumed to be the beginning of the image
data - and not the end, as it is).

Therefore, when cvShowImage tries to access the image, it will try to
read invalid data.

Jean-Pierre Landry wrote:

> Not even sure that it's still a good idea to go incrementing directly
> the IplImage's 'imageData' pointer... I would have done the
> incrementing on a copy of it so it's still pointing at the image data
> beginning after the loop...
>
> Robin Hewitt wrote:
>
>> operator precedence? I'm not sure, but should this be
>> *(dest->imageData+ +)=tval;
>>
>>
>> - Robin
>>
>>
>>
>> ________________________________
>> From: Naveen <naveen.koul@ <mailto:naveen.koul%40lge.com> lge.com>
>> To: OpenCV@yahoogroups. <mailto:OpenCV%40yahoogroups.com> com
>> Sent: Thu, February 25, 2010 4:44:07 AM
>> Subject: [OpenCV] How to fill data is Ipl image structure
>>
>>
>> Hello,
>>
>> I have to push some image data in IPl image structure and then display
it.

>>
>> I have created
>>
>> IplImage* dest=cvCreateImage( size,8,1) ;`
>>
>> And I am filling data like this
>>
>> *dest->imageData+ +=tval;
>>
>> Were tval is unsigned int.
>>
>> But when I am trying to display the image
>>
>> cvNamedWindow( "destination" ,1);
>>
>> cvShowImage( "destination" ,dest);
>>
>> it crashes.
>>
>> When I try to see data in destination it shows garbage.
>>
>> NK
>>
>> [Non-text portions of this message have been removed]
>>
>>
>>
>>
>>
>>
>>
>> [Non-text portions of this message have been removed]
>>
>>
>>
>> ------------------------------------
>>
>> Change settings: http://www.yahoogro
<http://www.yahoogroups.com/mygroups,> ups.com/mygroups, select
>> Get Emails (get all posts)
>> Daily Digest (one summary email per day)
>> Read on the web (read posts on the web only)Or Unsubscribe by mailing
OpenCV-unsubscribe@ <mailto:OpenCV-unsubscribe%40yahoogroups.com>
yahoogroups.com
>>
>
>
>
> ------------------------------------
>
> Change settings: http://www.yahoogro
<http://www.yahoogroups.com/mygroups,> ups.com/mygroups, select
> Get Emails (get all posts)
> Daily Digest (one summary email per day)
> Read on the web (read posts on the web only)Or Unsubscribe by mailing
OpenCV-unsubscribe@ <mailto:OpenCV-unsubscribe%40yahoogroups.com>
yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>





[Non-text portions of this message have been removed]

Reply | Threaded
Open this post in threaded view
|

Re: How to fill data is Ipl image structure

Frank Lamosa
You could try

dest->imageData[array_index] = (char)tval

This way you will not have your image data pointer move from the
beginning of the allocated image data array.

If you have your data in an array already, you could also use the memcpy
function:

memcpy ( dest->imageData, (const char *)source_array, nbr_bytes_to_copy)


Naveen wrote:

>
> Hello,
>
> You are right tval is int but I have typecasted it for unsigned char.
>
> What ever you have written is correct. The pointer gets incremented
> and reaches at the last . may be that is why it is crashing.
>
> What is best alternative to fix this. Shld I create an copy then
> increment that, or allocate different memory. But if I allocate
> different memory how I view the buffer by cv ShowImage.
>
> /Thanks & Regards,
> NK/
>
>
>
> ------------------------------------------------------------------------
> size=2 width="100%" align=center tabindex=-1>
>
> *From:* [hidden email] [mailto:[hidden email]] *On
> Behalf Of *Frank Lamosa
> *Sent:* Friday, February 26, 2010 3:04 AM
> *To:* Jean-Pierre Landry
> *Cc:* [hidden email]
> *Subject:* Re: [OpenCV] Re: How to fill data is Ipl image structure
>
> A couple of points to look at.
>
> First, the image data is 8 bit (char/unsigned char) since that is the
> data type you specified in cvCreateImage but you are attempting to write
> an unsigned int value.
>
> Second, you are incrementing the pointer, which means that you will end
> up with the image data pointer pointing to the end of the image, so when
> it tries to read the image, it will go beyond the end of the image data
> array (since the pointer is assumed to be the beginning of the image
> data - and not the end, as it is).
>
> Therefore, when cvShowImage tries to access the image, it will try to
> read invalid data.
>
> Jean-Pierre Landry wrote:
> > Not even sure that it's still a good idea to go incrementing directly
> > the IplImage's 'imageData' pointer... I would have done the
> > incrementing on a copy of it so it's still pointing at the image data
> > beginning after the loop...
> >
> > Robin Hewitt wrote:
> >
> >> operator precedence? I'm not sure, but should this be
> >> *(dest->imageData+ +)=tval;
> >>
> >>
> >> - Robin
> >>
> >>
> >>
> >> ________________________________
> >> From: Naveen <[hidden email] <mailto:naveen.koul%40lge.com>>
> >> To: [hidden email] <mailto:OpenCV%40yahoogroups.com>
> >> Sent: Thu, February 25, 2010 4:44:07 AM
> >> Subject: [OpenCV] How to fill data is Ipl image structure
> >>
> >>
> >> Hello,
> >>
> >> I have to push some image data in IPl image structure and then
> display it.
> >>
> >> I have created
> >>
> >> IplImage* dest=cvCreateImage( size,8,1) ;`
> >>
> >> And I am filling data like this
> >>
> >> *dest->imageData+ +=tval;
> >>
> >> Were tval is unsigned int.
> >>
> >> But when I am trying to display the image
> >>
> >> cvNamedWindow( "destination" ,1);
> >>
> >> cvShowImage( "destination" ,dest);
> >>
> >> it crashes.
> >>
> >> When I try to see data in destination it shows garbage.
> >>
> >> NK
> >>
> >> [Non-text portions of this message have been removed]
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> [Non-text portions of this message have been removed]
> >>
> >>
> >>
> >> ------------------------------------
> >>
> >> Change settings: http://www.yahoogroups.com/mygroups,
> <http://www.yahoogroups.com/mygroups,> select
> >> Get Emails (get all posts)
> >> Daily Digest (one summary email per day)
> >> Read on the web (read posts on the web only)Or Unsubscribe by
> mailing [hidden email]
> <mailto:OpenCV-unsubscribe%40yahoogroups.com>
> >>
> >
> >
> >
> > ------------------------------------
> >
> > Change settings: http://www.yahoogroups.com/mygroups,
> <http://www.yahoogroups.com/mygroups,> select
> > Get Emails (get all posts)
> > Daily Digest (one summary email per day)
> > Read on the web (read posts on the web only)Or Unsubscribe by mailing
> [hidden email]
> <mailto:OpenCV-unsubscribe%40yahoogroups.com>
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
>
>
>



------------------------------------

Change settings: http://www.yahoogroups.com/mygroups, select
   Get Emails (get all posts)
   Daily Digest (one summary email per day)
   Read on the web (read posts on the web only)Or Unsubscribe by mailing [hidden email]
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/OpenCV/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/OpenCV/join
    (Yahoo! ID required)

<*> To change settings via email:
    [hidden email]
    [hidden email]

<*> To unsubscribe from this group, send an email to:
    [hidden email]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/