Archive for the ‘Capture’ tag
PS3Capture Test Project
The first thing I’d to do is to capture the frames of each camera. So i created the test project called PS3Capture for doing this job.
PS3 Class
The job of this class is to capture the frames of the PS3 eye cameras, display frames or just return the frame pointer to other functions.
Main Public Methods
- GetCameraCount() (Get PS3 camera count)
- GetGUID( int camId ) (Get the device GUID by Id )
- GetGUID() (Get this PS3 camera GUID)
- SetCamera() (Set the params to the camera)
- StartCamera() (Start the camera)
- StopCamera() (Stop the camera)
- ShowWindow() (Show the window or not, control by bool value)
- GetFrameCount() (Get the frame count)
- GetPixels() (Get the pointer of frames)
Other methods can be seen at online svn browser
CamSplice Class
The main job of this class is to test the frames capture function of PS3 class, and display the spliced result image. Users can also control the order the images.
Main Public Methods
- SetXY() (Set the x/y axis camera number)
- SetWidthHeight() (Set the width/height for CAMERA resolution)
- SetCamVec() (Set the PS3* vector which content camera order info)
- Start() (Start the process)
- Stop() (Stop the process)
Main Private Methods
- Run() (The main method do the process job)
- DisplayThread() (The callback method for multi-thread)
- SetImagePixels() (Set the spliced image from every camera’s frame)
Other methods can be seen at online svn browser
Main Entry
This file named main.cpp as the main entry of the project.
Main functions
- PrintHelp() (Print help information)
- SelectCamera() (Select the camera by key pressed)
- IsCameraIndexCorrect() (Return true if the index is correct)
- CameraSettings() (The first step of splice process)
- CameraSplice() (The main process of camera splice)
- main() (The entry)
This file can be seen at online svn browser
I will explain the main() function below, as it’s entry of the project.
Get the PS3 camera count by the static method GetCameraCount().
camCount = PS3::GetCameraCount();
Allocate the space by camCount.
cams = new PS3*[camCount];
And then, we get device guid each camera by using the static method GetGUID( int camId ).
for ( int i = 0; i < camCount; i++ ) { GUID guid = PS3::GetGUID( i );
Create and set the new camera.
cams[i] = new PS3(); //! Set the values for camera cams[i]->SetCamera( guid, //!< Camera with this guid you want to create CLEYE_MONO_PROCESSED, //!< Gray mode CLEYE_VGA, //!< Resolution of camera VGA(640x480) or QVGA(320x240) 30 //!< Framerate ); //! Show window to display the capture images cams[i]->SetShow( true ); cams[i]->SetWindowTitle( " ID: " + PS3::Int2String(i) + " [GUID: " + PS3::GUID2String(guid, '-', true ) + "]");
Start the camera.
if ( cams[i]->StartCamera() ) { printf( "#%d: started!\n", i ); } else { printf( "#%d: could not started!\n", i ); }
Main loop for processing.
while ( ( key = cvWaitKey(0) ) != 0x1b /* ESC key: 27 or 0x1b in hex*/ ) { //! Print DEBUG information printf( "// DEBUG:\n// \tKey: %d [Hex: %x]\n", key, key ); for( int i = 0; i < camCount; ++i ) { printf( "// \t#%d frame count: %d\n", i, cams[i]->GetFrameCount() ); } //! Select the camera to control if ( key >= '0' && key <= '9' ) { if ( SelectCamera( key, camCount ) ) { printf( "Select Camera #%d\n", camIndex ); } else { printf( "Wrong selecting!\n" ); } continue; } if ( pCam != NULL ) { //! camera must be selected switch ( key ) { //! Horizontal flip case 'h': case 'H': hFlip = hFlip ? false : true; if ( pCam->SetHFlip( hFlip ) ) { printf( "Camera #%d Horizontal flip set: %s\n", camIndex, hFlip ? "true" : "false" ); } else { printf( "Camera #%d could not set H Flip\n" ); } break; //! Vertical flip case 'v': case 'V': vFlip = vFlip ? false : true; if ( pCam->SetVFlip( vFlip ) ) { printf( "Camera #%d Vertical flip set: %s\n", camIndex, vFlip ? "true" : "flase" ); } else { printf( "Camera #%d could not set V Flip\n" ); } break; //! Show or hide the window case ' ': //! Should be fixed, developing in this moment bShow = bShow ? false : true; if ( pCam->ShowWindow( bShow ) ) { printf( "%s camera #%d capture image\n", bShow ? "Show" : "Hide", camIndex ); } else { printf( "Could not %s camera #%d capture image\n", bShow ? "show" : "hide", camIndex ); } break; //! Print camera information case 'i': case 'I': printf( "Camera #%d Information:\n" "\tResolution(width x height): %dx%d\n" "\tFPS: %d\n" , camIndex, pCam->GetWidth(), pCam->GetHeight(), pCam->GetFPS() ); break; //! Camera settings case 's': CameraSettings(); break; case 'S': CameraSplice(); break; default: break; } } }
If the user pressed ESC, it will break the loop, and then stop cameras and release resources.
if ( bSpliceMode ) { splice->Stop(); splice = NULL; } //! Release the resources for ( int i = 0; i < camCount; ++i ) { printf( "Stopping capture on camera %d\n", i ); //! Stop the camera cams[i]->StopCamera(); delete cams[i]; }
THE END
Update
2011-05-30
- Add DecrementParam() and IncrementParam() methods for PS3 class.
- Add GAIN parameter setter for main file