#include #include #pragma hdrstop #include "MultiCams_.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "VidGrab" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::SetupVideoCaptureDevice (TVideoGrabber *VideoGrabber, int VideoDeviceIndex) { // NOTE: THE SETTINGS BELOW CAN BE DONE AT DESIGN TIME FROM THE OBJECT INSPECTOR // we assign each video capture device respectively to each component (0, 1, 2 and 3) VideoGrabber->VideoDevice = VideoDeviceIndex; // we assign a different prefix to file names for each camera during frame capture VideoGrabber->AutoFilePrefix = "cam" + IntToStr (VideoDeviceIndex + 1) + "_"; // if the video capture device is DV, this will divide the frame rate by 2 (15 fps NTSC or 12.5 fps PAL) VideoGrabber->DVReduceFrameRate = True; // otherwise we set 15 fps for non-DV video sources VideoGrabber->FrameRate = 15; // this will reduce the CPU load by dividing the preview frame rate by 2 (but this does not modify the capture frame rate VideoGrabber->ReducePreviewCPULoad = true; // we don't want to worry about sizes, we choose to preview in 320x240 using the nearest size available on the video capture device VideoGrabber->UseNearestVideoSize (320, 240, true); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { SetupVideoCaptureDevice (VideoGrabber1, 0); SetupVideoCaptureDevice (VideoGrabber2, 1); SetupVideoCaptureDevice (VideoGrabber3, 2); SetupVideoCaptureDevice (VideoGrabber4, 3); Edit3->Text = VideoGrabber1->StoragePath; // we use a common storage path in this project } //--------------------------------------------------------------------------- void __fastcall TForm1::ProcessFrameCapture (TVideoGrabber *VideoGrabber) { switch (RadioGroup1->ItemIndex) { case 0: VideoGrabber->CaptureFrameTo (fc_TBitmap ); break; case 1: VideoGrabber->CaptureFrameTo (fc_JpegFile); break; case 2: VideoGrabber->CaptureFrameTo (fc_BmpFile ); break; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { CheckBox1->Checked = false; // stops the burst mode (see CheckBox1Click code) ProcessFrameCapture (VideoGrabber1); ProcessFrameCapture (VideoGrabber2); ProcessFrameCapture (VideoGrabber3); ProcessFrameCapture (VideoGrabber4); } //--------------------------------------------------------------------------- void __fastcall TForm1::ProcessAutomaticCapture (TVideoGrabber *VideoGrabber) { if (CheckBox1->Checked) { switch (RadioGroup1->ItemIndex) { case 0: VideoGrabber->BurstType = fc_TBitmap ; break; case 1: VideoGrabber->BurstType = fc_JpegFile; break; case 2: VideoGrabber->BurstType = fc_BmpFile ; break; } VideoGrabber->BurstCount = 0; // don't stop capturing frames VideoGrabber->BurstMode = true; // starts capturing frames automatically VideoGrabber->BurstInterval = StrToIntDef (Edit2->Text, 0); // we skip n frames for each frame captured } else { VideoGrabber->BurstMode = false; // stops capturing frames automatically } } //--------------------------------------------------------------------------- void __fastcall TForm1::CheckBox1Click(TObject *Sender) { ProcessAutomaticCapture (VideoGrabber1); ProcessAutomaticCapture (VideoGrabber2); ProcessAutomaticCapture (VideoGrabber3); ProcessAutomaticCapture (VideoGrabber4); } //--------------------------------------------------------------------------- void __fastcall TForm1::VideoGrabber1FrameCaptureCompleted(TObject *Sender, const TFrameData &FrameData, TFrameCaptureDest DestType, AnsiString FileName, bool Success) { Image1->Picture->Bitmap->Assign (FrameData.Bitmap); if (DestType != fc_TBitmap) { Memo2->Lines->Add (FileName); Memo2->Lines->Add (""); } } //--------------------------------------------------------------------------- void __fastcall TForm1::VideoGrabber2FrameCaptureCompleted(TObject *Sender, const TFrameData &FrameData, TFrameCaptureDest DestType, AnsiString FileName, bool Success) { Image2->Picture->Bitmap->Assign (FrameData.Bitmap); if (DestType != fc_TBitmap) { Memo2->Lines->Add (FileName); Memo2->Lines->Add (""); } } //--------------------------------------------------------------------------- void __fastcall TForm1::VideoGrabber3FrameCaptureCompleted(TObject *Sender, const TFrameData &FrameData, TFrameCaptureDest DestType, AnsiString FileName, bool Success) { Image3->Picture->Bitmap->Assign (FrameData.Bitmap); if (DestType != fc_TBitmap) { Memo2->Lines->Add (FileName); Memo2->Lines->Add (""); } } //--------------------------------------------------------------------------- void __fastcall TForm1::VideoGrabber4FrameCaptureCompleted(TObject *Sender, const TFrameData &FrameData, TFrameCaptureDest DestType, AnsiString FileName, bool Success) { Image4->Picture->Bitmap->Assign (FrameData.Bitmap); if (DestType != fc_TBitmap) { Memo2->Lines->Add (FileName); Memo2->Lines->Add (""); } } //--------------------------------------------------------------------------- void __fastcall TForm1::RadioGroup1Click(TObject *Sender) { CheckBox1Click (CheckBox1); // to reflect the new value } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton7Click(TObject *Sender) { AnsiString Dir = VideoGrabber1->StoragePath; if (SelectDirectory (Dir, TSelectDirOpts() << sdAllowCreate << sdPerformCreate << sdPrompt, 0)) { Edit3->Text = Dir; VideoGrabber1->StoragePath = Dir; VideoGrabber2->StoragePath = Dir; VideoGrabber3->StoragePath = Dir; VideoGrabber4->StoragePath = Dir; } } //---------------------------------------------------------------------------