QCameraImageCapture get QImage without saving



  • Hi all,
    I'm on N9.
    I can show camera in a viewfinder.

    Now I need to get a QImage from camera to manipulate it without saving a file in my phone.

    is It possible?





  • Thanks,
    I try to explain me better.
    In my application I need to get a QImage from phone camera.
    This is my code:
    @
    {
    ...
    ...
    m_camera = new QCamera("primary");
    m_camera->setViewfinder(ui->viewFinder);
    m_imageCapture = new QCameraImageCapture(m_camera);
    QImageEncoderSettings encoder_setting = m_imageCapture->encodingSettings();
    encoder_setting.setCodec("image/jpeg");
    encoder_setting.setQuality(QtMultimediaKit::NormalQuality);
    encoder_setting.setResolution(800,600);
    m_imageCapture->setEncodingSettings(encoder_setting);
    connect(m_imageCapture, SIGNAL(imageSaved(int,QString)), this, SLOT(processSavedImage(int,QString)));
    ...
    m_imageCapture->capture();
    ....
    }

    void MainWindow::processSavedImage(int requestId, QString str)
    {
    QImage my_image(str);
    ...
    }
    @

    This way I get a QImage reading it from phone memory while I'd like to get the QImage without saving to disk before.



  • I have the same problem using QML and Camera Element.

    When I call Camera.captureImage() it capture a jpg image and save it.

    Is there a way to avoid to save the image?
    If not, is there a way to specify a path of the saved image?



  • Hi, I had this problem a while ago. This is my fix:

    @void init_WebCam()
    {
    cam = new QCamera(0);
    connect(&captureTimer, SIGNAL(timeout()),
    this, SLOT (frameUpdated()));
    videoWidget = new QVideoWidget();
    videoWidget->setFixedSize(640,480);
    cam->setViewfinder(videoWidget);
    }

    void MainWindow::frameUpdated()
    {
    videoWidget->grab().toImage(); // this is your QImage
    }@

    Note that this is not QML, but c++ gui.



  • [quote author="puksec" date="1378901986"]Hi, I had this problem a while ago. This is my fix:[/quote]

    Thank you for sharing this solution but please wrap the source code with @ to make it easier for reading.



  • Hm "@". So that's how you all are doing it :). Thanks for the tip.



  • QCameraImageCapture::setCaptureDestination(QCameraImageCapture::CaptureToBuffer) is what you need.

    Then listen to the QCameraImageCapture::imageAvailable() signal to get notified whenever the buffer is available.
    You'll notice that what you get is a QVideoFrame, and you'll have to convert it to a QImage if that's what you need.



  • I agree that that would be the first choice, but I had a situation where QCameraImageCapture::CaptureToBuffer was not supported on my system (for some unknown reason).



  • Hi, I am having similar problem and I am quit new to qt programing.
    Do you have an example of how to use the CaputureToBuffer ?
    I do not know how to listen to QCameraImageCapture::imageAvailable() signal.
    Thanks.

    [quote author="Yoann Lopes" date="1383734227"]QCameraImageCapture::setCaptureDestination(QCameraImageCapture::CaptureToBuffer) is what you need.

    Then listen to the QCameraImageCapture::imageAvailable() signal to get notified whenever the buffer is available.
    You'll notice that what you get is a QVideoFrame, and you'll have to convert it to a QImage if that's what you need.[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.