setSensorMode of camera to output 1080p

Hi Guys,

I am trying to set the mode of the camera so as to get the desired resolution outputted directly without using scaler. If I understand it right, the setResolution API sets the final desired resolution and setSensorMode API sets the camera mode. However, I am unable to verify whether the camera mode set for a particular resolution using this API actually works or not. Please find the code snippet below :

bool  execute()
{

    using namespace Argus;
    
    // Initialize the preview window and EGL display.    
    Window &window = Window::getInstance(); 
    PROPAGATE_ERROR(g_display.initialize(window.getEGLNativeDisplay()));

    // Initialize the Argus camera provider.
    UniqueObj<CameraProvider> cameraProvider(CameraProvider::create());

    // Get the ICameraProvider interface from the global CameraProvider.
    ICameraProvider *iCameraProvider = interface_cast<ICameraProvider>(cameraProvider);
    if (!iCameraProvider)
        ORIGINATE_ERROR("Failed to get ICameraProvider interface");

    // Get the camera devices.
    std::vector<CameraDevice*> cameraDevices;
    iCameraProvider->getCameraDevices(&cameraDevices);

    if (cameraDevices.size() < 2)
        ORIGINATE_ERROR("Must have at least 2 sensors available");



    CameraDevice *cameraDevice = cameraDevices[0];
    ICameraProperties *iCameraProperties = interface_cast<ICameraProperties>(cameraDevice);
    if (!iCameraProperties)
        ORIGINATE_ERROR("Failed to get ICameraProperties interface");


    // Create the capture session, AutoControl will be based on what the 1st device sees.
    UniqueObj<CaptureSession> captureSessionCamera0(iCameraProvider->createCaptureSession(cameraDevices[0]));
    ICaptureSession *iCaptureSessionCamera0 = interface_cast<ICaptureSession>(captureSessionCamera0);
    if (!iCaptureSessionCamera0)
        ORIGINATE_ERROR("Failed to get capture session interface");



    std::vector<Argus::SensorMode*> sensorModes;

    // Get the sensor mode to determine the video output stream resolution.   

    iCameraProperties->getSensorModes(&sensorModes);

    if (sensorModes.size() == 0)
	ORIGINATE_ERROR("Failed to get sensor modes");

    ISensorMode *iSensorMode = interface_cast<ISensorMode>(sensorModes[0]);
    if (!iSensorMode)
	ORIGINATE_ERROR("Failed to get sensor mode interface");

    // Create stream settings object and set settings common to both streams.
    UniqueObj<OutputStreamSettings> streamSettingsCamera0(iCaptureSessionCamera0->createOutputStreamSettings());
    IOutputStreamSettings *iStreamSettingsCamera0 = interface_cast<IOutputStreamSettings>(streamSettingsCamera0);
    if (!iStreamSettingsCamera0)
        ORIGINATE_ERROR("Failed to create OutputStreamSettings");
 
    iStreamSettingsCamera0->setPixelFormat(PIXEL_FMT_YCbCr_420_888);
  
    iStreamSettingsCamera0->setResolution(Argus::Size(1920,1080));

    // Create egl streams
    iStreamSettingsCamera0->setCameraDevice(cameraDevices[0]);
    UniqueObj<OutputStream> streamLeft(iCaptureSessionCamera0->createOutputStream(streamSettingsCamera0.get()));
    IStream *iStreamLeft = interface_cast<IStream>(streamLeft);
    if (!iStreamLeft)
        ORIGINATE_ERROR("Failed to create left stream");


    UniqueObj<OutputStream> videoStreamCamera0(iCaptureSessionCamera0->createOutputStream(streamSettingsCamera0.get()));
    IStream *iVideoStreamCamera0 = interface_cast<IStream>(videoStreamCamera0);
    if (!iVideoStreamCamera0)
        ORIGINATE_ERROR("Failed to create video stream");


    // Create a request

    UniqueObj<Request> requestCamera0(iCaptureSessionCamera0->createRequest());	

   IRequest *iRequestCamera0 = interface_cast<IRequest>(requestCamera0);
    if (!iRequestCamera0)
        ORIGINATE_ERROR("Failed to create Request");


    // Enable both streams in the request.    
    iRequestCamera0->enableOutputStream(streamLeft.get());
    ISourceSettings *iSourceSettingsCamera0 = interface_cast<ISourceSettings>(iRequestCamera0->getSourceSettings());
    if (!iSourceSettingsCamera0)
        ORIGINATE_ERROR("Failed to get ISourceSettings interface");
    iSourceSettingsCamera0->setFrameDurationRange(Argus::Range<uint64_t>(1e9/DEFAULT_FPS));
    iSourceSettingsCamera0->setSensorMode(sensorModes[1]);


    // Submit capture for the specified time.
    if (iCaptureSessionCamera0->repeat(requestCamera0.get()) != STATUS_OK)
        ORIGINATE_ERROR("Failed to start repeat capture request for preview");


    // Stop the capture requests and wait until they are complete.
    iCaptureSessionCamera0->stopRepeat();
    iCaptureSessionCamera0->waitForIdle();
    iStreamLeft->disconnect();

    // Disconnect Argus producer from the EGLStreams (and unblock consumer acquire).


   // Shut down Argus.
   cameraProvider.reset();

   // Cleanup the EGL display
   PROPAGATE_ERROR(g_display.cleanup());

    return true;
}

}; // namespace ends here

int main(int argc, char** argv )
{
   if (!ArgusSamples::execute())
      return EXIT_FAILURE;
	
   return EXIT_SUCCESS;
}

Kindly let me know if this is the way to go about setting the camera mode to output 1080p directly. Is there a way to verify whether the change has reflected ?

Regards,
Atishay

Hi lamegeorge,

This setResolution is for EGLStreamProducer but not camera directly.

What kind of camera are you using? CSI or a usb camera?

Hi WayneWWW,

We are using Sony IMX274 CSI camera. Kindly let me know what ‘setSensorMode’ API does ? Is it sufficient to achieve what is intended using this API. If not then what can be done?

Thanks

Hi lamegeorge,

Your guess is correct. RequestImpl::setSensorMode would set a mode which is supported by your camera.

If it is IMX274, 1080p should be supported.

There is a sample for setSensorMode, please refer to /argus/samples/bayerAverageMap/main.cpp