Getting images from a web that's in YUV12 format

I’m recoding a lot of my eyetracker project, which I last mention in August
or so. Long story short, the image from the webcam is not coloured
properly. This is the code I am using:

    SDL_Surface *convert = SDL_CreateRGBSurfaceFrom( (void

*)webcam->frame->imageData,
webcam->frame->width,
webcam->frame->height,

webcam->frame->depth*webcam->frame->nChannels,
webcam->frame->widthStep,
0xff0000, 0x00ff00, 0x0000ff, 0 );
SDL_Surface *surface = SDL_CreateRGBSurface( 0, widget->rect.w,
widget->rect.h, 24, 0, 0, 0, 0 );
if( !convert || !surface ) printf( “SDL Error: %s\n”, SDL_GetError()
);
SDL_BlitSurface( convert, NULL, surface, NULL );

    if( widget->texture ) SDL_DestroyTexture( widget->texture );
    widget->texture = SDL_CreateTextureFromSurface( 0, surface );

    SDL_FreeSurface( surface );
    SDL_FreeSurface( convert );

Does anyone have a suggestion?

Take care,
-Alex

I would guess that the masks passed to SDL_CreateRGBSurfaceFrom are off. I
don’t know how you would find the appropriate ones for the webcam data
though, besides the good old guess and check.

Jonny DOn Tue, Nov 16, 2010 at 1:17 PM, Alex Barry <alex.barry at gmail.com> wrote:

I’m recoding a lot of my eyetracker project, which I last mention in August
or so. Long story short, the image from the webcam is not coloured
properly. This is the code I am using:

    SDL_Surface *convert = SDL_CreateRGBSurfaceFrom( (void

*)webcam->frame->imageData,
webcam->frame->width,
webcam->frame->height,

webcam->frame->depth*webcam->frame->nChannels,
webcam->frame->widthStep,
0xff0000, 0x00ff00, 0x0000ff, 0 );
SDL_Surface *surface = SDL_CreateRGBSurface( 0, widget->rect.w,
widget->rect.h, 24, 0, 0, 0, 0 );
if( !convert || !surface ) printf( “SDL Error: %s\n”,
SDL_GetError() );
SDL_BlitSurface( convert, NULL, surface, NULL );

    if( widget->texture ) SDL_DestroyTexture( widget->texture );
    widget->texture = SDL_CreateTextureFromSurface( 0, surface );

    SDL_FreeSurface( surface );
    SDL_FreeSurface( convert );

Does anyone have a suggestion?

Take care,
-Alex


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Oh, the title of your message mentions YUV12. I’m not familiar with such
conversions, but someone else or the web might be.

Jonny DOn Tue, Nov 16, 2010 at 2:31 PM, Jonathan Dearborn <@Jonathan_Dearborn>wrote:

I would guess that the masks passed to SDL_CreateRGBSurfaceFrom are off.
I don’t know how you would find the appropriate ones for the webcam data
though, besides the good old guess and check.

Jonny D

On Tue, Nov 16, 2010 at 1:17 PM, Alex Barry <alex.barry at gmail.com> wrote:

I’m recoding a lot of my eyetracker project, which I last mention in
August or so. Long story short, the image from the webcam is not coloured
properly. This is the code I am using:

    SDL_Surface *convert = SDL_CreateRGBSurfaceFrom( (void

*)webcam->frame->imageData,
webcam->frame->width,
webcam->frame->height,

webcam->frame->depth*webcam->frame->nChannels,
webcam->frame->widthStep,
0xff0000, 0x00ff00, 0x0000ff, 0 );
SDL_Surface *surface = SDL_CreateRGBSurface( 0, widget->rect.w,
widget->rect.h, 24, 0, 0, 0, 0 );
if( !convert || !surface ) printf( “SDL Error: %s\n”,
SDL_GetError() );
SDL_BlitSurface( convert, NULL, surface, NULL );

    if( widget->texture ) SDL_DestroyTexture( widget->texture );
    widget->texture = SDL_CreateTextureFromSurface( 0, surface );

    SDL_FreeSurface( surface );
    SDL_FreeSurface( convert );

Does anyone have a suggestion?

Take care,
-Alex


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

No problem. The thing I’m puzzled with is that SDL 1.2 had Overlay support,
which gave me the ability to set the pixels, and I could use this webcam no
problem. Now with SDL 1.3, it looks like I should directly be using
SDL_Texture, but I don’t have pixel access, and it doesn’t seem to make
sense to use SDL_Surface. I think I can probably do the conversion using
OpenCV, but I’m doing realtime face/eye tracking, so the less steps I have
to do each frame, the better.
Also, with my posted code, it seems like I probably shouldn’t be discarding
the texture every new frame…there should be a way for me to update the
texture without having to make a new one each time. I think the query
texture gives a double pointer to pixel data, so maybe I can try that, but I
don’t want to cause a nasty memory leak.

Suggestions?On Tue, Nov 16, 2010 at 2:32 PM, Jonathan Dearborn wrote:

Oh, the title of your message mentions YUV12. I’m not familiar with such
conversions, but someone else or the web might be.

Jonny D

On Tue, Nov 16, 2010 at 2:31 PM, Jonathan Dearborn wrote:

I would guess that the masks passed to SDL_CreateRGBSurfaceFrom are off.
I don’t know how you would find the appropriate ones for the webcam data
though, besides the good old guess and check.

Jonny D

On Tue, Nov 16, 2010 at 1:17 PM, Alex Barry <@Alex_Barry> wrote:

I’m recoding a lot of my eyetracker project, which I last mention in
August or so. Long story short, the image from the webcam is not coloured
properly. This is the code I am using:

    SDL_Surface *convert = SDL_CreateRGBSurfaceFrom( (void

*)webcam->frame->imageData,
webcam->frame->width,
webcam->frame->height,

webcam->frame->depth*webcam->frame->nChannels,
webcam->frame->widthStep,
0xff0000, 0x00ff00, 0x0000ff, 0 );
SDL_Surface *surface = SDL_CreateRGBSurface( 0, widget->rect.w,
widget->rect.h, 24, 0, 0, 0, 0 );
if( !convert || !surface ) printf( “SDL Error: %s\n”,
SDL_GetError() );
SDL_BlitSurface( convert, NULL, surface, NULL );

    if( widget->texture ) SDL_DestroyTexture( widget->texture );
    widget->texture = SDL_CreateTextureFromSurface( 0, surface );

    SDL_FreeSurface( surface );
    SDL_FreeSurface( convert );

Does anyone have a suggestion?

Take care,
-Alex


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org