×
Namespaces

Variants
Actions
(Difference between revisions)

Secondary camera in QML

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan")
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix ArticleMetaData)
Line 10: Line 10:
 
|devicecompatability= must have secondary camera
 
|devicecompatability= must have secondary camera
 
|dependencies= qt mobility
 
|dependencies= qt mobility
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
+
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|keywords= Camera, QML
 
|keywords= Camera, QML
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->  
+
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|creationdate= 20120607
 
|creationdate= 20120607
|author= [[User:xmlich02]]  
+
|author= [[User:xmlich02]]
 
}}
 
}}
  

Revision as of 03:30, 14 June 2012

This article explains how to use the secondary camera in QML

Note.pngNote: This is an entry in the PureView Imaging Competition 2012Q2

Article Metadata
Code ExampleTested with
Devices(s): N9
Compatibility
Platform(s): Qt 4.6 and later
Device(s): must have secondary camera
Dependencies: qt mobility
Article
Keywords: Camera, QML
Created: xmlich02 (07 Jun 2012)
Last edited: hamishwillee (14 Jun 2012)

Contents

Introduction

This article describes how to use the secondary camera in QML. The article [1] describes how to use the primary camera in various ways. However, access to the secondary camera is not available in QML.

Current solution

The secondary camera (i.e. frontal camera) is available though the C++ API. The registration of the component in QML is possible. However, this component does not provide the methods which are in the QML Camera component [2].

#include <QGraphicsVideoItem>
 
FrontCameraApp::FrontCameraApp(QDeclarativeItem *parent) : QDeclarativeItem(parent)
{
myViewfinder = new QGraphicsVideoItem(this);
QByteArray frontCamera = QCamera::availableDevices()[1];
myCamera = new QCamera(frontCamera);
 
myCamera->setViewfinder(myViewfinder);
myCamera->start();
}

The multimedia part from qt mobility has to be included in project.

CONFIG += mobility
MOBILITY += multimedia

Also, the FrontCameraApp object has to be registered for QML.

    qmlRegisterType<FrontCameraApp>("cz.vutbr.fit.pcmlich", 1, 0, "CameraFront");

The use in QML is as follows:

import com.nokia.meego 1.0
import cz.vutbr.fit.pcmlich 1.0
// import QtMultimediaKit 1.1
Page {
CameraFront {
anchors.fill: parent;
}
/*
// or primary camera
Camera {
anchors.fill: parent;
}
*/

}

Additional features

Since Qt mobility is open source, you can download the source codes from [3]. The implementation of the Camera element is in /plugins/declarative/multimedia/qdeclarativecamera.cpp. In order to use of this class in your own project it is necessary to modify its code to work with secondary camera as follows:

QDeclarativeCamera::QDeclarativeCamera(QDeclarativeItem *parent) :
QDeclarativeItem(parent),
m_camera(0),
m_viewfinderItem(0),
m_imageSettingsChanged(false),
m_pendingState(ActiveState),
m_isStateSet(false)
{
// m_camera = new QCamera(this); // remove this line
QByteArray frontCamera = QCamera::availableDevices()[1]; // add this line
m_Camera = new QCamera(frontCamera); // add this line
...
}

Next, it is necessary to add included private header files to your project.

#include "qdeclarativecamera_p.h"
#include "qdeclarativecamerapreviewprovider_p.h"

There could be a conflict in the class names QDeclarativeCamera and other problems, so it is recommended to perform refactoring of QDeclarativeCamera class. Finally, the modified class is registered into QML, as is described in the previous section.

Problems

The image from the secondary camera could be confusing to the user. Therefore it is appropriate to flip it.

        transform: Rotation { origin.x: frontcam.width/2; origin.y: frontcam.height/2; axis { x: 0; y: 1; z: 0 } angle: 180  }

The primary and secondary cameras cannot be opened at same time.

Summary

After these modifications, we have a QML component for the secondary camera which allows us modify white balance mode, exposure compensation, and other configuration of the secondary camera. It is also possible to capture images and monitor camera states. This solution is only a workaround, since the Qt Mobility is not providing a suitable interface for the secondary camera. All mentioned components are available in the attached file Media:SecondaryCameraInQml.tar.gz

121 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×