CLEyeCreateCamera() calling order
Posted: 18 December 2010 01:44 PM   [ Ignore ]
New Member
Rank
Total Posts:  5
Joined  2010-04-02

Suppose I have four cameras connected to my computer, and calling CLEyeGetCameraUUID() returns guid0, guid1, guid2, and guid3 for camera indexes 0, 1, 2, and 3 respectively.

No suppose one application/thread calls CLEyeCreateCamera(), CLEyeCameraStart(), and starts capturing frames with CLEyeCameraGetFrame() from guid0 and guid3.

When I then try to CLEyeCreateCamera() on guid1 and guid2 from another application/thread, the call fails (the returned CLEyeCameraInstance is NULL).

Is there some kind of restriction on the order in which CLEyeCreateCamera() can be called on the guids?  I believe if I first create/start guid0 and guid1 from the 1st application/thread, then the 2nd application/thread IS successfully able to create/start guid2 and guid3.

Am I missing something?


Thanks,
MP

Profile
 
 
Posted: 18 December 2010 01:51 PM   [ Ignore ]   [ # 1 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Hi MP

Have you looked at the sample code for initialising multiple cameras : http://codelaboratories.com/research/view/cl-eye-platform-cpp-sample

I don’t know if that will help solve your problems. If your still having trouble, it might be helpful if you post your code.

-Khaled

Profile
 
 
Posted: 20 December 2010 01:12 PM   [ Ignore ]   [ # 2 ]
New Member
Rank
Total Posts:  5
Joined  2010-04-02

Hi,

I’ve attached two files: dummy1.cpp and dummy2.cpp.  The only difference between the two files is in the fixedGuidArray[] definition at the top.  I have 4 cameras connected to my computer, all of which have been activated.  I’m running the CLEyeMulticam.dll in the redist directory.  I have version 4.0.2.1017 of the driver, and version 1.2.0.1008 of the SDK.

If I run dummy1 first, and then run dummy2, I get the following outputs:

dummy1.exe output:

Found 4 cameras
PSeye[0]
295315e9-6975-5ef4-7c85-6b216c45ddbd
PSeye[1]
1a2c87e1-3cce-c320-eee0-c4bc80fd0c55
PSeye[2]
dbfef392-249c-7f50-eaf2-277e1f37d47c
PSeye[3]
79445588-fcef-5c20-2822-fc3ea210877c
PSeye[0]
create success
PSeye[1]
create success
PSeye[0]
start success
PSeye[1]
start success
PSeye[0]
buffer allocated
PSeye[1]
buffer allocated
Hit a key to quit 

dummy2.exe output:

Found 1 camera
PSeye[0]
295315e9-6975-5ef4-7c85-6b216c45ddbd
PSeye[0]
create success
PSeye[1]
creation failed 

If I run dummy2 first, and then dummy1, I get the following:

dummy2.exe output:

Found 4 cameras
PSeye[0]
295315e9-6975-5ef4-7c85-6b216c45ddbd
PSeye[1]
1a2c87e1-3cce-c320-eee0-c4bc80fd0c55
PSeye[2]
dbfef392-249c-7f50-eaf2-277e1f37d47c
PSeye[3]
79445588-fcef-5c20-2822-fc3ea210877c
PSeye[0]
create success
PSeye[1]
create success
PSeye[0]
start success
PSeye[1]
start success
PSeye[0]
buffer allocated
PSeye[1]
buffer allocated
Hit a key to quit 

dummy1.exe output:

No cameras found 

Am I doing something wrong?

Here’s dummy1.cpp:

#include <stdio.h>
#include <iostream>
#include <conio.h>
#include "CLEyeMulticam.h"

#define NUM_FIXED_CAMS 2

/************************************************************************/
int
main
(int argcchar **argv)
{
    GUID fixedGuidArray[NUM_FIXED_CAMS] 
{
        
// { 0x295315e9, 0x6975, 0x5ef4,
        //   { 0x7c, 0x85, 0x6b, 0x21, 0x6c, 0x45, 0xdd, 0xbd } },
        
{ 0x1a2c87e10x3cce0xc320,
          
{ 0xee0xe00xc40xbc0x800xfd0x0c0x55 } },
        
{ 0xdbfef3920x249c0x7f50,
          
{ 0xea0xf20x270x7e0x1f0x370xd40x7c } },
        
// { 0x79445588, 0xfcef, 0x5c20,
        //   { 0x28, 0x22, 0xfc, 0x3e, 0xa2, 0x10, 0x87, 0x7c } },
    
};

    
// camera count
    
int numCams CLEyeGetCameraCount();
    if (
numCams <= 0)
    
{
        printf
("No cameras found\n");
        return -
1;
    
}
    
else
    
{
        printf
("Found %d camera%s\n"numCamsnumCams == "" "s");
    
}

    
// get and print GUIDs
    
GUID *guidArray = new GUID[numCams];
    for (
int idx 0idx numCamsidx++)
    
{
        guidArray[idx] 
CLEyeGetCameraUUID(idx);

        
GUID *= &guidArray;[idx];
        
printf("PSeye[%d]: lx-hx-hx-xx-xxxxxx\n",
               
idx,
               
g->Data1g->Data2g->Data3,
               
g->Data4[0]g->Data4[1]g->Data4[2]g->Data4[3],
               
g->Data4[4]g->Data4[5]g->Data4[6]g->Data4[7]);
    
}

    
// create fixed cameras
    
CLEyeCameraInstance cam[NUM_FIXED_CAMS];
    for (
int idx 0idx NUM_FIXED_CAMSidx++)
    
{
        cam[idx] 
CLEyeCreateCamera(fixedGuidArray[idx],
                                     
CLEYE_MONO_PROCESSED,
                                     
CLEYE_VGA,
                                     
30);
        if (
cam[idx] == NULL)
        
{
            
for (int idx2 0idx2 idxidx2++)
            
{
                CLEyeDestroyCamera
(cam[idx2]);
            
}
            printf
("PSeye[%d]: creation failed\n"idx);

            return -
1;
        
}

        printf
("PSeye[%d]: create success\n"idx);
    
}

    
// start fixed cameras
    
for (int idx 0idx NUM_FIXED_CAMSidx++)
    
{
        bool success 
CLEyeCameraStart(cam[idx]);

        if (! 
success)
        
{
            
for (int idx2 0idx2 idxidx2++)
            
{
                CLEyeCameraStop
(cam[idx2]);
                
CLEyeDestroyCamera(cam[idx2]);
            
}
            printf
("PSeye[%d]: start failed\n"idx);

            return -
1;
        
}

        printf
("PSeye[%d]: start success\n"idx);
    
}

    
// allocate memory for buffers
    
PBYTE buf[NUM_FIXED_CAMS];
    for (
int idx 0idx NUM_FIXED_CAMSidx++)
    
{
        buf[idx] 
= new BYTE[640*480];
        
printf("PSeye[%d]: buffer allocated\n"idx);
    
}

    
// sit in a loop getting frames from each camera
    
printf("Hit a key to quit\n");
    while (
1)
    
{
        
for (int idx 0idx NUM_FIXED_CAMSidx++)
        
{
            CLEyeCameraGetFrame
(cam[idx]buf[idx]);
        
}

        
if (_kbhit())
        
{
            
break;
        
}
    }

    
// free memory
    
for (int idx 0idx NUM_FIXED_CAMSidx++)
    
{
        delete buf[idx]
;
        
printf("PSeye[%d], buffer deleted\n"idx);
    
}

    
// stop cameras
    
for (int idx 0idx NUM_FIXED_CAMSidx++)
    
{
        CLEyeCameraStop
(cam[idx]);

        
printf("PSeye[%d]: stopped\n"idx);
    
}

    
// destroy cameras
    
for (int idx 0idx NUM_FIXED_CAMSidx++)
    
{
        CLEyeDestroyCamera
(cam[idx]);

        
printf("PSeye[%d]: destroyed\n"idx);
    
}

    
return 0;

dummy2.cpp is the same except the definition of fixedGuidArray is as follows:

GUID fixedGuidArray[NUM_FIXED_CAMS] {
        { 0x295315e9
0x69750x5ef4,
          
{ 0x7c0x850x6b0x210x6c0x450xdd0xbd } },
        
// { 0x1a2c87e1, 0x3cce, 0xc320,
        //   { 0xee, 0xe0, 0xc4, 0xbc, 0x80, 0xfd, 0x0c, 0x55 } },
        // { 0xdbfef392, 0x249c, 0x7f50,
        //   { 0xea, 0xf2, 0x27, 0x7e, 0x1f, 0x37, 0xd4, 0x7c } },
        
{ 0x794455880xfcef0x5c20,
          
{ 0x280x220xfc0x3e0xa20x100x870x7c } },
    
}

Thanks,
MP

Profile
 
 
Posted: 20 December 2010 06:24 PM   [ Ignore ]   [ # 3 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

Hi MP,

why are you running two programmes this way?
I take it what you intend on doing is creating a fixed list of cameras that always initialise in the same order. You could create this all within one programme. It would be good to hear what the intentions are for this? I am currently creating an array with multiple cameras. There is a stored array of GUIDs which are called and initialised each to their own thread.

The code will act differently as it seems from what you are saying that variables and memory allocations are being written over due to using the same pointer names etc.

It would be good to know what it is this code is aiming to do.

Thanks
-K

Profile
 
 
Posted: 20 December 2010 10:38 PM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

Hi koolness,

From the code ant the output I can assume that the following is the issue you are having:
While in the first loop you use ‘numCams’ (which is btw correct) to display the guids, all the rest of the loops use ‘NUM_FIXED_CAMS’ and static guid array, which might not correct since you those cameras might not be plugged-in or recognized. I suggest you use the mix of both methods, first you scan the cameras and build the guid list, and then look into your own list and use only those guids that exist.

There are no restrictions of the order of camera creation from two different threads in the same process.
However if you are using two different processes and run them in parallel, then there might be a problem. In another words, you should have a way to sync two processes so that you don’t call CLEyeCreateCamera in process #1 before you called CLEyeGetCameraUUID in the process #2. One way to do this is to setup a global mutex or event.

AlexP

Profile
 
 
Posted: 21 December 2010 11:15 AM   [ Ignore ]   [ # 5 ]
New Member
Rank
Total Posts:  5
Joined  2010-04-02

Khaled,

In my setup I have two pairs of cameras, and each pair is assigned a completely different task.  Hence, one way to keep things simple is to have one program per camera pair.  That’s why I create/start the cameras from two different processes.


Alex,

You’ve answered my question with: “if you are using two different processes and run them in parallel, then there might be a problem”.  What I will do is create/start all cameras from one process, and then pass the data to other processes over shared memory.  Either that or run everything as different threads of the same process.  (BTW, everything is plugged in and recognized as the two dummy programs are run within seconds of each other).


Thanks for the clarification,
MP

Profile
 
 
Posted: 21 December 2010 05:30 PM   [ Ignore ]   [ # 6 ]
Member
Avatar
RankRankRank
Total Posts:  76
Joined  2010-08-03

I think what Alex said is what i was thinking, his knowledge in this area is unsurpassed :D

I agree the best approach would really be to initialise all cameras to start off with and then creating separate programmes to perform the tasks you want to achieve. This way its much easier to debug and you will minimise on redundant code.

keep us posted with your progress!

-K

Profile
 
 
 
 


RSS 2.0     Atom Feed