Code is straightforward and with 60fps set on my dual core CPU I get 50% CPU utilization (one core in Performance shows almost full load). Increasing FPS to 75 in code, causes drop in frames => real FPS reported by code doesn’t go above 55fps.
#include “stdafx.h”
#include <time.h>
#include “CLEyeMulticam.h”
// Sample camera capture class
class CLEyeCameraCapture
{
GUID _cameraGUID;
CLEyeCameraInstance _cam;
CLEyeCameraColorMode _mode;
CLEyeCameraResolution _resolution;
int _fps;
HANDLE _hThread;
bool _running;
LPBYTE m_pBuffer;
public:
CLEyeCameraCapture(GUID cameraGUID,
CLEyeCameraColorMode mode,
CLEyeCameraResolution resolution, int fps) :
_cameraGUID(cameraGUID), _cam(NULL), _mode(mode),
_resolution(resolution), _fps(fps), _running(false)
{
}
~CLEyeCameraCapture()
{
if(m_pBuffer)
delete [] m_pBuffer;
}
bool StartCapture()
{
if(!m_pBuffer)
return _running = false;
_running = true;
// Start CLEye image capture thread
_hThread = CreateThread(NULL, 0, &CLEyeCameraCapture;::CaptureThread, this, 0, 0);
if(_hThread == NULL)
{
MessageBox(NULL,“Could not create capture thread”,“CLEyeMulticamTest”, MB_ICONEXCLAMATION);
_running = false;
}
return _running;
}
void StopCapture()
{
if(!_running) return;
_running = false;
WaitForSingleObject(_hThread, 1000);
}
void IncrementCameraParameter(int param)
{
if(!_cam) return;
CLEyeSetCameraParameter(_cam,
(CLEyeCameraParameter)param,
CLEyeGetCameraParameter(_cam, (CLEyeCameraParameter)param)+10);
}
void DecrementCameraParameter(int param)
{
if(!_cam) return;
CLEyeSetCameraParameter(_cam,
(CLEyeCameraParameter)param,
CLEyeGetCameraParameter(_cam, (CLEyeCameraParameter)param)-10);
}
void Capture()
{
_cam = CLEyeCreateCamera(_cameraGUID, _mode, _resolution, _fps);
// Set some camera parameters
CLEyeSetCameraParameter(_cam, CLEYE_GAIN, 20);
CLEyeSetCameraParameter(_cam, CLEYE_EXPOSURE, 511);
// Start capturing
DWORD dwClock = clock()-1;
int i=0;
CLEyeCameraStart(_cam);
// image capturing loop
while(_running)
{
m_pBuffer = new BYTE[((_resolution==CLEYE_QVGA)?(320*240):(640*480))*sizeof(RGBQUAD)];
Sleep(0);
if(CLEyeCameraGetFrame(_cam, m_pBuffer, 10))
{
printf(”%d %g\r”, i++, i/((clock()-dwClock)/1000.));
LPBYTE pBuffer = new BYTE[((_resolution==CLEYE_QVGA)?(320*240):(640*480))*sizeof(RGBQUAD)];
if(pBuffer)
{
CopyMemory(pBuffer, m_pBuffer, ((_resolution==CLEYE_QVGA)?(320*240):(640*480))*sizeof(RGBQUAD));
delete [] pBuffer;
}
}
if(m_pBuffer)
delete [] m_pBuffer;
}
// Stop camera capture
CLEyeCameraStop(_cam);
// Destroy camera object
CLEyeDestroyCamera(_cam);
_cam = NULL;
}
static DWORD WINAPI CaptureThread(LPVOID instance)
{
// SetThreadPriority(GetCurrentThread(), REALTIME_PRIORITY_CLASS);
// forward thread to Capture function
CLEyeCameraCapture *pThis = (CLEyeCameraCapture *)instance;
pThis->Capture();
return 0;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
// SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
CLEyeCameraCapture *pCam = NULL;
int numCams = CLEyeGetCameraCount();
if(numCams == 0)
{
printf(“No PS3Eye cameras detected\n”);
return -1;
}
printf(“Found %d cameras\n”, numCams);
GUID guid = CLEyeGetCameraUUID(0);
printf(“Camera %d GUID: [x-x-x-xxxxxxxx]\n”,
1, guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2],
guid.Data4[3], guid.Data4[4], guid.Data4[5],
guid.Data4[6], guid.Data4[7]);
pCam = new CLEyeCameraCapture(guid, CLEYE_COLOR, CLEYE_VGA, 60); // <= change here fps to 75 => I’m not getting more then 55 <= drop frames start happening
pCam->StartCapture();
Sleep(100000);
pCam->StopCapture();
delete pCam;
return 0;
}