Camera Initialize not working sometimes

Post Reply
malizadeh91
Posts: 1
Joined: Tue Jul 05, 2022 1:53 am

Camera Initialize not working sometimes

Post by malizadeh91 » Tue Jul 05, 2022 1:59 am

Hi there,
I have tried to integrate the camera SDK and get the list of cameras. I have read all sample codes.
Now my code is working but sometimes I need to re-start the app to get the cameras. It means for some reason my code can't detect the cameras and I have to restart the app.
Here is my Code:

I have used this function to init:

Code: Select all

int cVideoCameraManager::Initialize()
{
    if( CameraManager::X().WaitForInitialization() )
    {
        UpdateCameraList();

        for( Camera* camera : mAllCameras )
            SetupCamera( *camera );
    }

    return (int)mAllCameras.size();
}
And here is UpdateCameraList function:

Code: Select all

int cVideoCameraManager::UpdateCameraList()
{
    for( Camera* camera : mAllCameras )
    {
        if( camera->IsCameraRunning() )
            camera->Stop();
        camera->Release();
    }
    mAllCameras.clear();

    // Sort cameras by Serial
    struct CompareCameraID 
    {
        bool operator() ( const Camera* cam1, const Camera* cam2 ) const
        {
            return cam1->Serial() < cam2->Serial();
        }
    };

    std::set<Camera*, CompareCameraID> sortedCameras;
    CameraList cameraList;

    for( int i = 0; i < cameraList.Count(); i++ )
    {
        const CameraEntry& cameraEntry = cameraList[i];
        if( Camera* camera = CameraManager::X().GetCameraBySerial( cameraEntry.Serial() ) )
        {
            if( camera->IsCamera() )
            {
                camera->AddRef();
                sortedCameras.insert( camera );
            }
        }
    }

    int cameraID = 1;
    for( Camera* camera : sortedCameras )
        camera->SetNumeric( true, cameraID++ );

    mAllCameras.assign( sortedCameras.begin(), sortedCameras.end() );

    return (int)mAllCameras.size();
}
Thanks in advance

Post Reply