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 »

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
mcleanross
Posts: 1
Joined: Tue Aug 09, 2022 11:56 pm

Re: Camera Initialize not working sometimes

Post by mcleanross »

Camera works in Windows but also facing some problems
cookie clicker
sharase
Posts: 1
Joined: Wed Nov 09, 2022 7:38 pm

Re: Camera Initialize not working sometimes

Post by sharase »

This is a common problem. The first time you run the app, it will initialize the camera and take a snapshot. However, it will not work the next time you run the app. The reason why this happens is that your camera is not initialized properly.
When your phone starts up, it checks to see if there is a camera available. If there is, it will attempt to initialize it. However, if there is no camera available, your phone will try to create one.
subway surfers
herrry99
Posts: 8
Joined: Tue Dec 06, 2022 12:47 am

Re: Camera Initialize not working sometimes

Post by herrry99 »

malizadeh91 wrote: 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
The first thing to do is to make sure that the cameras are properly connected to the device and that they are powered on. If the cameras are still not being detected, you can try restarting the app or rebooting the device. It may also help to update the camera SDK to the latest version. You can also try resetting the cameras by pressing the reset button or disconnecting the cameras and reconnecting them. Finally, you can try using a different USB cable and port to connect the cameras. To find the more information you can also contact me I will do me best to guide you.
Last edited by jillian.smythe on Tue Mar 12, 2024 6:38 am, edited 1 time in total.
Reason: Removing hidden link
Post Reply