Initialising camera (blank grey boxes) - C++
Posted: 11 September 2010 06:55 AM   [ Ignore ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Hey everyone!

So I’ve been playing about with the API for a while, understanding some parts of it and some others don’t seem to make much sense to me. As I’ve said previously, my knowledge and understanding of C++ isn’t the greatest…yet! :D

Would anyone be able to demonstrate a very crude/simplistic implementation of the following functions or tell me where I am going wrong.

CLEyeCameraInstance CLEyeCreateCamera(CamUIID as GUID, CLEyeCameraColorMode, CLEyeCameraResolution, Framerate as int) returns CLEyeCameraInstance

I have managed to get this function working **I think** however i dont really understand how i can then call on the camera instance to display it out to the screen. I’m assuming I pass the instance to a new OpenCV window. or use: bool CLEyeCameraStart(CLEyeCameraInstance)

What I have managed to patch together so far:

bool createcam int xint fps)
{
CLEyeCameraInstance newcam 
CLEyeCreateCamera(CLEyeGetCameraUUID(x), CLEYE_COLOR_RAWCLEYE_VGAfps);
if(
newcam !=NULL)
{
cout
<<"Camera "<<x<<" created successfully!"<<endl;
bool makecam(char newcam);
return 
true;
}
else
return 
false;

I have attempted to make this into a function, however i am unable to pass “newcam” in through the function as i get an error of undeclared variable and unable to convert const char to char or vice versa.
I am looking to create a multicam set-up, but think its best to improve my understanding of C++ and the API before I hit the deep end.

Hope someone can help me!

Profile
 
 
Posted: 14 September 2010 09:46 AM   [ Ignore ]   [ # 1 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

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
window_small.JPG

Large Window
window_large.JPG

CMD console window
output.JPG

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 argcchar *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 0numCamsi++)
    
{
        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(windowNameguidCLEYE_MONO_RAWCLEYE_QVGA30);
        
        
        
printf("Starting capture on camera %d\n"i+1);
        
cam[i]->StartCapture();
    
}
    cin
.get();                                                                    //wait on keypress
     
for(int i 0numCamsi++)
    
{
        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 resolutionfloat fps) :
                                
_cameraGUID(cameraGUID), _cam(NULL), _mode(mode),
                                
_resolution(resolution), _fps(fps), _running(false)
        
{
        strcpy_s
(_windowNamewindowName);
        
}


bool StartCapture
()
    
{
        _running 
true;
        
cvNamedWindow(_windowNameCV_WINDOW_AUTOSIZE);
        
// Start CLEye image capture thread
        
_hThread CreateThread(NULL0, &CLEyeCameraCapture;::CaptureThreadthis00);
        if(
_hThread == NULL)
    
{
        
return false;
    
}
        
return true;
    
}
void StopCapture
()
    
{
        
if(!_running)   return;
        
_running false;
        
WaitForSingleObject(_hThread1000);
        
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(_camwh);
        
// Depending on color mode chosen, create the appropriate OpenCV image
        
if(_mode == CLEYE_MONO_PROCESSED)
            
pCapImage cvCreateImage(cvSize(wh), IPL_DEPTH_8U1);
        else
            
pCapImage cvCreateImage(cvSize(wh), IPL_DEPTH_8U4);
 
        
// Set some camera parameters
            
CLEyeSetCameraParameter(_camCLEYE_GAIN20);
            
CLEyeSetCameraParameter(_camCLEYE_EXPOSURE511);
        
        
// Start capturing
            
CLEyeCameraStart(_cam);
        
// image capturing loop
        
while(_running)
    
{
            cvGetImageRawData
(pCapImage, &pCapBuffer;);
            
CLEyeCameraGetFrame(_campCapBuffer);
            
cvShowImage(_windowNamepCapImage);
    
}
        
// 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
        
CLEyeCameraCapturepThis = (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

Profile
 
 
Posted: 16 September 2010 12:49 AM   [ Ignore ]   [ # 2 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Anybody have any ideas as to what might be causing this?

Profile
 
 
Posted: 16 September 2010 08:33 AM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

The reason why you are not seeing anything in the capture windows might be because you are creating the camera with CLEYE_MONO_RAW color mode (although with this setting you should be seeing something other than just gray image).

According to the code the color mode should be either CLEYE_MONO_PROCESSED or CLEYE_COLOR_PROCESSED.

This mode is checked in the following code:

if(_mode == CLEYE_MONO_PROCESSED)
            
pCapImage cvCreateImage(cvSize(wh), IPL_DEPTH_8U1);
        else
            
pCapImage cvCreateImage(cvSize(wh), IPL_DEPTH_8U4); 

As you can see, depending on the mode selected, a different opencv image is being created.
For the grayscale this will be a single channel 8bit and for color it is four channel 8bits per channel image.

If you look at the C++ sample code (CLEyeMulticamTest project) in the latest CL-Eye Platform SDK, you’ll find exact code and full VS2008 project that you can compile and modify.
This might be a good starting point that will get you going.

AlexP

Profile
 
 
Posted: 16 September 2010 01:29 PM   [ Ignore ]   [ # 4 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Thanks for that AlexP

I totally butchered the code, decided to start from fresh from the SDK. Given this, it has given me the opportunity to get used to the API, which is definately a plus. Also noticed there were some differences in the new SDK code and the example in the research section on line. I don’t know if that matters, however I’ve just got 4 cameras to work at VGA @ 30fps. I’m looking to get 8 cameras powered (hopefully VGA @ 60fps)

Probably good for a new thread but, do you think installing a PCIE USB card with dual controllers be sufficient to power 8 cameras? There was no information on the hardware you used during your 8 camera showcase.


Thanks for the help!

kshaaban

Profile
 
 
Posted: 20 September 2010 04:05 PM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

Because of the limited maximum USB 2.0 bandwidth, you might be able to run two maximum of two cameras at VGA resolution @ 60fps. Anything more than that will exceed the bandwidth of the single USB controller. Therefore you’d need to balance bandwidth load by connecting two cameras per controller. So in your case I would go with at least 4 USB ports. If the controllers on your PCIE USB can drive two ports each, then this should be good.

AlexP

Profile
 
 
Posted: 20 September 2010 04:25 PM   [ Ignore ]   [ # 6 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

It looks like my controllers are only able to support two at that spec. looks like I’m going to have to invest in some USB cards :D. Given the final project is going to be running on a custom built machine, now is the perfect time to figure out the specifications. The hardware side seems to be the easiest part for me so far. My coding is OK, however digesting the SDK samples is taking the most time.

I’ll get there!

thanks again.

Profile
 
 
 
 


RSS 2.0     Atom Feed