×
Namespaces

Variants
Actions
(Difference between revisions)

Secondary camera in QML

From Nokia Developer Wiki
Jump to: navigation, search
xmlich02 (Talk | contribs)
(Xmlich02 -)
 
xmlich02 (Talk | contribs)
(Xmlich02 -)
Line 1: Line 1:
[[Category:Draft]]
+
[[Category:Draft]][[Category:Qt]][[Category:Qt Mobility]][[Category:Multimedia]][[Category:MeeGo]][[Category:Code Examples]][[Category:Code Snippet]]
 
{{Abstract|This article explains how to use the secondary camera in QML }}
 
{{Abstract|This article explains how to use the secondary camera in QML }}
 
''Enter article metadata as described below. Note that this template can be placed anywhere in the article. Do not remove parameters that you do not use''
 
''Enter article metadata as described below. Note that this template can be placed anywhere in the article. Do not remove parameters that you do not use''
 +
{{Note|This is an entry in the [[PureView Imaging Competition 2012Q2]]}}
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
+
|devices= N9
 
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
+
|platform= Qt 4.6 and later
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
+
|devicecompatability= must have secondary camera
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
+
|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= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
+
|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]] -->

Revision as of 17:45, 7 June 2012

This article explains how to use the secondary camera in QML Enter article metadata as described below. Note that this template can be placed anywhere in the article. Do not remove parameters that you do not use

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

Article Metadata
Tested 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: (18 Jun 2012)
Last edited: xmlich02 (07 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 [FIXME]

83 page views in the last 30 days.
×