Page 1 of 1

Camera Initialize not working sometimes

Posted: Tue Jul 05, 2022 1:59 am
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

Re: Camera Initialize not working sometimes

Posted: Tue Aug 09, 2022 11:59 pm
by mcleanross
Camera works in Windows but also facing some problems
cookie clicker

Re: Camera Initialize not working sometimes

Posted: Sun Nov 20, 2022 7:28 pm
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

Re: Camera Initialize not working sometimes

Posted: Sat Jan 07, 2023 4:33 am
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.