PDA

View Full Version : RGB image from frame grabber flipped!



Matt
May 27, 2004, 22:59:30
I'm using an Imaging Source video-to-firewire converter for a project. When I grab in YUV, I can use GetActiveMemBuffer->getPtr() and use that to import the image into my own code. When I do the same thing in RGB, the image I get is flipped horizontally and vertically.

If I try to use the demo app for the same mode (RGB24, 640x480), the image appears fine, and if I startLive(true), the image shown is right-side-up.

Any ideas?

-Matt

Matt
May 27, 2004, 23:23:31
The image is only flipped vertically (along the horizontal axis).

Stefan Geissler
May 28, 2004, 08:05:09
Hello Matt,

The images in the video frames are saved as DIBs. DIBs are allways saved bottom up. If you want to
use an HTBITMAP you should copy the DIB in to a HBITMAP. The following code is not realy tested but
imported from an existing project. It shows how to create a bitmap in memory and how to copy the
image buffer into this bitmap.



// Create the bitmap
HBITMAP hCamera1Bitmap ;

// Get the bits per pixel of the current screen
HDC dc = CreateCompatibleDC( NULL );
int bpp = GetDeviceCaps(dc,BITSPIXEL);
DeleteDC(dc);

// Retrieve the bitmap info header of the image buffer to
// get the width and height of the image buffer
smart_ptr<BITMAPINFOHEADER> pInf = pBuffer->getBitmapInfoHeader();

// Allocate memory for the bitmap
DWORD Size = ((bpp>>3) * pInf->biWidth * pInf->biHeight);
BYTE *bytes = NULL;
bytes = new BYTE[Size];

// Create the bitmap
m_hCamera1Bitmap = CreateBitmap(pInf->biWidth,
pInf->biHeight,1,bpp,bytes);

/ The memory is not longer needed, so we can delete it
delete [] bytes;


Now you have created a bitmap in memory. This should be a member of your class or the
GrabberListener derive class. Copy the Imagebuffer to the Bitmap:



HDC memDC;
memDC = CreateCompatibleDC(NULL);
smart_ptr<BITMAPINFOHEADER> pInf = pBuffer->getBitmapInfoHeader();

// Select the bitmap of the memory DC to draw in.
SelectObject(memDC, m_hCamera1Bitmap);

int nLines = StretchDIBits(memDC,// Handle to the device
0, // x-coord of destination upper-left corner
0, // y-coord of destination upper-left corner
pInf->biWidth, // width of destination rectangle
pInf->biHeight, // height of destination rectangle
0, // x-coord of source upper-left corner
0,// y-coord of source upper-left corner
pInf->biWidth, // Source rectangle width
pInf->biHeight, // Source rectangle height
pBuffer->getPtr(),
0, // First scan line in array

reinterpret_cast<LPBITMAPINFO>( &*pInf ),
DIB_RGB_COLORS,// RGB or palette indices
SRCCOPY
);

DeleteDC( memDC);


Now you should have the image in the hCamera1Bitmap. This can be passed to other controls. pBuffer
is a pointer to a MemBuffer.