×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Red face Implementing camera example in my applicaton but not working

    Hi all,

    I tried the QQrdecoder example by nokia, implemented it without the decoding features on N8. it has a Qcameracontroller class which has a function named MCeocameraready which is responsible for initialising the view finder. i tried the example and its working fine. but the same thing is not working when i tried to integrate it with my applicaiton. somehow, the mceocameraready function is not getting called.. i dunno wat went wrong. MCeocameraready is called thru, i guess, internal functions.

    Any help with the same would be appreciated.

    Thanks,

    Ulhas

  2. #2
    Regular Contributor
    Join Date
    Oct 2008
    Location
    Oslo, Norway
    Posts
    329

    Re: Implementing camera example in my applicaton but not working

    Hi,

    Seeing some actual code would help here, I guess. If the example compiles and works, try to see what's different compared to your code. Does your app have UserEnvironment capability?

    Note that there is an updated version of the camerawrapper available here - one that builds as a static library so you don't need to deploy embedded sisx package anymore with your application. It also has a number of bugs fixed.

    Or, you could think further ahead and start using QCamera from Qt Mobility.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Re: Implementing camera example in my applicaton but not working

    we r using 4.6 and the capability is set to user enivronment and mobility is set to multimedia in the .pro file.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Re: Implementing camera example in my applicaton but not working

    void MExpITAppController::showCaptureReceiptDlg()
    {
    QQrDecoder* w = new QQrDecoder();
    w->showFullScreen();
    w->raise();
    }



    QQrdecoder.cpp

    #include "QQrDecoder.h"
    //#include <zxing/qrcode/QRCodeReader.h>
    #include <zxing/MultiFormatReader.h>

    #include <QFileDialog>
    #include <QGraphicsView>
    #include <QPainter>
    #include <QPoint>
    #include <QPixmap>


    QQrDecoder::QQrDecoder(QWidget *parent): QMainWindow(parent)
    {
    ui.setupUi(this);
    connect(ui.startDecode, SIGNAL(clicked()), this, SLOT(findAndSave()));
    connect(ui.cameraWidget, SIGNAL(imageCaptured(QImage)), this, SLOT(saveImage(QImage)));
    connect(ui.cameraWidget, SIGNAL(logMessage(QString)), ui.resultLabel, SLOT(setText(QString)));
    }

    QQrDecoder::~QQrDecoder()
    {
    }

    void QQrDecoder::InitializeSymbianCamera()
    {

    }

    void QQrDecoder::findAndSave()
    {
    ui.cameraWidget->CaptureImage();
    }

    void QQrDecoder::saveImage(QImage originalImage)
    {
    QString path("E:\\Images\\Receipt_Images\\");
    QDir dir(path);

    // Get next filename
    QStringList files = dir.entryList(QStringList() << "receipt_*.png");
    int lastImage = 0;
    foreach( QString fileName, files )
    {
    int imgNumber = fileName.mid(7, fileName.size() - 11).toInt();
    lastImage = qMax(lastImage, imgNumber);
    }


    originalImage.save(QString(path).append("receipt_%1.png").arg(lastImage+1));

    }


    QCameraController

    #include "QCameraControllerWidget.h"
    #include <QPainter>
    #include <QMessageBox>

    QCameraControllerWidget::QCameraControllerWidget(QWidget* parent) : QWidget(parent),
    iCameraWrapper(NULL), iBackBuffer(NULL), iBackBufferDevice(NULL), iBackBufferContext(NULL)
    {
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(sendBackbufferToDecode()));
    timer->start(500);
    }

    QCameraControllerWidget::~QCameraControllerWidget()
    {
    if (iCameraWrapper)
    {
    iCameraWrapper->ReleaseAndPowerOff();
    }

    delete iCameraWrapper;

    if(timer)
    {
    delete timer;
    timer = NULL;
    }

    ReleaseBackBuffer();
    }

    void QCameraControllerWidget::CaptureImage()
    {
    if (iCameraWrapper && iCameraWrapper->State() == CCameraEngine::EEngineViewFinding)
    {
    emit logMessage("Capturing picture");
    iCameraWrapper->StopViewFinder();
    TRAPD(err,iCameraWrapper->CaptureL());
    if (err)
    {
    emit logMessage("Camera capture error");
    }
    }
    }

    void QCameraControllerWidget:aintEvent(QPaintEvent* event)
    {
    if(iBackBuffer)
    {
    QPainter paint(this);
    paint.drawPixmap(0,0,QPixmap::fromSymbianCFbsBitmap(iBackBuffer));
    }
    }

    void QCameraControllerWidget::resizeEvent(QResizeEvent* event)
    {
    static int savedWidth = 0;
    static int savedHeight = 0;

    if(!savedWidth || !savedHeight)
    {
    InitializeCamera();
    savedWidth = geometry().width();
    savedHeight = geometry().height();
    }
    }

    void QCameraControllerWidget::InitializeCamera()
    {
    // Create camera wrapper class here because
    // whole camera wrapper and all handles have to reset
    // while orientatio of the application changes.
    if (iCameraWrapper)
    {
    // Power off camera if it is on
    iCameraWrapper->StopViewFinder();
    iCameraWrapper->ReleaseAndPowerOff();
    delete iCameraWrapper; iCameraWrapper = NULL;
    }
    TInt camErr(KErrNotSupported);
    if(CCameraEngine::CamerasAvailable() > 0)
    {
    TRAP(camErr, iCameraWrapper = CCameraEngine::NewL(0,0,this));
    }

    // iViewFinderSize is picture size for viewfinder.
    // iCaptureSize is picture size for capturing picture.
    // We want fill whole screen
    if (geometry().width() > geometry().height())
    {
    iViewFinderSize = TSize(geometry().width(),geometry().width());
    iCaptureSize = TSize(geometry().width(),geometry().width()); // Captured picture size
    }
    else
    {
    iViewFinderSize = TSize(geometry().height(), geometry().height());
    iCaptureSize = TSize(geometry().height(),geometry().height()); // Captured picture size
    }

    ReleaseBackBuffer();
    CreateBackBufferL();

    if(camErr == KErrNone)
    {
    iCameraWrapper->ReserveAndPowerOn();
    emit logMessage("Camera power on");
    }
    else
    {
    emit logMessage("no camera found");
    }
    }

    void QCameraControllerWidget::CreateBackBufferL()
    {
    // create back buffer bitmap
    iBackBuffer = q_check_ptr(new CFbsBitmap);

    try{
    TSize size;
    size.iHeight = this->geometry().height();
    size.iWidth = this->geometry().width();
    QT_TRAP_THROWING( iBackBuffer->Create(size,EColor64K));
    }
    catch(std::exception& e)
    {

    }

    iBackBufferDevice = CFbsBitmapDevice::NewL(iBackBuffer);
    User::LeaveIfError(iBackBufferDevice->CreateContext(iBackBufferContext));
    iBackBufferContext->SetPenStyle(CGraphicsContext::ESolidPen);

    iBackBufferContext->SetBrushColor(KRgbBlack);
    iBackBufferContext->Clear();
    }

    void QCameraControllerWidget::ReleaseBackBuffer()
    {
    if (iBackBufferContext)
    {
    delete iBackBufferContext;
    iBackBufferContext = NULL;
    }
    if (iBackBufferDevice)
    {
    delete iBackBufferDevice;
    iBackBufferDevice = NULL;
    }
    if (iBackBuffer)
    {
    delete iBackBuffer;
    iBackBuffer = NULL;
    }
    }

    void QCameraControllerWidget::MceoCameraReady()
    {
    emit logMessage("inside mceocameraready");
    if (iCameraWrapper->State() == CCameraEngine::EEngineIdle)
    {
    emit logMessage("inside if iCameraWrapper->State() = idle");
    TSize imageSize;
    imageSize.iHeight = 480;
    imageSize.iWidth = 640;

    CCamera::TFormat format = CCamera::EFormatFbsBitmapColor64K;

    TRAPD(err,iCameraWrapper->PrepareL(imageSize, format));
    if (err)
    {
    emit logMessage("Camera prepare error");
    return;
    }


    emit logMessage("IF NOT - > CAMERA PREPARE ERROR");
    TSize finderSize;
    finderSize.iHeight = this->geometry().height();
    finderSize.iWidth = this->geometry().width();
    TRAPD(err2,iCameraWrapper->StartViewFinderL(finderSize));
    if (err2)
    {
    emit logMessage("Camera start viewfinder error");
    return;
    }

    emit logMessage("Camera viewfinder started");
    }
    }

    void QCameraControllerWidget::MceoFocusComplete()
    {
    // CameraEngine state is EEngineIdle
    emit logMessage("Focused");

    // Capture picture after it has focused
    iCameraWrapper->StopViewFinder();
    TRAPD(err,iCameraWrapper->CaptureL());
    if (err)
    {
    emit logMessage("Camera capture error");
    }
    }

    void QCameraControllerWidget::MceoCapturedDataReady( TDesC8* aData )
    {

    }

    void QCameraControllerWidget::MceoCapturedBitmapReady( CFbsBitmap* aBitmap )
    {
    if (iBackBufferContext)
    {
    emit logMessage("Succesfull capture");

    QPixmap pix(QPixmap::fromSymbianCFbsBitmap(aBitmap));
    emit imageCaptured(pix.toImage());

    TSize finderSize;
    finderSize.iHeight = this->geometry().height();
    finderSize.iWidth = this->geometry().width();
    TRAPD(err2,iCameraWrapper->StartViewFinderL(finderSize));
    if (err2)
    {
    emit logMessage("Camera start viewfinder error");
    return;
    }
    }
    if (iCameraWrapper)
    iCameraWrapper->ReleaseImageBuffer();
    }

    void QCameraControllerWidget::MceoViewFinderFrameReady( CFbsBitmap& aFrame )
    {
    if (iBackBufferContext)
    {
    TSize bmpSizeInPixels = aFrame.SizeInPixels();
    TInt xDelta = 0;
    TInt yDelta = 0;
    TPoint pos( xDelta, yDelta );

    // Copy received viewfinder picture to back buffer
    iBackBufferContext->BitBlt( pos, &aFrame, TRect( TPoint( 0, 0 ), bmpSizeInPixels ));

    // Update backbuffer into screen
    update();
    }
    if (iCameraWrapper)
    iCameraWrapper->ReleaseViewFinderBuffer();
    }

    void QCameraControllerWidget::MceoHandleError( TCameraEngineError aErrorType, TInt aError )
    {

    if (aErrorType == EErrReserve)
    {
    return; //-18 comes on application startup, but everything works ok
    }

    switch (aErrorType)
    {
    case EErrReserve:
    {
    emit logMessage("Camera reserved error");
    break;
    }
    case EErrPowerOn:
    {
    emit logMessage("Camera power on error");
    break;
    }
    case EErrViewFinderReady:
    {
    emit logMessage("Camera viewfinder error");
    break;
    }
    case EErrImageReady:
    {
    emit logMessage("Camera image ready error");
    break;
    }
    case EErrAutoFocusInit:
    case EErrAutoFocusMode:
    case EErrAutoFocusArea:
    case EErrAutoFocusRange:
    case EErrAutoFocusType:
    case EErrOptimisedFocusComplete:
    {
    //emit logMessage("Try focusing again");
    break;
    }
    default:
    {
    emit logMessage("Unknown error");
    break;
    }
    };

    }

    void QCameraControllerWidget::MceoHandleOtherEvent( const TECAMEvent& /*aEvent*/ )
    {
    }

    //Timer slot
    void QCameraControllerWidget::sendBackbufferToDecode()
    {
    if(!iBackBuffer)
    return;

    QPixmap pix(QPixmap::fromSymbianCFbsBitmap(iBackBuffer));
    emit imageCaptured(pix.toImage());

    if(timer)
    timer->start(500);
    }


    the mceocameraready() function in the QCameraController class is not getting invoked.... can anyone tell me the reason for the same...

    any help would be very grateful..

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Implementing camera example in my applicaton but not working

    I don't know if this is a cut-and-paste from the original example but it looks very suspicious:
    void QCameraControllerWidget::MceoHandleError( TCameraEngineError aErrorType, TInt aError )
    {

    if (aErrorType == EErrReserve)
    {
    return; //-18 comes on application startup, but everything works ok
    }

    switch (aErrorType)
    {
    case EErrReserve:
    {
    emit logMessage("Camera reserved error");
    break;
    }
    ...
    You'll never see a Camera reserved error because you deliberately ignore them. -18 is KErrNotReady which suggests things called out of order or without waiting for appropriate callbacks.

    Have you made sure the intialize function is getting called and debugged with a breakpoint in the error handling stuff?

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Re: Implementing camera example in my applicaton but not working

    Hi All,

    I have tried implementing the QQrDecoder example in my application. The camera works fine after integration. But when I close the QQrDecoder window and try to launch it again, MceoCameraReady(...) event is not thrown or captured. The camera gets "power on" but viewfinder is not initialized.

    Please let us know any valuable comments.

    -Ulhas

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Re: Implementing camera example in my applicaton but not working

    Hi,
    Where is the static library...it is not there in the link that u hv provided?

Similar Threads

  1. Camera example (camerawrapper) not working on E55
    By markus_sunela in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2010-08-03, 09:12
  2. Implementing the example code
    By gurubai in forum Symbian
    Replies: 19
    Last Post: 2010-07-02, 17:27
  3. Implementing Example
    By Priya23 in forum Symbian
    Replies: 2
    Last Post: 2009-08-07, 17:28
  4. Implementing camera in a Ui Form
    By etranger in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2007-11-25, 07:13
  5. Camera example not working on real phone
    By esanchis in forum Symbian
    Replies: 1
    Last Post: 2003-02-13, 13:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×