日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          新聞中心

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

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

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

          預(yù)研

          本文引用地址:http://yuyingmama.com.cn/article/201610/305989.htm

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

          照相流程

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

          該過程主要涉及到的觀察器類就是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;

          //假如取景器模式為位圖模式時預(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;

          };

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

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

          關(guān)于CameraInfo

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

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

          iHardwareVersion

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

          iSoftwareVersion

          相機軟件的版本號(驅(qū)動程序版本號),該值也是OEM關(guān)心

          iOrientation

          相機的朝向,該值是OEM出廠時根據(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的主攝像頭朝向為EOrientationOutwards,當(dāng)然通過對N81和E71主次攝像頭信息數(shù)據(jù)的采集,可知類似N81、E71等雙攝像頭手機的主攝像頭屬性都是EOrientationOutwards的,而前面次攝像頭屬性都EOrientationInwards。從而猜測像N93i這樣的手機其攝像頭朝向?qū)傩詰?yīng)該為EOrientationMobile(因為是猜測,所有還期待有人幫忙驗證一下)。根據(jù)這個屬性,對于雙攝像頭手機,我們可以編程選中需要使用的攝像頭。

          iOptionsSupported

          同樣也是一些無法修改的屬性,表明了此攝像頭支持的功能,因為該值是個位域的值,通常使用過程中要用位與操作來判斷其是否支持某一種屬性,具體如下羅列的枚舉值

          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)心這個手機的攝像頭支持何種模式的取景器,支不支持拍照(EImageCaptureSupported)、支不支持錄像(EVideoCaptureSupported)、支不支持對比度設(shè)置(EcontrastSupported)和亮度設(shè)置(EBrightnessSupported)就可以了。

          因為N81主攝像頭的iOptionsSupporte值是14(即1110)所以該主攝像頭只支持位圖模式的取景器設(shè)置,同時支持圖像和視頻的拍攝,不支持對比度亮度等設(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.快門開時閃 */

          EFlashSlowFrontSync = 0x0010,

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

          EFlashSlowRearSync = 0x0020,

          /** User configurable setting */

          EFlashManual = 0x0040

          };

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

          知道了支持何種類型,我們就可以對攝像頭的閃光燈類型通過CCamera::Flash和CCamera::SetFlashL兩個函數(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的相機曝光支持模式為7(即0111),所以只支持自動、夜晚、背光和中間四種模式。

          我們可以通過CCamera::Exposure()和CCamera::SetExposureL兩個函數(shù)對攝像頭的曝光模式進行獲取和設(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兩個方法來進行對白平衡參數(shù)的獲取和設(shè)置。

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

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

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

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

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

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

          iImageFormatsSupported和iNumImageSizesSupported兩個參數(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

          };

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

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

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

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

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

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

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

          因為N81的iVideoFrameFormatsSupported是2048(也即0x800),所以視頻格式只支持EFormatYUV420Planar一種格式,而iNumVideoFrameSizesSupported為3,即支持3種模式,通過CCamera::EnumerateVideoFrameSizes(TSize aSize,TInt aSizeIndex,TFormat aFormat)函數(shù)可以得到N81攝像時支持的三種視頻尺寸為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è)置攝像時所要用到的視頻尺寸和幀速;調(diào)用CCamera::StartVideoCapture函數(shù)開啟攝像,開啟攝像后攝像頭會調(diào)用MCameraObserver::FrameBufferReady傳遞回來具體的每一幀數(shù)據(jù),供界面顯示和編寫成視頻文件;調(diào)用CCamera::StopVideoCapture函數(shù)來停止攝像,在任何時候可以通過CCamera::VideoCaptureActive來查詢攝像頭是否處于攝像過程中。

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

          幀緩存參數(shù)

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

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

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

          E71 CameraInfo信息截圖

          N81 橫屏CameraInfo信息截圖

          因為E71不區(qū)分橫豎屏,所以CameraInfo是一樣的,有心的可以對比下之前的豎屏N81截圖和橫屏的差別。

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



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

          評論


          相關(guān)推薦

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

          關(guān)閉