Article View: borland.public.cppbuilder.multimedia
Article #17Multiple Video Display USB
From: Andrew
Date: Sun, 26 Feb 2006 08:47
Date: Sun, 26 Feb 2006 08:47
130 lines
5345 bytes
5345 bytes
Hi, I am using BCB5, Win XP
Using the Following code (posted by Gambit) a long time ago,
displays video on a panel from a USB camera.
Is there a way to display from a second camera,
possibly on a second panel?
I'm sure it has to do with Indexing, but can't make work yet.
Thanks in Advance.
Following is post from Gambit for Video.
#include <vcl.h>
#pragma hdrstop
#include "Test_Video_Unit.h"
#include <vfw.h>
HWND CaptureWindow = NULL;
CAPDRIVERCAPS DriverCaps;
CAPTUREPARMS CapParams;
LRESULT PASCAL FrameCallback(HWND hWnd, LPVIDEOHDR lpVHdr);
LRESULT PASCAL ErrorCallback(HWND hWnd, int nErrID, LPSTR
lpErrorText);
LRESULT PASCAL StatusCallback(HWND hWnd, int nID, LPSTR
lpStatusText);
//-------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
char szDeviceName[80];
char szDeviceVersion[80];
for(int wIndex = 0; wIndex < 10; wIndex++)
{
if(capGetDriverDescription(wIndex, szDeviceName,
sizeof(szDeviceName), szDeviceVersion, sizeof(szDeviceVersion)))
{
// Append name to list of installed capture drivers
// and then let the user select a driver to use.
ComboBox1->Items->Add(szDeviceName);
}
}
CapParams.dwRequestMicroSecPerFrame = 4444;
CapParams.fYield = TRUE;
CapParams.fCaptureAudio = FALSE;
}
//--------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(CaptureWindow)
{
capCaptureStop(CaptureWindow);
capDriverDisconnect(CaptureWindow);
}
}
//--------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
int wID;
CaptureWindow = capCreateCaptureWindow("MyWindow", WS_CHILD |
WS_VISIBLE, 0, 0, 160, 120, (HWND)Panel1->Handle, 0);
if(CaptureWindow)
{
if(capDriverConnect(CaptureWindow, 0))
{
capDriverGetCaps(CaptureWindow, &DriverCaps,
sizeof(CAPDRIVERCAPS));
capPreviewScale(CaptureWindow, FALSE);
capCaptureSetSetup(CaptureWindow, &CapParams,
sizeof(CAPTUREPARMS));
capSetCallbackOnFrame(CaptureWindow, FrameCallback);
capSetCallbackOnError(CaptureWindow, ErrorCallback);
capSetCallbackOnStatus(CaptureWindow, StatusCallback);
if(DriverCaps.fHasOverlay)
capOverlay(CaptureWindow, TRUE);
else
{
capPreviewRate(CaptureWindow, 66);
capPreview(CaptureWindow, TRUE);
}
}
else
ShowMessage("Driver not connected");
}
else
ShowMessage("Could not create capture window");
}
//--------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(CaptureWindow)
{
if(DriverCaps.fHasOverlay)
capOverlay(CaptureWindow, FALSE);
else
capPreview(CaptureWindow, FALSE);
capDriverDisconnect(CaptureWindow);
DestroyWindow(CaptureWindow);
CaptureWindow = NULL;
}
}
//--------------------------------------------------------------LRESULT PASCAL FrameCallback(HWND hWnd, LPVIDEOHDR lpVHdr)
{
// do something
return (LRESULT)TRUE;
}
// -------------------------------------------------------------
LRESULT PASCAL ErrorCallback(HWND hWnd, int nErrID, LPSTR lpErrorText)
{
if (nErrID == 0) // Starting a new major function.
return TRUE; // Clear out old errors.
char caption[256];
// Show the error identifier and text.
wsprintf(caption, "Error# %d", nErrID);
MessageBox(hWnd, lpErrorText, caption, MB_OK | MB_ICONEXCLAMATION);
return (LRESULT)TRUE;
}
// -------------------------------------------------------------
LRESULT PASCAL StatusCallback(HWND hWnd, int nID, LPSTR lpStatusText)
{
char caption[256];
if (nID == 0)
{
// Clear old status messages.
SetWindowText((HWND)Form1->Handle, "My Webcam");
return (LRESULT)TRUE;
}
// Show the status ID and status text...
wsprintf(caption, "Status# %d: %s", nID, lpStatusText);
SetWindowText((HWND)Form1->Handle, (LPSTR)caption);
return (LRESULT)TRUE;
}
Technical Details
Message-ID:
<44017935$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,22ad6df66dd21099,start X-Google-Attributes: gid10d0fc,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrew" <mcisaacame@shaw.ca> Sender: "Andrew" <mcisaacame@shaw.ca> Reply-To: "Andrew" <mcisaacame@shaw.ca> Subject: Multiple Video Display USB Newsgroups: borland.public.cppbuilder.multimedia X-User-Info: 24.70.95.203 X-Forwarded-For: 68.148.133.2 NNTP-Posting-Host: 207.105.83.66 Message-ID: <44017935$1@newsgroups.borland.com> Date: 26 Feb 2006 01:47:33 -0700 X-Trace: newsgroups.borland.com 1140947253 207.105.83.66 (26 Feb 2006 01:47:33 -0700) Lines: 131 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail