<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Symbian 攝像頭編程預(yù)研

          Symbian 攝像頭編程預(yù)研

          作者: 時(shí)間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

          預(yù)研

          本文引用地址:http://www.ex-cimer.com/article/201610/305989.htm

          目前使用,網(wǎng)上用的最多的都是直接調(diào)用手機(jī)自帶的照相/攝像程序來完成,不過使用這種方式,可控性就顯得弱一些,為此近期對(duì)直接使用ECAM API進(jìn)行了下簡(jiǎn)單預(yù)研。

          照相流程

          因?yàn)楸敬晤A(yù)研主要還是偏重照相功能。整個(gè)照相過程,假設(shè)使用文字說明可能會(huì)顯得相對(duì)繁瑣,為此結(jié)合ECAM API對(duì)照相功能進(jìn)行了順序流程圖描繪,具體如下

          該過程主要涉及到的觀察器類就是MCameraObserver,該類和CCamera均在ecam.h頭文件中被定義,以下是該觀察器接口類的聲明

          class MCameraObserver

          {

          public:

          //CCamera::Reserve異步函數(shù)的回調(diào)通知

          virtual void ReserveComplete(TInt aError)=0;

          //CCamera::PowerOn異步函數(shù)的回調(diào)通知

          virtual void PowerOnComplete(TInt aError)=0;

          //假如取景器模式為位圖模式時(shí)預(yù)覽位圖的回調(diào)通知

          virtual void ViewFinderFrameReady(CFbsBitmap aFrame)=0;

          //CCamera::CaptureImage異步函數(shù)的回調(diào)通知

          virtual void ImageReady(CFbsBitmap* aBitmap,HBufC8* aData,TInt aError)=0;

          //CCamera::StartVideoCapture異步函數(shù)的回調(diào)通知

          virtual void FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)=0;

          };

          在這里需要說明下的,恐怕就是取景器了,因?yàn)榧僭O(shè)不是數(shù)碼達(dá)人或者第一次接觸攝像頭類編程,這個(gè)概念還是比較新的。其實(shí)所謂取景器,可以理解為預(yù)覽擬拍攝景物的視窗,CCamera支持兩種顯示取景器的方法:一種是直接屏幕訪問模式,即應(yīng)用程序只要指明在屏幕上的哪個(gè)區(qū)域顯示圖像,攝像頭對(duì)象就會(huì)把當(dāng)前取到的圖像直接繪制到這個(gè)區(qū)域上(可以說過程不用程序干預(yù)的);另外一種是位圖模式,即攝像頭對(duì)象提供一系列的位圖,由應(yīng)用程序把位圖繪制到窗口上。

          一般在設(shè)置之前需要先獲取一下攝像頭參數(shù),看看其是否支持所要設(shè)置的模式。EViewFinderDirectSuported就是支持直接屏幕訪問模式,EViewFinderBitmapsSupported就是位圖模式。通常情況下,假如兩種模式都支持的情況下,選用直接屏幕訪問模式,因?yàn)檫@種模式比較快而且不用程序代碼干預(yù),否則就用位圖模式,位圖模式時(shí),當(dāng)捕捉到圖像后會(huì)調(diào)用觀察器的ViewFinderFrameReady()函數(shù)將圖像傳給觀察器進(jìn)行繪制。

          關(guān)于CameraInfo

          攝像頭本身有屬性信息,我們可以通過調(diào)用CCamera:: CameraInfo(TCameraInfo aInfo)函數(shù)獲取。對(duì)N81手機(jī)主攝像頭進(jìn)行缺省參數(shù)的提取,具體參數(shù)如下圖所示

          對(duì)各自參數(shù)的分析如下

          iHardwareVersion

          相機(jī)硬件的版本號(hào),該值不用細(xì)究,是OEM關(guān)心的

          iSoftwareVersion

          相機(jī)軟件的版本號(hào)(驅(qū)動(dòng)程序版本號(hào)),該值也是OEM關(guān)心

          iOrientation

          相機(jī)的朝向,該值是OEM出廠時(shí)根據(jù)相機(jī)特性設(shè)定的,編程無法修改,不過可以給我們編程提供參考條件,其取值有如下幾種類型

          /** Possible directions in which the camera may point.

          */

          enum TCameraOrientation

          {

          /** Outward pointing camera for taking pictures.

          Camera is directed away from the user. */

          EOrientationOutwards,

          /** Inward pointing camera for conferencing.

          Camera is directed towards the user. */

          EOrientationInwards,

          /** Mobile camera capable of multiple orientations.

          Camera orientation may be changed by the user. */

          EOrientationMobile,

          /** Camera orientation is not known. */

          EOrientationUnknown

          };

          根據(jù)取得的值的情況,N81的主攝像頭朝向?yàn)镋OrientationOutwards,當(dāng)然通過對(duì)N81和E71主次攝像頭信息數(shù)據(jù)的采集,可知類似N81、E71等雙攝像頭手機(jī)的主攝像頭屬性都是EOrientationOutwards的,而前面次攝像頭屬性都EOrientationInwards。從而猜測(cè)像N93i這樣的手機(jī)其攝像頭朝向?qū)傩詰?yīng)該為EOrientationMobile(因?yàn)槭遣聹y(cè),所有還期待有人幫忙驗(yàn)證一下)。根據(jù)這個(gè)屬性,對(duì)于雙攝像頭手機(jī),我們可以編程選中需要使用的攝像頭。

          iOptionsSupported

          同樣也是一些無法修改的屬性,表明了此攝像頭支持的功能,因?yàn)樵撝凳莻€(gè)位域的值,通常使用過程中要用位與操作來判斷其是否支持某一種屬性,具體如下羅列的枚舉值

          enum TOptions

          {

          /** View finder display direct-to-screen flag */

          EViewFinderDirectSupported = 0x0001,

          /** View finder bitmap generation flag */

          EViewFinderBitmapsSupported = 0x0002,

          /** Still image capture flag */

          EImageCaptureSupported = 0x0004,

          /** Video capture flag */

          EVideoCaptureSupported = 0x0008,

          /** View finder display mirroring flag */

          EViewFinderMirrorSupported = 0x0010,

          /** Contrast setting flag */

          EContrastSupported = 0x0020,

          /** Brightness setting flag */

          EBrightnessSupported = 0x0040,

          /** View finder clipping flag */

          EViewFinderClippingSupported = 0x0080,

          /** Still image capture clipping flag */

          EImageClippingSupported = 0x0100,

          /** Video capture clipping flag */

          EVideoClippingSupported = 0x0200

          };

          我的英文比較差,就不一一翻譯了,畢竟有些EviewFinderMirrorSupported、EviewFinderClippingSupported、EimageClippingSupported、EvideoClippingSupported我也不知道是啥具體用的。我們只需要關(guān)心這個(gè)手機(jī)的攝像頭支持何種模式的取景器,支不支持拍照(EImageCaptureSupported)、支不支持錄像(EVideoCaptureSupported)、支不支持對(duì)比度設(shè)置(EcontrastSupported)和亮度設(shè)置(EBrightnessSupported)就可以了。

          因?yàn)镹81主攝像頭的iOptionsSupporte值是14(即1110)所以該主攝像頭只支持位圖模式的取景器設(shè)置,同時(shí)支持圖像和視頻的拍攝,不支持對(duì)比度亮度等設(shè)置。

          iFlashModesSupported

          閃光燈支持模式,具體的模式可以參見如下枚舉值

          enum TFlash

          {

          /** No flash, always supported. */

          EFlashNone = 0x0000,

          /** Flash will automatically fire when required. */

          EFlashAuto = 0x0001,

          /** Flash will always fire. */

          EFlashForced = 0x0002,

          /** Reduced flash for general lighting */

          EFlashFillIn = 0x0004,

          /** Red-eye reduction mode. */

          EFlashRedEyeReduce = 0x0008,

          /** Flash at the moment when shutter opens.快門開時(shí)閃 */

          EFlashSlowFrontSync = 0x0010,

          /** Flash at the moment when shutter closes. 快門關(guān)事閃*/

          EFlashSlowRearSync = 0x0020,

          /** User configurable setting */

          EFlashManual = 0x0040

          };

          這里就不做贅述了,N81的值11(即1011),支持自動(dòng)、總是打開和紅眼消除,當(dāng)然總是關(guān)閉肯定是支持的。

          知道了支持何種類型,我們就可以對(duì)攝像頭的閃光燈類型通過CCamera::Flash和CCamera::SetFlashL兩個(gè)函數(shù)獲取和設(shè)置。

          iExposureModesSupported

          曝光支持模式,具體的模式詳見如下枚舉值

          /** Specifies the type of exposure. - EExposureAuto is the default value. */

          enum TExposure

          {

          /** Set exposure automatically. Default, always supported. */

          EExposureAuto = 0x0000,

          /** Night-time setting for long exposures. */

          EExposureNight = 0x0001,

          /** Backlight setting for bright backgrounds. */

          EExposureBacklight = 0x0002,

          /** Centered mode for ignoring surroundings. */

          EExposureCenter = 0x0004,

          /** Sport setting for very short exposures. */

          EExposureSport = 0x0008,

          /** Generalised setting for very long exposures. */

          EExposureVeryLong = 0x0010,

          /** Snow setting for daylight exposure. */

          EExposureSnow = 0x0020,

          /** Beach setting for daylight exposure with reflective glare. */

          EExposureBeach = 0x0040,

          /** Programmed exposure setting. */

          EExposureProgram = 0x0080,

          /** Aperture setting is given priority. */

          EExposureAperturePriority = 0x0100,

          /** Shutter speed setting is given priority. */

          EExposureShutterPriority = 0x0200,

          /** User selectable exposure value setting. */

          EExposureManual = 0x0400,

          /** Exposure night setting with colour removed to get rid of colour noise. */

          EExposureSuperNight = 0x0800,

          /** Exposure for infra-red sensor on the camera */

          EExposureInfra = 0x1000

          };

          獲取N81的相機(jī)曝光支持模式為7(即0111),所以只支持自動(dòng)、夜晚、背光和中間四種模式。

          我們可以通過CCamera::Exposure()和CCamera::SetExposureL兩個(gè)函數(shù)對(duì)攝像頭的曝光模式進(jìn)行獲取和設(shè)置。

          iWhiteBalanceModesSupported

          白平衡支持模式,白平衡具體的模式如下

          /** Specifies how the white balance is set. */

          enum TWhiteBalance

          {

          /** Set white balance automatically. Default, always supported. */

          EWBAuto = 0x0000,

          /** Normal daylight. */

          EWBDaylight = 0x0001,

          /** Overcast daylight. */

          EWBCloudy = 0x0002,

          /** Tungsten filament lighting. */

          EWBTungsten = 0x0004,

          /** Fluorescent tube lighting */

          EWBFluorescent = 0x0008,

          /** Flash lighting. */

          EWBFlash = 0x0010,

          /** High contrast daylight primarily snowy */

          EWBSnow = 0x0020,

          /** High contrast daylight primarily near the sea */

          EWBBeach = 0x0040,

          /** User configurable mode */

          EWBManual = 0x0080

          };

          具體不做展開,可以通過調(diào)用CCamera::WhiteBalance和CCamera::SetWhiteBalanceL兩個(gè)方法來進(jìn)行對(duì)白平衡參數(shù)的獲取和設(shè)置。

          焦距(放大倍數(shù))

          在CameraInfo里面涉及焦距的參數(shù)真不少,iMinZoom、iMaxZoom、iMaxDigitalZoom、iMinZoomFactor、iMaxZoomFactor、iMaxDigitalZoomFactor

          這幾個(gè)參數(shù)值其實(shí)很困惑我的,特別是iMaxDigitalZoom,不知道是干嘛用的,這個(gè)值只能先不管了。根據(jù)CCamer提供了四個(gè)關(guān)于Zoom的如下四個(gè)函數(shù)

          /**

          Sets the digital zoom factor.

          This must be in the range of 0 to TCameraInfo::iMaxDigitalZoom inclusive.

          May leave with KErrNotSupported if the zoom factor is out of range.

          @param aDigitalZoomFactor

          The required digital zoom factor.

          */

          virtual void SetDigitalZoomFactorL(TInt aDigitalZoomFactor = 0)=0;

          /**

          Gets the currently set digital zoom factor.

          @return The currently set digital zoom factor.

          */

          virtual TInt DigitalZoomFactor() const=0;

          /**

          Sets the zoom factor.

          This must be in the range of TCameraInfo::iMinZoom to TCameraInfo::iMaxZoom

          inclusive. May leave with KErrNotSupported if the specified zoom factor is

          out of range.

          @param aZoomFactor

          Required zoom factor.

          */

          virtual void SetZoomFactorL(TInt aZoomFactor = 0)=0;

          /**

          Gets the currently set zoom factor.

          @return The currently set zoom factor.

          */

          virtual TInt ZoomFactor() const=0;

          可以猜測(cè)分別表示數(shù)碼變焦和光學(xué)變焦。

          另外,經(jīng)過對(duì)N81和E71的參數(shù)比較,N81的iMaxDigitalZoomFactor是20.0,而E71是4.0,正好對(duì)應(yīng)N81的20倍數(shù)碼變焦,E71的4倍數(shù)碼變焦。因?yàn)楹芏嗍謾C(jī)攝像頭鏡頭都不支持光學(xué)變焦,所以在這里對(duì)我們有用的也就是只需要通過DigitalZoomFactor和 SetDigitalZoomFactorL兩個(gè)函數(shù)在iMaxDigitalZoomFactor范圍內(nèi)設(shè)置數(shù)碼變焦值就可以了。

          圖像格式和圖像尺寸參數(shù)

          iImageFormatsSupported和iNumImageSizesSupported兩個(gè)參數(shù)分別用以表明攝像頭拍照時(shí)所支持的圖像格式和圖像尺寸數(shù)量,具體支持的圖像格式如下枚舉值定義

          enum TFormat

          {

          /** 8 bit greyscale values, 0=black, 255=white. */

          EFormatMonochrome = 0x0001,

          /** Packed RGB triplets, 4 bits per pixel with red in the least significant bits

          and the 4 most significant bits unused. */

          EFormat16bitRGB444 = 0x0002,

          /** Packed RGB triplets, 5 bits per pixel for red and blue and 6 bits for green,

          with red in the least significant bits. */

          EFormat16BitRGB565 = 0x0004,

          /** Packed RGB triplets, 8 bits per pixel with red in the least significant bits

          and the 8 most significant bits unused. */

          EFormat32BitRGB888 = 0x0008,

          /** JFIF JPEG. */

          EFormatJpeg = 0x0010,

          /** EXIF JPEG */

          EFormatExif = 0x0020,

          /** CFbsBitmap object with display mode EColor4K. */

          EFormatFbsBitmapColor4K = 0x0040,

          /** CFbsBitmap object with display mode EColor64K. */

          EFormatFbsBitmapColor64K = 0x0080,

          /** CFbsBitmap object with display mode EColor16M. */

          EFormatFbsBitmapColor16M = 0x0100,

          /** Implementation dependent. */

          EFormatUserDefined = 0x0200,

          /** 4:2:0 format, 8 bits per sample, Y00Y01Y10Y11UV. */

          EFormatYUV420Interleaved = 0x0400,

          /** 4:2:0 format, 8 bits per sample, Y00Y01Y02Y03...U0...V0... */

          EFormatYUV420Planar = 0x0800,

          /** 4:2:2 format, 8 bits per sample, UY0VY1. */

          EFormatYUV422 = 0x1000,

          /** 4:2:2 format, 8 bits per sample, Y1VY0U. */

          EFormatYUV422Reversed = 0x2000,

          /** 4:4:4 format, 8 bits per sample, Y00U00V00 Y01U01V01... */

          EFormatYUV444 = 0x4000,

          /** 4:2:0 format, 8 bits per sample, Y00Y01Y02Y03...U0V0... */

          EFormatYUV420SemiPlanar = 0x8000,

          /** CFbsBitmap object with display mode EColor16MU. */

          EFormatFbsBitmapColor16MU = 0x00010000

          };

          因?yàn)镹81主攝像頭的iImageFormatsSupported值為480(也即0x01E0),所以支持的格式為EFormatExif、EFormatFbsBitmapColor4K、 EFormatFbsBitmapColor64K和 EFormatFbsBitmapColor16M四種。

          每一種格式又有對(duì)應(yīng)的各種不同的尺寸,而具體支持的尺寸數(shù)則有iNumImageSizesSupported來限定,如上N81的iNumImageSizesSupported值為3,對(duì)每種格式使用CCamera::EnumerateCaptureSizes獲取得尺寸均為320*240,640*480,1152*864,這讓我百思不得其解,畢竟N81是200萬像素的攝像頭,怎么會(huì)最大尺寸是菜1152*864呢?系統(tǒng)自帶的照相/攝像程序也是支持1600*1200的,而且關(guān)鍵QQ手中郵也是支持1600*1200格式的,后來經(jīng)過在論壇上搜索,才知道原來CCamera::EnumerateCaptureSizes獲取的尺寸跟UI程序時(shí)橫屏(landscape)還是豎屏(portrait)有關(guān)的,像N81在橫屏模式下iNumImageSizesSupported的值為4,其尺寸為320*240,640*480,1152*864和1600*1200,而默認(rèn)豎屏下就是之前的那些數(shù)值。

          另外用E71手機(jī)做過實(shí)驗(yàn),發(fā)現(xiàn)對(duì)于E71,橫屏還是豎屏,其實(shí)是一樣的,沒有任何變化,其iNumImageSizesSupported始終是5,而用CCamera::EnumerateCaptureSizes獲取得尺寸也均為320*240,640*480,1152*864,1600*1200和2048*1536,所以我們?cè)讷@取最大尺寸時(shí)可以毫無顧忌的使用橫屏模式。

          有了這個(gè)尺寸,我們就可以根據(jù)需要,調(diào)用CCamera::PrepareImageCaptureL(TFormat aImageFormat,TInt aSizeIndex)函數(shù)來設(shè)定我們拍照時(shí)需要的具體尺寸了。

          在這里畫蛇添足下,對(duì)于使用橫屏和豎屏模式切換,可以在C*AppUi內(nèi)通過調(diào)用CAknAppUiBase::SetOrientationL(TAppUiOrientation aOrientation)來簡(jiǎn)單實(shí)現(xiàn),具體的參數(shù)值橫屏?xí)r傳EappUiOrientationLandscape,豎屏?xí)r傳EappUiOrientationPortrait。不過類似我們程序的自定義界面,調(diào)用完這個(gè)函數(shù)后,會(huì)產(chǎn)生消息到C*AppUi::HandleResourceChangeL,只要我們?cè)谶@個(gè)函數(shù)內(nèi)部處理好界面排版就可以了。關(guān)于該項(xiàng)測(cè)試,周二已經(jīng)和大紅一起演示過了。

          視頻格式和視頻尺寸參數(shù)

          手機(jī)攝像頭自然也提供了視頻的錄制功能,視頻是由一幀一幀的圖像構(gòu)成,在CameraInfo信息里頭與視頻相關(guān)的參數(shù)就是iNumVideoFrameSizesSupported(單幀的尺寸)、iNumVideoFrameRatesSupported(幀速)和iVideoFrameFormatsSupported(支持的幀格式)。

          因?yàn)镹81的iVideoFrameFormatsSupported是2048(也即0x800),所以視頻格式只支持EFormatYUV420Planar一種格式,而iNumVideoFrameSizesSupported為3,即支持3種模式,通過CCamera::EnumerateVideoFrameSizes(TSize aSize,TInt aSizeIndex,TFormat aFormat)函數(shù)可以得到N81攝像時(shí)支持的三種視頻尺寸為320*240,176*144,128*96,另外可以通過調(diào)用CCamera::EnumerateVideoFrameRates(TReal32 aRate, TInt aRateIndex, TFormat aFormat,TInt aSizeIndex,TExposure aExposure = EExposureAuto)函數(shù)得到N81支持的幀速為15幀每秒。

          有了這些參數(shù)可以方便的通過調(diào)用CCamera::PrepareVideoCaptureL函數(shù)設(shè)置攝像時(shí)所要用到的視頻尺寸和幀速;調(diào)用CCamera::StartVideoCapture函數(shù)開啟攝像,開啟攝像后攝像頭會(huì)調(diào)用MCameraObserver::FrameBufferReady傳遞回來具體的每一幀數(shù)據(jù),供界面顯示和編寫成視頻文件;調(diào)用CCamera::StopVideoCapture函數(shù)來停止攝像,在任何時(shí)候可以通過CCamera::VideoCaptureActive來查詢攝像頭是否處于攝像過程中。

          其它至于目前所使用的幀尺寸和幀速在其它地方是不可設(shè)置的,只能通過CCamera::GetFrameSize和CCamera::FrameRate兩個(gè)函數(shù)來進(jìn)行獲取當(dāng)前的參數(shù)值。

          幀緩存參數(shù)

          這個(gè)不知道怎么翻譯,我就籠統(tǒng)稱其為幀緩存參數(shù)好了,在攝像過程需要使用到幀緩存有iMaxFramesPerBufferSupported和iMaxBuffersSupported,前者表示每個(gè)buffer允許存放的最大幀數(shù),后者為允許使用的buffer最大個(gè)數(shù)。由于N81的iMaxBuffersSupported為2,所以最多允許使用2個(gè)幀緩存區(qū),又iMaxFramesPerBufferSupported是1,也即每個(gè)幀緩存最多只能放一幀數(shù)據(jù)。雖然目前并不完全知道其實(shí)際作用如何,但是這兩個(gè)參數(shù)也是只有通過CCamera::PrepareVideoCaptureL這個(gè)函數(shù)來進(jìn)行設(shè)置,通過函數(shù)CCamera::BuffersInUse()和CCamera::FramesPerBuffer()來獲取當(dāng)前的設(shè)置值。

          由于視頻攝像需要涉及到音視頻編輯方面的內(nèi)容,個(gè)人在視頻錄制方面還是空白,為此目前沒有真正嘗試,也就沒有深入進(jìn)去。

          以下在貼幾張預(yù)研中對(duì)E71 320萬像素4倍數(shù)碼變焦的CameraInfo信息截圖和N81 200萬像素20倍數(shù)碼變焦橫屏?xí)r的CameraInfo信息截圖,以供大家參閱。

          E71 CameraInfo信息截圖

          N81 橫屏CameraInfo信息截圖

          因?yàn)镋71不區(qū)分橫豎屏,所以CameraInfo是一樣的,有心的可以對(duì)比下之前的豎屏N81截圖和橫屏的差別。

          此次小結(jié)先到這里,錯(cuò)誤之處還望指正。



          關(guān)鍵詞: Symbian 攝像頭編程

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();