Главная » Просмотр файлов » Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008

Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008 (779888), страница 43

Файл №779888 Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008 (Symbian Books) 43 страницаWiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008 (779888) страница 432018-01-10СтудИзба
Просмтор этого файла доступен только зарегистрированным пользователям. Но у нас супер быстрая регистрация: достаточно только электронной почты!

Текст из файла (страница 43)

In the example below we will be using CCamera::StartViewFinderBitmapsL().The client application needs to inherit from the interface class MCameraObserver in order to actively interact with the camera API. Thismixin class provides five pure virtual functions that must be implemented:• void ReserveComplete(): handles the completion result fromcamera reservation• void PowerOnComplete(): indicates whether camera power-oncompleted successfully• void ViewFinderFrameReady(): receives the data from the camera viewfinder bitmap• void ImageReady(): handles the completion event raised by imagecapture• void FrameBufferReady(): handles the completion event raisedby video capture.Having discussed the basic set-up we can now proceed with our specific example.

In its header file, ColorTrackerView.h, the followingcan be seen:• inclusion of ecam.h for the camera APIs and FBS.h for bitmapmanipulation (also requires linking against fbscli.lib in theproject’s MMP file)• inheritance from MCameraObserver• declaration of the tracking function TrackColor()• declaration of the iCamera and iViewFinderBitmap membervariables (the latter is a bitmap holding individual frames from thecamera) and a Boolean member variable (iAllowDraw) to indicatethe availability of a camera frame from the viewfinder.#include <ecam.h>#include <FBS.h>// Camera API// Fonts and Bitmap APIclass CColorTrackerAppView : public CCoeControl, MCameraObserver184EXPLOITING THE PHONE HARDWARE{public:...

// Construction, destruction omitted for clarityprivate:// Inherited from MCameraObservervoid ReserveComplete(TInt);void PowerOnComplete(TInt);void ViewFinderFrameReady(CFbsBitmap&);void ImageReady(CFbsBitmap*, HBufC8*, TInt);void FrameBufferReady(MFrameBuffer*, TInt);// The function to track colors in our example// @arg1: The color to track// @arg2: Reference to the application's graphics contextvoid TrackColor(TRgb&, CWindowGc&);private:CCamera* iCamera;CFbsBitmap* iViewFinderBitmap;TBool iAllowDraw;};On instantiation, as part of the second phase construction of a CColorTrackerAppView object, the ConstructL() method constructs theiCamera object and reserves it, and constructs the viewfinder bitmapiViewFinderBitmap.void CColorTrackerAppView::ConstructL(const TRect& aRect){...// Omitted for clarity// Instantiate iCamera:// arg1: reference to the inherited MCameraObserver interface// arg2: the index of the device camera to use - 0 for the// back camera.iCamera = CCamera::NewL(*this, 0);// Check if there is a cameraif( iCamera->CamerasAvailable() > 0 ){iCamera->Reserve();// Construct the bitmap to hold the frames captured by the cameraiViewFinder = new(ELeave) CFbsBitmap();}else{User::Leave(KErrNotFound);}}As we previously discussed CCamera::Reserve(), CCamera::PowerOn(), and CCamera::StartViewFinderBitmapsL() are allasynchronous functions, and each must only be called when the preceding function in the sequence has completed, because dependencies exist.For example, StartViewFinderBitmapsL() is dependent on thecompletion of PowerOn(), which is itself dependent on the completionCAMERA185of Reserve().

If StartViewFinderBitmapsL() is called before thePowerOn() method completes, it will panic the application.To manage this sequence of calls, we implement the callback functionsof the iMCameraObserver to provide the framework to monitor thecompletion of each camera operation. Therefore, we add the followingfunction implementations to ColorTrackerView.cpp.void CColorTrackerAppView::ReserveComplete(TInt aErr){// Check the camera is reserved successfully// Error handling is omitted for clarifyif( aErr==KErrNone)// Turn the camera oniCamera->PowerOn(); // Asynchronous completion}void CColorTrackerAppView::PowerOnComplete(TInt aErr){if (aErr==KErrNone){// Set the size of the rectangle on screen to use// for the view finderTSize size(240,180);// Start capturing frames – asynchronous completionTRAPD( result, iCamera->StartViewFinderBitmapsL(size) );if( result != KErrNone){// Error handling omitted for clarity}}}void CColorTrackerAppView::ViewFinderFrameReady(CFbsBitmap& aFrame){// There is one frame ready to display,iAllowDraw = ETrue;// duplicate it,iViewFinder->Duplicate(aFrame.Handle());// and render it on screen.DrawNow();}void CColorTrackerAppView::ImageReady(CFbsBitmap*, HBufC8*, TInt){// No need for implementation.}void CColorTrackerAppView::FrameBufferReady(MFrameBuffer*, TInt){// No need for implementation.}void CColorTrackerAppView::Draw(const TRect& aRect) const{...// Omitted for clarity// Allow bitmap drawing and manipulationif(iAllowDraw){// The color to track (red)TRgb colorToTrack(255,0,0);// Draw the frame on screen186EXPLOITING THE PHONE HARDWAREgc.BitBlt(TPoint(0,0), iViewFinder);// Track the red colorTrackColor(colorToTrack, gc);}}When the camera reservation is finished, an event is raised that resultsin a call to MCameraObserver::ReserveComplete() to notify it ofcompletion.

On checking that there is no error passed as a parameter to thecallback function, to confirm that reserving the camera was successful,PowerOn() is called from within the handler function, which startspowering up the camera asynchronously. If this completes successfullywe call StartViewFinderBitmapsL() from PowerOnComplete(),which starts loading the frames from the camera viewfinder.When the first bitmap frame is ready, the MCameraObserver::ViewFinderFrameReady() observer function is called by the framework, passing as a parameter that frame (aFrame), allowing it to becopied, or duplicated, into iViewFinderBitmap for later manipulation. The method sets iAllowDraw to ETrue to indicate that it ispossible now to start drawing bitmap frames to the screen as there is atleast one that has been successfully loaded.

DrawNow() in ViewFinderFrameReady() calls Draw() to perform the on-screen drawing.You should not call Draw() directly as there are several steps WSERVtakes before and after a call to Draw() which DrawNow() deals withinternally.The previous code illustrates the use of the camera on any Symbian OSsmartphone. To complete this example, the following function performsthe actual tracking of a color, red in our example. The function is calledfrom within Draw(), which will draw white squares on the screen inplace of the red pixels. Note that this is a very simple color trackingalgorithm, and we acknowledge that there are more sophisticated andaccurate solutions available.TrackColor() identifies a threshold for the color to track in aspherical shape surrounding it.

The function calculates the distancebetween the color to track, represented as the centre of the sphere, andthe color of an arbitrary pixel on screen in the RGB (0 ≤ R, G andB ≤ 255) space, as shown in Figure 6.5. Point C represents the centre ofthe color threshold. R is the radius of the sphere and r is the distancebetween B (which falls within the boundary) and C. Apparently point Ais outside the sphere boundary making L much beyond the length of R,and thus A is not considered for detection.If the distance between the color of an arbitrary screen pixel and thecolor to track (in the RGB space) is less than the predefined radius of thesurrounding sphere, 125 in our example, then the two colors match, andthat pixel is replaced with white.

Otherwise, the color is not recognizedCAMERA187GreenRCrBLBlueARedFigure 6.5 Spherical boundary color detectionand the functions continue checking other pixels. The following codeimplements this detection method.void CColorTrackerAppView::TrackColor(TRgb& aColor, CWindowGc& aGc){// Set the color of the dots to drawaGc.SetBrushColor( KRgbWhite );TUint r, g, b, distance;TRgb pixelColor;// Traversing the 240×180 viewfinder bitmap capturedfor(TUint x=0; x<240; x+=2){for(TUint y=0; y<180; y+=2){iViewFinder->GetPixel(pixelColor,TPoint(x,y));r = pixelColor.Red();g = pixelColor.Green();b = pixelColor.Blue();// Calculating the threshold as a sphere radius.

Характеристики

Тип файла
PDF-файл
Размер
2,71 Mb
Материал
Тип материала
Высшее учебное заведение

Список файлов книги

Свежие статьи
Популярно сейчас
Почему делать на заказ в разы дороже, чем купить готовую учебную работу на СтудИзбе? Наши учебные работы продаются каждый год, тогда как большинство заказов выполняются с нуля. Найдите подходящий учебный материал на СтудИзбе!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
6430
Авторов
на СтудИзбе
307
Средний доход
с одного платного файла
Обучение Подробнее