examples/Multimedia/ICL/ICLExample/iclpanoramaexample.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // The code demonstrates panorama stitching functionality of CIclExample
00015 //
00016 
00017 
00018 
00023 #include "iclexample.h"
00024 #include <panorama/panorama.h>
00025 
00026 void CIclExample::BasicPanoramaStitchingL()
00027         {
00028         TSize imageSize(1200, 1000);
00029         
00030         TDirection direction = EPanoramaDirectionRight;
00031                 
00032         //Lens parameters or internal camera characteristics should be available for the 
00033         //specific camera module in use. Here we use default values.
00034         TPanoramaLens lens;
00035                 
00036         //Create transform. A transform is an approximate offset between each image.
00037         CPanoramaTransform* panTrans = CPanoramaTransform::NewL();
00038         CleanupStack::PushL(panTrans);
00039         
00040         //Create panorama object.This stitches the individual images together.
00041         CImagePanorama* panImage = CImagePanorama::NewL();
00042         CleanupStack::PushL(panImage);
00043                 
00044         //Create panorama engine and set the lens and size
00045         panImage->InitializeL(imageSize, lens, direction);
00046                 
00047         //Each file added is provided with an approximate translation. 
00048         //In this case there are 4 images.
00049         panTrans->SetTranslationL(TPoint(0, 0), imageSize);
00050         panImage->AddFileL(KTestFileName1, *panTrans);
00051                 
00052         panTrans->SetTranslationL(TPoint(900, -30), imageSize);
00053         panImage->AddFileL(KTestFileName2, *panTrans);
00054                 
00055         panTrans->SetTranslationL(TPoint(900, 60), imageSize);
00056         panImage->AddFileL(KTestFileName3, *panTrans);
00057         
00058         panTrans->SetTranslationL(TPoint(400, -30), imageSize);
00059         panImage->AddFileL(KTestFileName4, *panTrans);
00060                 
00061         //The image size can be obtained before rendering (if required)
00062         TSize size;
00063         panImage->CurrentImageSizeL(size);
00064         
00065         //view the output image
00066         panImage->RenderL(KTestBSOutputFileName);
00067 
00068         CleanupStack::PopAndDestroy(2); //panTrans, panImage
00069         }
00070         
00071 void CIclExample::ViewFinderImageTrackingL()
00072         {
00073         _LIT(KFileOutput, "c:\\ICLExample\\viewfinder%d.mbm");
00074         _LIT(KFileCapturedImage, "c:\\ICLExample\\pancapture%d.jpg");
00075         TInt i = 0;
00076 
00077         TSize imageSize(1200,1000);
00078 
00079     CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
00080         CleanupStack::PushL(bmp);
00081 
00082         // get 1st viewfinder image from camera into bmp (detail excluded)
00083         
00084         // ####Begin exclude from OS Library example  
00085         // (for example purposes we have some prepared viewfinder images on disk)
00086         TFileName vfFileName;
00087     vfFileName.Format(KFileOutput(),i);
00088     User::LeaveIfError(bmp->Load(vfFileName));
00089         // ####End exclude from OS Library example  
00090 
00091         TSize bmpSize = bmp->SizeInPixels();
00092 
00093         CPanoramaTransform* panTrans = CPanoramaTransform::NewL();//create panorama transform
00094         CleanupStack::PushL(panTrans);
00095 
00096         CVFTracker* vfTracker = CVFTracker::NewL(); //create VFTracker and load the plugin
00097         CleanupStack::PushL(vfTracker);
00098                 
00099         vfTracker->InitializeL(bmpSize); //Create VFTracker and set size
00100 
00101         CImagePanorama* panImage = CImagePanorama::NewL(); //create CImagePanorama object
00102         CleanupStack::PushL(panImage);
00103                 
00104         TDirection direction = EPanoramaDirectionRight; //assign direction
00105                 
00106         // Lens parameters or internal camera characteristics should be available for the 
00107         // specific camera module in use. Here we use default values.
00108         TPanoramaLens lens;
00109         panImage->InitializeL(imageSize, lens, direction); //initialise size, lens, direction and create panorama engine
00110 
00111         // get the first captured image from the camera as a starting point - its name is given in capturedFileName
00112         TFileName capturedFileName;
00113     capturedFileName.Format(KFileCapturedImage(),i);
00114         panImage->AddFileL(capturedFileName, *panTrans); //add the captured image
00115 
00116         do 
00117                 {
00118                 // give the next camera viewfinder image to the tracker (details ommitted)
00119                 vfTracker->RegisterImageL(*bmp, *panTrans); // register viewfinder image
00120                 
00121                 // check if we have a good overlap with the previous image
00122                 if(vfTracker->IsTimeToCapture(direction, KPanoramaDefaultOverlap)) 
00123                         {
00124                         // capture the next image from the camera (details ommitted)
00125                     capturedFileName.Format(KFileCapturedImage(),i);
00126                         
00127                         panImage->AddFileL(capturedFileName, *panTrans); //add the captured image
00128                         vfTracker->Reset(); //reset the VFTracker object
00129                         }
00130         
00131                 // ####Begin exclude from OS Library example  
00132                 // For example purposes we have some prepared viewfinder images on disk.
00133                 i += 10;        
00134                 vfFileName.Format(KFileOutput(),i);
00135             TInt err = bmp->Load(vfFileName);
00136                 // ####End exclude from OS Library example  
00137                 
00138                 if ( err != KErrNone )  // some termination condition usually a signal from user
00139                         {
00140                         // no more viewfinder images
00141                         break;
00142                         }
00143                 }
00144         while (1);  
00145                 
00146         panImage->RenderL(KTestVFTOutputFileName); // render the stitched image
00147         
00148         CleanupStack::PopAndDestroy(4,bmp); //panTrans, vfTracker, panImage, bmp
00149         }
00150 

Generated on Thu Jan 21 10:32:59 2010 for TB10.1 Example Applications by  doxygen 1.5.3