 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sun Oct 19, 2003 2:51 pm Post subject: VideoCapture: Problem storing bitmap frame from uyvy buffer |
|
|
Hi all,
I'm trying to capture a frame and store it to a TBitmap, so that I can
process it later.
(needs to be Tbitmap). The main problem lies inside the callback funciton
"myYieldCallbackProc".
Stealing from a previous post, I've read that the data is in uyvy format.
I managed to steal another bit of code ( written by Andrew Tridgell 2000)
but to no avail.
All I get is a black background with red little dots scattered everywhere,
and nothing
like the captured picture.
Anyone know how to solve this beast??
------------------------BITS OF
CODE---------------------------------------------------------------
LRESULT FAR PASCAL myYieldCallbackProc(HWND hWnd,LPVIDEOHDR lpVHdr)
{
LPBITMAPINFO lpbi;
LPBITMAPINFOHEADER lpdata;
int sz;
// char lpStatusText[50];
CAPSTATUS cs;
sz = (int)capGetVideoFormatSize(hWnd);
lpbi = (LPBITMAPINFO)LocalAlloc(LPTR, sz);
lpdata = (LPBITMAPINFOHEADER)lpVHdr->lpData;
if (lpbi)
{
capGetVideoFormat(hWnd, lpbi, sz);
frmmain->Caption = DateTimeToStr(Now());
char * MyImage = lpVHdr->lpData; // is buffer contained video in format
avi uyvy
//***************************************
Graphics::TBitmap * SrcBitmap;
SrcBitmap = new Graphics::TBitmap;
SrcBitmap->PixelFormat = pf24bit;
SrcBitmap->Width = lpbi->bmiHeader.biWidth;
SrcBitmap->Height = lpbi->bmiHeader.biHeight;
char * thisptr = MyImage;
yuv_convert(MyImage,thisptr,320,200);
for (int y = 0;y< 200;y++)
{
for (int x = 0;x< 320;x++)
{
SrcBitmap->Canvas->Pixels[x][y] = thisptr[ (y*320) + x];
}
}
frmmain->Image2->Canvas->Draw(0,0,SrcBitmap);
SrcBitmap->SaveToFile("c:\temp.bmp");
SrcBitmap->Free();
//****************************************
}
LocalFree(lpbi);
return (LRESULT) TRUE;
}
void __fastcall Tfrmmain::Button11Click(TObject *Sender)
{
hwnd = capCreateCaptureWindow( NULL, WS_CHILD | WS_VISIBLE, 0, 0,
640, 400, this->Handle,100 );
SendMessage(hwnd,WM_CAP_DRIVER_CONNECT,0,0);
capOverlay(hwnd,TRUE);
capSetCallbackOnVideoStream( hwnd, myYieldCallbackProc );
capCaptureSequenceNoFile(hwnd);
}
void yuvtorgb(int Y, int U, int V, char* rgb)
{ int r, g, b;
static short L1[256], L2[256], L3[256], L4[256], L5[256];
static int initialised;
if (!initialised)
{
int i;
initialised=1;
for (i=0;i<256;i++) {
L1[i] = 1.164*(i-16);
L2[i] = 1.596*(i-128);
L3[i] = -0.813*(i-128);
L4[i] = 2.018*(i-128);
L5[i] = -0.391*(i-128);
}
}
#if 0
r = 1.164*(Y-16) + 1.596*(V-128);
g = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128);
b = 1.164*(Y-16) + 2.018*(U-128);
#endif r = L1[Y] + L2[V]; g = L1[Y] + L3[U] + L5[V]; b = L1[Y] + L4[U];
if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; if (r > 255) r = 255;
if (g > 255) g = 255; if (b > 255) b = 255; rgb[0] = r;
rgb[1] = g;
rgb[2] = b;
}
void yuv_convert(char* buf, char * rgb, int xsize, int ysize)
{ int i;
for (i=0;i
int Y1, Y2, U, V;
Y1 = buf[2*i+0];
Y2 = buf[2*i+2];
U = buf[2*i+1];
V = buf[2*i+3];
yuvtorgb(Y1, U, V, &rgb[3*i]);
yuvtorgb(Y2, U, V, &rgb[3*(i+1)]);
}
}
|
|
| Back to top |
|
 |
Edward Guest
|
Posted: Tue Dec 02, 2003 4:46 am Post subject: Re: VideoCapture: Problem storing bitmap frame from uyvy buf |
|
|
Maqn i have thew same problem but i use this code
CAPSTATUS CapStatus;
char str[12];
TimerRefresh->Enabled = false;
if(!FileExists("SAIR.DAT"))
{
if(ctImg>=20)
{
ctImg=0;
}
ctImg++;
sprintf(str,"web%03d.bmp",ctImg);
try
{
capGetStatus(hWndC, &CapStatus, sizeof (CAPSTATUS));
capFileSaveDIB(hWndC, str);
Graphics::TBitmap *bmpOld = new Graphics::TBitmap();
Graphics::TBitmap *bmpNew = new Graphics::TBitmap();
bmpOld->LoadFromFile(str);
bmpNew->Width = tamXVL;
bmpNew->Height = tamYVL;
bmpNew->Canvas->StretchDraw(bmpNew->Canvas->ClipRect, bmpOld);
bmpNew->Assign(bmpNew);
bmpNew->SaveToFile(str);
delete bmpOld;
delete bmpNew;
}
catch (Exception &Ex)
{
MessageDlg("Exception type " + Ex.ClassName() + " returned error
message: " + Ex.Message + "r" + " in form " + this->ClassName(), mtError,
TMsgDlgButtons() << mbOK, 0);
abort();
}
}
else
{
capDriverDisconnect(hWndC);
FreeLibrary(AVICapDllHandle);
Close();
}
TimerRefresh->Enabled = true;
<aa> escreveu na mensagem news:3f92a6b0 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi all,
I'm trying to capture a frame and store it to a TBitmap, so that I can
process it later.
(needs to be Tbitmap). The main problem lies inside the callback funciton
"myYieldCallbackProc".
Stealing from a previous post, I've read that the data is in uyvy format.
I managed to steal another bit of code ( written by Andrew Tridgell 2000)
but to no avail.
All I get is a black background with red little dots scattered everywhere,
and nothing
like the captured picture.
Anyone know how to solve this beast??
------------------------BITS OF
CODE---------------------------------------------------------------
LRESULT FAR PASCAL myYieldCallbackProc(HWND hWnd,LPVIDEOHDR lpVHdr)
{
LPBITMAPINFO lpbi;
LPBITMAPINFOHEADER lpdata;
int sz;
// char lpStatusText[50];
CAPSTATUS cs;
sz = (int)capGetVideoFormatSize(hWnd);
lpbi = (LPBITMAPINFO)LocalAlloc(LPTR, sz);
lpdata = (LPBITMAPINFOHEADER)lpVHdr->lpData;
if (lpbi)
{
capGetVideoFormat(hWnd, lpbi, sz);
frmmain->Caption = DateTimeToStr(Now());
char * MyImage = lpVHdr->lpData; // is buffer contained video in
format
avi uyvy
//***************************************
Graphics::TBitmap * SrcBitmap;
SrcBitmap = new Graphics::TBitmap;
SrcBitmap->PixelFormat = pf24bit;
SrcBitmap->Width = lpbi->bmiHeader.biWidth;
SrcBitmap->Height = lpbi->bmiHeader.biHeight;
char * thisptr = MyImage;
yuv_convert(MyImage,thisptr,320,200);
for (int y = 0;y< 200;y++)
{
for (int x = 0;x< 320;x++)
{
SrcBitmap->Canvas->Pixels[x][y] = thisptr[ (y*320) + x];
}
}
frmmain->Image2->Canvas->Draw(0,0,SrcBitmap);
SrcBitmap->SaveToFile("c:\temp.bmp");
SrcBitmap->Free();
//****************************************
}
LocalFree(lpbi);
return (LRESULT) TRUE;
}
void __fastcall Tfrmmain::Button11Click(TObject *Sender)
{
hwnd = capCreateCaptureWindow( NULL, WS_CHILD | WS_VISIBLE, 0, 0,
640, 400, this->Handle,100 );
SendMessage(hwnd,WM_CAP_DRIVER_CONNECT,0,0);
capOverlay(hwnd,TRUE);
capSetCallbackOnVideoStream( hwnd, myYieldCallbackProc );
capCaptureSequenceNoFile(hwnd);
}
void yuvtorgb(int Y, int U, int V, char* rgb)
{ int r, g, b;
static short L1[256], L2[256], L3[256], L4[256], L5[256];
static int initialised;
if (!initialised)
{
int i;
initialised=1;
for (i=0;i<256;i++) {
L1[i] = 1.164*(i-16);
L2[i] = 1.596*(i-128);
L3[i] = -0.813*(i-128);
L4[i] = 2.018*(i-128);
L5[i] = -0.391*(i-128);
}
}
#if 0
r = 1.164*(Y-16) + 1.596*(V-128);
g = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128);
b = 1.164*(Y-16) + 2.018*(U-128);
#endif r = L1[Y] + L2[V]; g = L1[Y] + L3[U] + L5[V]; b = L1[Y] + L4[U];
if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; if (r > 255) r =
255;
if (g > 255) g = 255; if (b > 255) b = 255; rgb[0] = r;
rgb[1] = g;
rgb[2] = b;
}
void yuv_convert(char* buf, char * rgb, int xsize, int ysize)
{ int i;
for (i=0;i
int Y1, Y2, U, V;
Y1 = buf[2*i+0];
Y2 = buf[2*i+2];
U = buf[2*i+1];
V = buf[2*i+3];
yuvtorgb(Y1, U, V, &rgb[3*i]);
yuvtorgb(Y2, U, V, &rgb[3*(i+1)]);
}
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|