libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libcvd-members] Copying images from a Windows DirectShow buffer in


From: John Ryding
Subject: Re: [libcvd-members] Copying images from a Windows DirectShow buffer into a LibCVD Image object
Date: Wed, 25 Feb 2009 20:04:10 -0500

So an update on my situation,

I was able to acquire an image through from my webcam on Windows in the required RGB format of an unsigned char*.  The problem I now have is how to to get that image converted into an Image<Rgb<byte>>.

so basically my function looks something along the lines of:

getImage( Image<Rgb<byte>> &rgbImage )
{
     unsigned char* buffer = video.getFrame();

     Image<Rgb<byte>> newImage( ImageRef( XSIZE, YSIZE), (Rgb<byte>*)buffer );
     rgbImage = *newImage;
}

The C++ compiler gives me errors whenever I try to typecast my unsigned char*, im basically trying to make my code as quick as possible and I feel the grabbing of my frames is my bottleneck.  I basically want to create a reference to the new frame from my webcam to process, but am having trouble setting this up for an RGB CVD::Image object.

Thank you for your responses and help.




-John Ryding


On Wed, Feb 25, 2009 at 7:08 AM, Tom Drummond <address@hidden> wrote:
Probably BGR should exist as a colour type in libcvd - then copying from the webcam could be using memcpy - or in fact the webcam buffer could be used directly in the returned video frame (no copying).  glDrawPixels also supports GL_BGR as a native type - so GL based display should be fast (provided the hardware supports this format directly without resorting to a software fallback).

There is a bit of work to do to incorportate it however, there are colour conversion functions that need to be written to handle it.

This probably means that libcvd is not that well laid out as several files have to be touched to support this - namely

rgb.h (to include the additional definition) - or a new bgr.h
glhelpers.h (to provide a new glDrawPixels overload)
and any files involved in the rather messy colour space conversion code

Tom


On Wed, Feb 25, 2009 at 11:05 AM, Gerhard Reitmayr <address@hidden> wrote:
Hi John,

I am not sure about the details of using DirectShow, but I know that
Windows uses BGR format (instead of RGB) quite a lot. I guess that you
are simply getting a buffer in BGR format. Therefore, you need your code
below to convert it then into an RGB format and stores the result in the
image data.

LibCVD does not support BGR at the moment. It's possible to add this
(look at rgb.h) but requires also some conversion functions similar to
the one you wrote.

fill and copy do not deal with conversion between image formats but
simply copy the data as it is laid out in memory. therefore they cannot
do the necessary byte swizzeling to get from BGR to RGB.

your current code is probably the best solution without adding full
support for BGR to libCVD. in the end, if you want the image from the
webcam in RGB format, this conversion has to happen anyway, whether in
libcvd or in your code.

cheers,
 Gerhard

John Ryding wrote:
> Hello,
>
> I am currently using LibCVD for a personal project on using Windows.
>
> The problem that I am getting is that whenever I use any of the native
> methods for copying an image buffer from the Windows (using DirectShow),
> the image is output as larger than my program's window and looks as if 2
> images are placed over each other.
>
> Playing around with my code, I come to find that this problem does not
> occur when I manually copy the data from my image buffer (an unsigned
> char*) into the objects like so:
>
>
>
>
>
>
> unsigned char* pImage = m_buffer; //The image from my webcam in windows
> unsigned char *rgbDest = (unsigned char *)image.data();
>
> rgbDest += 2; //start by advancing to first Blue byte of dest
>         for(int i=0; i<CAPTURE_SIZE_X*CAPTURE_SIZE_Y; ++i) {
>             *rgbDest = *pImage;
>
>             ++pImage;
>             --rgbDest; // backup to Green
>
>             *rgbDest = *pImage;
>
>             ++pImage;
>             --rgbDest; // backup to Red
>
>             *rgbDest = *pImage;
>
>             ++pImage;
>             rgbDest += 5; // advance to Blue of next pixel
> }
>
>
>
>
> Looking at this code, it is obvious that I must first start at the Blue
> pixel of my image and copy the image from the buffer as if it was a BGR
> image.
>
> I am just wondering if this is a bug in the libCVD code as I am unable
> to use any of the libCVD copy() or fill() methods, which from looking at
> the documentation, use MUCH faster methods of copying the images from
> buffer to object.
>
> If this is not a bug, then why must I copy the image like a BGR image?
>
> lastly, is there any faster way to copy the image from my USB webcam's
> buffer into a CVD::Image object?
>
> Thank you.
>
> -John Ryding
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> libcvd-members mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/libcvd-members


--
Gerhard Reitmayr
MIL, Engineering Department, Cambridge University
http://www.eng.cam.ac.uk/~gr281/
tel: +44 1223 765150


_______________________________________________
libcvd-members mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/libcvd-members



--
Dr T Drummmond                               http://mi.eng.cam.ac.uk/~twd20
Machine Intelligence Laboratory
Department of Engineering
University of Cambridge


reply via email to

[Prev in Thread] Current Thread [Next in Thread]