Week 4: Ways to Get to iPhone’s Camera Frames
2011-07-28 12:42
239 查看
Week4:WaystoGettoiPhone’sCameraFrames
March21,2010
Everythingfromthisweekyou’llfindinnextweek’sarticle:Week5:WaystoGettoiPhone’sCameraFrames(Continued).原文:
Week5:WaystoGettoiPhone’sCameraFrames(Continued)
March28,2010
ThesupportedwayofusingtheiPhone’scameraisbytakingphotosandvideosonthesupporteddeviceswiththestandardUIImagePickerControllerandthensavethemtodiskforfurtherusage.ThesameUIImagePickerControllerisalsousedforpickingexistingmedia.Post-processingalreadytakenmediadoesn’tmakesenseforanARapp.
AnARappwhichdoesimageprocessingneeds
cameraframesatarelativelyhighfrequencyf1forimageprocessingand
thescreenfilledwithcameraframesataveryhighfrequencyf2tocreatetheillusionof“lookingthroughthedeviceintotherealworld”.
TheResolutiondoesn’tmatterthatmuchforimageprocessingneitherfordisplayingonthedevice’sscreenwithitssmallresolution.
Regardlesswhichmethodisused,fillingthescreenwithcameraframesnevercomesuptotheneededfrequencyf2ofabout30-60Hz.SowedisplaythepreviewoftheUIImagePickerController.
ImagePickerController’scontrols
SinceiPhoneOS3.1it’spossibletohidethecontrols.
Nowthereisablackbaratthebottom(spacethecameracontrolsonceoccupied)withaheightof56px.Tocoverthatwecanstretchthecamera’sviewwithanaffinematrixtransform.
idiom:stretchvertically
ImagePickerController’sviewstretchedvertically
Advantage:noimageinformationloss
Disadvantage:distortedaspectration
idiom:scaleproportionally
ImagePickerController’sviewscaled
Advantage:keepaspectratio
Disadvantage:loseimageinformationonthesideduetozoomeffect
Decision:useidiom2foritsaspectratiokeeping
(480-56)->1
480->1.132075471698113(~13%scale)
Unfortunatelywecan’tlowerdisadvantagebydistributethelossonbothsides(notonlyrightside),sincetranslationdoesn’tseemtoapply.Wewouldhave:
320*1.132075471698113=362.26415094339616=~362
362–320=42pxlossonrightside=>move21pxtotheleft
Note:thetransformwillapplytoanypicturestakenby-takePicture
Nowwehaveascreenfuloftherealworldatahighfrequency.
Tocapturethecameraframesatarelativelyhighfrequencyf1forimageprocessingtherearebasicallythreeways:
UIImagePickerController’smethod-takePicture
ThisisawayoftakingpicturesprogrammaticallyintroducediniPhoneOS3.1.ButitstillrequirestheheavyuserprocessandaftersometestsIfoundafrequencyofabout1Hzbutf1mustbehigher.Alsotheimagewasinfullcameraresolution(about3MP)andIranintomemoryconstraints.
HackswithprivateAPI
Idon’thaveanyexperiencewiththisandwon’tconcentrateonit.Ithinkit’sneveragoodwaytogo.
“PrivateAPI”functionUIGetScreenImage
It’sprivateAPIbutApplehasstartedallowingtheuseofthisfunctionintheendof2009.MaybeitwillbreakinafuturereleaseofiPhoneOSandmaybeyoustillgotrejectedfromtheAppStore.MaybeApplesoonwillprovideapublicAPI.
Sinceitsimplycapturesthecurrentscreencontent,ifyouoverlayUIinframetitwillbecapturedtooinframet+1.ThepartofthescreenyouwanttoprocessmustremainclearfromUIandshowtheoriginalpicture.
Tousethisfunctionconveniently,thefollowingworkwasnecessary.
01 | @implementation UIImage(DBAdditions) |
02 |
03 | +(UIImage*)imageWithScreenContents{ |
04 | //Capturesthecurrentscreencontentinscreenresolution. |
05 | //-"PrivateAPI" |
06 | //-returnsNULLinsimulator |
07 | //-Thememorymanagement"CreateRule"statesthateveryfunctionwith"Create"or"Copy"embeddedinthename |
08 | //returnaretainedobject.Allothersareautoreleased.However,UIGetScreenImagereturnsaretainedCGImageRef. |
09 | //Becauseit’ssupposedtobeaprivateAPI,theyweren'tcarefulwiththename. |
10 | //Declarationinsidemethodsinceit'stheonlyscopeweneedthisfunction. |
11 | extern CGImageRefUIGetScreenImage( void ); |
12 | //keyword'extern':clarifythatdefinitionisinotherfile |
13 | //argument'void':emptyargumentlistwouldmeananynumberofargumentsofanytypeinC |
14 |
15 | CGImageRefscreenImage=UIGetScreenImage(); |
16 | if (screenImage!= NULL ){ |
17 | UIImage*image=[UIImageimageWithCGImage:screenImage]; |
18 | CGImageRelease(screenImage); |
19 | return image; |
20 | } |
21 | return nil ; |
22 | } |
23 |
24 | @end |
相关文章推荐
- 6 Ways To Stay Ready So You Don’t Have To Get Ready
- How to capture video frames from the camera as images using AV Foundation
- Seven effective ways to get the most out of the morning
- ways to get DNS updated for a server re-IP.
- Iphone开发中的两个小bug,1.调用camera时的内存警告导致view自动upload,2,Not enough frames in stack.
- (算法分析Week1)Different Ways to Add Parentheses[Medium]
- Four Ways to Deal With the Longer iPhone 5 screen
- How to get the Projection ProjectionMatrixFromCameraIntrinsics
- How to capture video frames from the camera as images using AV Foundation on iOS
- Different ways to get the symbol name and ...
- 241. Different Ways to Add Parentheses(week 2)
- Iphone真机调试出错:launching remote program: failed to get the task for process XXX
- How to Get First and Last Day of a Week in SQL Server
- How to Get Sql sever 2000 WeekFirstDay and WeekLastDay...
- 【藏】iPhone Development: 12 Tips To Get You Started Article
- How to Get Sql sever 2000 WeekFirstDay and WeekLastDay...
- How to Get the Best Image Quality from Your IP Camera
- iOS Programming 101: How To Get the User Location in iPhone App
- How to grab video frames directly from QCamera
- 拨打视频电话时选择关闭摄像头弹出Phone报错java.lang.RuntimeException: Fail to get camera info 或 startPreview failed