So I’ve had a go at trying to break down the Introduction to CL-Eye Multicam C++ API & The CL-Eye Platform SDK C++ Sample found on the research page. utilising the majority of the code on those pages, i have managed to get everything to compile.
Both PS3 cameras are found and initialised. When the OpenCV windows are created, one window is smaller than the other (as pictured) and both just show a blank grey square. I have tested both cameras on a number of different USB ports, and both are currently connected to the back of my PC. Both Cameras work perfectly with CL-EYE Test program and when the cameras are initialised in the code, both of the red LEDs light up.
Small window
Large Window
CMD console window
I can’t seem to see what might be going wrong… I havent got a huge amount of experience with C++ so its bound to be a schoolboy error or I’ve totally screwed it up from the get go.. anyways forgive me in advance, heres the code.
Main
#include "stdafx.h"
#include "includeall.h"
#include "createcamera.hpp"
int main(int argc, char *argv[])
{
/*---------------------------CODE STARTS HERE---------------------------------*/
CLEyeCameraCapture *cam[2];
srand(GetTickCount());
// Query for number of connected cameras
int numCams = CLEyeGetCameraCount();
if(numCams == 0)
{
printf("No PS3Eye cameras detected\n");
return -1;
}
printf("Found %d cameras\n", numCams);
for(int i = 0; i < numCams; i++)
{
char windowName[64];
// Query unique camera uuid
GUID guid = CLEyeGetCameraUUID(i);
//debug function
/*printf("Camera %d GUID: [x-x-x-xxxxxxxx]\n",
i+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]);*/
sprintf_s(windowName, "Camera Window %d", i+1);
// Create camera capture object
cam[i] = new CLEyeCameraCapture(windowName, guid, CLEYE_MONO_RAW, CLEYE_QVGA, 30);
printf("Starting capture on camera %d\n", i+1);
cam[i]->StartCapture();
}
cin.get(); //wait on keypress
for(int i = 0; i < numCams; i++)
{
printf("Stopping capture on camera %d\n", i+1);
cam[i]->StopCapture();
delete cam[i];
}
return 0;
}
AND Camera.hpp
#include "stdafx.h"
#include "includeall.h"
class CLEyeCameraCapture;class CLEyeCameraCapture
{
public:
char _windowName[256];
GUID _cameraGUID;
CLEyeCameraInstance _cam;
CLEyeCameraColorMode _mode;
CLEyeCameraResolution _resolution;
float _fps;
HANDLE _hThread;
bool _running;
CLEyeCameraCapture(LPSTR windowName,
GUID cameraGUID,
CLEyeCameraColorMode mode,
CLEyeCameraResolution resolution, float fps) :
_cameraGUID(cameraGUID), _cam(NULL), _mode(mode),
_resolution(resolution), _fps(fps), _running(false)
{
strcpy_s(_windowName, windowName);
}
bool StartCapture()
{
_running = true;
cvNamedWindow(_windowName, CV_WINDOW_AUTOSIZE);
// Start CLEye image capture thread
_hThread = CreateThread(NULL, 0, &CLEyeCameraCapture;::CaptureThread, this, 0, 0);
if(_hThread == NULL)
{
return false;
}
return true;
}
void StopCapture()
{
if(!_running) return;
_running = false;
WaitForSingleObject(_hThread, 1000);
cvDestroyWindow(_windowName);
}
void Capture()
{
int w, h;
IplImage *pCapImage;
PBYTE pCapBuffer = NULL;
// Create camera instance
_cam = CLEyeCreateCamera(_cameraGUID, _mode, _resolution, _fps);
if(_cam == NULL) return;
// Get camera frame dimensions
CLEyeCameraGetFrameDimensions(_cam, w, h);
// Depending on color mode chosen, create the appropriate OpenCV image
if(_mode == CLEYE_MONO_PROCESSED)
pCapImage = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1);
else
pCapImage = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 4);
// Set some camera parameters
CLEyeSetCameraParameter(_cam, CLEYE_GAIN, 20);
CLEyeSetCameraParameter(_cam, CLEYE_EXPOSURE, 511);
// Start capturing
CLEyeCameraStart(_cam);
// image capturing loop
while(_running)
{
cvGetImageRawData(pCapImage, &pCapBuffer;);
CLEyeCameraGetFrame(_cam, pCapBuffer);
cvShowImage(_windowName, pCapImage);
}
// Stop camera capture
CLEyeCameraStop(_cam);
// Destroy camera object
CLEyeDestroyCamera(_cam);
// Destroy the allocated OpenCV image
cvReleaseImage(&pCapImage;);
_cam = NULL;
}
static DWORD WINAPI CaptureThread(LPVOID instance)
{
// seed the rng with current tick count and thread id
srand(GetTickCount() + GetCurrentThreadId());
// forward thread to Capture function
CLEyeCameraCapture* pThis = (CLEyeCameraCapture *)instance;
pThis->Capture();
return 0;
}
};
Contents of includeall.h
#include "CLEyeMulticam.h"
#include "highgui.h"
#include "cv.h"
#include <iomanip>
#include <sstream>
#include <iostream>
using namespace std;
I’m Currently using Windows 7 Professional x64 edition (I believe VC++ express 2008 is set to x86)
Hopefully a fresh set of eyes could help me with this issue. Any pointers to help improve my C++ code would be good as well. I’m really getting into C++ and i know it can be an easy time to accidentally pick up bad habits. Any comments would help!
Thanks