• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            franksunny的個人技術空間
            獲得人生中的成功需要的專注與堅持不懈多過天才與機會。 ——C.W. Wendte

             文檔中涉及到貼圖,懶得搞,就附帶一份word文檔吧,需要的可以下下 http://m.shnenglu.com/Files/franksunny/camera.rar

            攝像頭編程預研

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

            照相流程

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

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

            class MCameraObserver

            {

            public:

                    //CCamera::Reserve異步函數的回調通知

                   virtual void ReserveComplete(TInt aError)=0;

                    //CCamera::PowerOn異步函數的回調通知

                   virtual void PowerOnComplete(TInt aError)=0;

                    //假如取景器模式為位圖模式時預覽位圖的回調通知

                   virtual void ViewFinderFrameReady(CFbsBitmap& aFrame)=0;

                    //CCamera::CaptureImage異步函數的回調通知

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

                    //CCamera::StartVideoCapture異步函數的回調通知

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

            };

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

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

            關于CameraInfo

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

            對各自參數的分析如下

            iHardwareVersion

            相機硬件的版本號,該值不用細究,是OEM關心的

            iSoftwareVersion

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

            iOrientation

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

                /** 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

                };

            根據取得的值的情況,N81的主攝像頭朝向為EOrientationOutwards,當然通過對N81E71主次攝像頭信息數據的采集,可知類似N81E71等雙攝像頭手機的主攝像頭屬性都是EOrientationOutwards的,而前面次攝像頭屬性都EOrientationInwards。從而猜測像N93i這樣的手機其攝像頭朝向屬性應該為EOrientationMobile(因為是猜測,所有還期待有人幫忙驗證一下)。根據這個屬性,對于雙攝像頭手機,我們可以編程選中需要使用的攝像頭。

            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

                          };

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

            因為N81主攝像頭的iOptionsSupporte值是14(即1110)所以該主攝像頭只支持位圖模式的取景器設置,同時支持圖像和視頻的拍攝,不支持對比度亮度等設置。

            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. 快門關事閃*/

                           EFlashSlowRearSync  = 0x0020,

                           /** User configurable setting */   

                           EFlashManual        = 0x0040

                   };

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

            知道了支持何種類型,我們就可以對攝像頭的閃光燈類型通過CCamera::FlashCCamera::SetFlashL兩個函數獲取和設置。

            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兩個函數對攝像頭的曝光模式進行獲取和設置。

            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

                   };

            具體不做展開,可以通過調用CCamera::WhiteBalanceCCamera::SetWhiteBalanceL兩個方法來進行對白平衡參數的獲取和設置。

            焦距(放大倍數)

            CameraInfo里面涉及焦距的參數真不少,iMinZoomiMaxZoomiMaxDigitalZoomiMinZoomFactoriMaxZoomFactoriMaxDigitalZoomFactor

            這幾個參數值其實很困惑我的,特別是iMaxDigitalZoom,不知道是干嘛用的,這個值只能先不管了。根據CCamer提供了四個關于Zoom的如下四個函數

            /**

             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;

            可以猜測分別表示數碼變焦和光學變焦。

            另外,經過對N81E71的參數比較,N81iMaxDigitalZoomFactor20.0,而E714.0,正好對應N8120倍數碼變焦,E714倍數碼變焦。因為很多手機攝像頭鏡頭都不支持光學變焦,所以在這里對我們有用的也就是只需要通過DigitalZoomFactor SetDigitalZoomFactorL兩個函數在iMaxDigitalZoomFactor范圍內設置數碼變焦值就可以了。

            圖像格式和圖像尺寸參數

            iImageFormatsSupportediNumImageSizesSupported兩個參數分別用以表明攝像頭拍照時所支持的圖像格式和圖像尺寸數量,具體支持的圖像格式如下枚舉值定義

                   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),所以支持的格式為EFormatExifEFormatFbsBitmapColor4K EFormatFbsBitmapColor64K EFormatFbsBitmapColor16M四種。

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

            另外用E71手機做過實驗,發現對于E71,橫屏還是豎屏,其實是一樣的,沒有任何變化,其iNumImageSizesSupported始終是5,而用CCamera::EnumerateCaptureSizes獲取得尺寸也均為320*240640*4801152*8641600*12002048*1536,所以我們在獲取最大尺寸時可以毫無顧忌的使用橫屏模式。

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

             

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

            視頻格式和視頻尺寸參數

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

            因為N81iVideoFrameFormatsSupported2048(也即0x800),所以視頻格式只支持EFormatYUV420Planar一種格式,而iNumVideoFrameSizesSupported3,即支持3種模式,通過CCamera::EnumerateVideoFrameSizes(TSize& aSize,TInt aSizeIndex,TFormat aFormat)函數可以得到N81攝像時支持的三種視頻尺寸為320*240176*144128*96,另外可以通過調用CCamera::EnumerateVideoFrameRates(TReal32& aRate, TInt aRateIndex, TFormat aFormat,TInt aSizeIndex,TExposure aExposure = EExposureAuto)函數得到N81支持的幀速為15幀每秒。

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

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

            幀緩存參數

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

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

             

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

            E71 CameraInfo信息截圖

            N81 橫屏CameraInfo信息截圖

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

             

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

            posted on 2010-11-03 14:55 frank.sunny 閱讀(2818) 評論(0)  編輯 收藏 引用 所屬分類: symbian 開發

            常用鏈接

            留言簿(13)

            隨筆分類

            個人其它博客

            基礎知識鏈接

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久久无码人妻中文字幕豆芽| 国产成人精品免费久久久久| 久久成人精品| 香蕉久久永久视频| 久久丫精品国产亚洲av| 国内精品欧美久久精品| 中文字幕乱码人妻无码久久| 精品久久久久久无码专区| 久久国产V一级毛多内射| 亚洲国产精品18久久久久久| 国产精品视频久久久| 模特私拍国产精品久久| 久久精品国产精品亚洲毛片| 91亚洲国产成人久久精品网址| 香蕉久久永久视频| 精品免费tv久久久久久久| 久久亚洲中文字幕精品一区| 久久精品国产半推半就| 婷婷久久久亚洲欧洲日产国码AV| 日韩欧美亚洲综合久久影院Ds| 久久久无码一区二区三区| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 日韩精品无码久久久久久| 国内精品久久久久久不卡影院| 波多野结衣中文字幕久久| 久久人人爽人人爽人人片av麻烦| 国产精品亚洲美女久久久| 久久91亚洲人成电影网站| 久久ZYZ资源站无码中文动漫| 久久精品极品盛宴观看| 久久毛片免费看一区二区三区| 成人a毛片久久免费播放| 狠狠色丁香婷婷综合久久来| 国产精品青草久久久久婷婷| 久久99精品国产麻豆| 久久精品国产亚洲av麻豆色欲 | 久久精品国产99国产精品| 国产精品久久久久久久午夜片| 99久久亚洲综合精品网站| 国产精品久久久久久久午夜片| 久久综合九色综合网站|