Finally, here is the long awaited PS3Eye multicam driver
After a lot of testing and optimization of the internal driver code, I finally am ready to release the first version of the PS3Eye multicam driver.
For your reference, below is the diagram of the internal components of the driver. For a single camera configuration the ‘Image Stitching’ component is bypassed.
The driver exports simple API that allows for full control of PS3Eye cameras.
I chose a C style export functions this time to allow for easier integration with different programming languages such as C#.
Here is the ‘PS3EyeMulticam.h’ file that you would normally include in your code:
//////////////////////////////////////////////////////////////////////////////////////////// // // This library allows you to use multiple PS3Eye cameras in your own applications. // // For updates, more information and downloads visit: // http://www.alexpopovich.com or // https://alexpopovich.wordpress.com/ // // Copyright 2008,2009 (c) AlexP. All rights reserved. // //////////////////////////////////////////////////////////////////////////////////////////// #pragma once #include <windows .h> #ifdef PS3EYEMULTICAM_EXPORTS #define PS3EYEMULTICAM_API extern "C" __declspec(dllexport) #else #define PS3EYEMULTICAM_API extern "C" __declspec(dllimport) #endif //////////////////////////////////////////////////////////////////////////////////////////// // PS3EyeMulticam API //////////////////////////////////////////////////////////////////////////////////////////// typedef enum{ QVGA, VGA }Resolution; // Camera information PS3EYEMULTICAM_API int PS3EyeMulticamGetCameraCount(); // Library initialization PS3EYEMULTICAM_API bool PS3EyeMulticamOpen(int camCnt, Resolution res, int frameRate); PS3EYEMULTICAM_API void PS3EyeMulticamClose(); // Capture control PS3EYEMULTICAM_API bool PS3EyeMulticamStart(); PS3EYEMULTICAM_API void PS3EyeMulticamStop(); // Settings control PS3EYEMULTICAM_API bool PS3EyeMulticamLoadSettings(char* fileName="settings.xml"); PS3EYEMULTICAM_API bool PS3EyeMulticamSaveSettings(char* fileName="settings.xml"); PS3EYEMULTICAM_API void PS3EyeMulticamShowSettings(); // Processed frame image data retrieval PS3EYEMULTICAM_API bool PS3EyeMulticamGetFrameDimensions(int &width, int &height); PS3EYEMULTICAM_API bool PS3EyeMulticamGetFrame(PBYTE pData, int waitTimeout=2000); ////////////////////////////////////////////////////////////////////////////////////////////
Included in the driver archive is a full source code of a simple ‘PS3EyeMulticamTest’ application that allows you to run and test the multicamera driver. This code could also serve as a good starting point for writing your own OpenCV image processing apps.
The PS3EyeMulticamTest app uses all of the API functions defined in ‘PS3EyeMulticam.h’ file.
Here is the ‘PS3EyeMulticamTest.cpp’ file:
// // PS3EyeMulticamTest.cpp // // This is a quick test application for the // PS3EyeMulticam driver // // To build it, in VS2008 create en empty window app project // and add all the files in this folder to it. // #include "stdafx.h" #define WINDOW_NAME "Capture Window" bool bRunning = false; int w, h; // Capture thread DWORD WINAPI Capture(LPVOID) { IplImage *grayImage = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1); PS3EyeMulticamStart(); while(bRunning) { PBYTE pBuffer = NULL; cvGetImageRawData(grayImage, &pBuffer); PS3EyeMulticamGetFrame(pBuffer); cvShowImage(WINDOW_NAME, grayImage); } PS3EyeMulticamStop(); cvReleaseImage(&grayImage); return 0; } void Program() { // Query driver for number of connected PS3Eye cameras int camCnt = PS3EyeMulticamGetCameraCount(); printf("Found %d PS3Eye cameras\n", camCnt); if(camCnt == 0) { MessageBox(NULL,"No PS3Eye camera(s) found","PS3EyeMulticamTest", MB_ICONEXCLAMATION); return; } // Open cameras if(!PS3EyeMulticamOpen(camCnt, VGA, 30)) { MessageBox(NULL,"Could not open PS3Eye camera(s)","PS3EyeMulticamTest", MB_ICONEXCLAMATION); return; } // Load the default camera settings 'settings.xml' file // If the file is not found it will be created PS3EyeMulticamLoadSettings("settings.xml"); // Get output image dimensions PS3EyeMulticamGetFrameDimensions(w, h); printf("Image dimensions (%d, %d)\n", w, h); // Create OpenCV main window cvNamedWindow(WINDOW_NAME, CV_WINDOW_AUTOSIZE); cvMoveWindow(WINDOW_NAME, 0, 0); cvResizeWindow(WINDOW_NAME, w, h); // Start PS3Eye image capture thread HANDLE hThread = CreateThread(NULL, 0, Capture, NULL, 0, 0); if(hThread == NULL) { MessageBox(NULL,"Could not create capture thread","PS3EyeMulticamTest", MB_ICONEXCLAMATION); PS3EyeMulticamClose(); return; } bRunning = true; // The '<esc>' key will exit the program // The 's' key will open camera settings dialog while(bRunning) { int key = cvWaitKey(0); switch(key) { case 's': case 'S': // Display settings PS3EyeMulticamShowSettings(); break; case 0x1b: printf("Exiting...\n"); // Stop the capture thread bRunning = false; // Wait for thread to exit WaitForSingleObject(hThread, 3000); printf("Thread exited\n"); break; } } // Save camera settings printf("Saving settings\n"); PS3EyeMulticamSaveSettings(); printf("Closing OpenCV window\n"); cvDestroyWindow(WINDOW_NAME); PS3EyeMulticamClose(); } // This is the program entry if you link with /SUBSYSTEM:CONSOLE option int main(int argc, char *argv[]) { Program(); return 0; } // This is the program entry if you link with /SUBSYSTEM:WINDOWS option int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { Program(); return 0; }
Last but not least, here you will find the PS3EyeMulticam.rar file.
Enjoy!
~Alex