IOS Preview in landscape with correct zoom - ios

Who can give me an minimal example in IOS 5 or higher
of an app that captures the video of the backside cam with the following requirements:
The resolution of the image captured by the camera is 1280x720
The preview layer is a AVCaptureVideoPreviewLayer and fills the full screen on both IPhone 5 and 4
The orientation of both video and preview is LandScapeRight
If I want to zoom the preview, I correctly zoom into the center of my landscape image
I got everything working until 4.). But everytime I try to apply the zoom with
viewLayer.affineTransform = CGAffineTransformMakeScale(2, 2);
I observe that in landscape orientation the center of the focused image is left below the center of the unzoomed image. That is the problem I am trying to solve. So if I set the scale to 1, 1.3, 1.6 or 2.0 I want to always see the center of my unzoomed image.

Related

iOS - Capture video in landscape while the device is in portrait mode

Is it possible to capture video in landscape while the device is in portrait mode?
something like this:
actually what i need is to capture in portrait but with width > height, i dont want the user to rotate the device, but i do want to capture a wider picture like in landscape mode.
just changing the preview layer frame to be wide (width>height) wont be enough of course.
i tried changing the video orientation of the preview layer, but that will rotate the picture, and thats not what i want.
previewLayer.connection.videoOrientation = .landscapeRight
is that make any sense?
No its not possible as you would have to physically rotate the camera.
You can CROP the output video to whatever aspect ratio you desire.
This will however make your vertical resolution be at most what your horizontal resolution currently is.
As well as decreasing your field of view.
If you still wanna crop the video to simulate this "smaller landscape mode" in real time i suggest you use the "GPUImageCropFilter" from the library GPUImage
You can, you need to use AVAssetWriter and set the dimensions of the output video.
However, remember that you're going to be reducing quality. If the camera orientation is portrait, then what you're receiving is a video that is (for arguments sake) 720H x 360W.
So you want to make that landscape, if you preserve the aspect ratio, you're going to end up with a video (by cropping the input) that's 180H x 360W.
Remember, there is a difference between what the camera sees, what you send to the preview layer and what you record to a file - they can all be independent of each other (you spoke about changing the preview layer frame, remember that has nothing to do with the video you write out).
Have you tried with setting gravity & bounds of previewLayer?
var bounds:CGRect = self.view.layer.bounds
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer?.bounds = bounds
previewLayer?.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))

SpriteKit camera is not centred with aspectFit

My scene is set to be .AspectFit. I have camera node in scene center and it is connected. Everything works fine for iPad landscape, but when I rotate simulator or run in different device then iPad in landscape camera is not centred. Why?
This is for landscape with camera on center:
After rotation camera is not centred:
Similar issue is for e.g. for landscape iPhone5s:
Why is camera shifted with scene setting .AspectFit with other device then iPad in landscape?
You can try out or experiment with this project on bitbucket I made.
EDIT: When I don't use camera, everything is on its place.
Set the scene anchor point to 0.5, 0.5 to center your camera onto the scene , there is an issue with the view to scene conversion, and will draw in the top left corner instead of the center. (Also, you will notice your hello world is off, this is because it is not accounting for the anchor change)
Perhaps the lack of a camera will make the scene translate where it draws to inside of the black bars, I have no idea.

Flash CameraUI orientation is wrong

We're developing an AIR app for android and iOS. An important part of the app is taking photos. Using flash.media.CameraUI works perfectly on android, but we experience problems on iOS.
In the iOS camera application, when we rotate the iPad, the orientation is wrong: If we rotate the pad clockwise, the image is rotated anticlockwise. The UI buttons have the correct orientation though, and when the photo is taken, the resulting bitmap has the right orentation based on the orientation of the camera, not the actual view on the screen.
Looking at different camera apps, I notice that when the pad is rotated so the orientation changes clockwise, the camera does three things: First, the displayed image immediately becomes rotated 90 degrees anti-clockwise (so it looks wrong). Then, the image slowly rotates 90 degrees clockwise, to restore the correct orientation. In addition, the UI buttons change orientation so the text is displayed correctly.
It seems as in our app, it only rotates the image slowly without doing the first immediate rotation. Thus, the end result is wrong.
Anyone know how to fix this?
After some more research, I found that the issue isn't just restricted to AIR.
UIImagePickerController camera view rotating strangely on iOS 8 (pictures)

How to set up the video size so that it works on all ios devices without black bars

I'm just wondering what size the video should be so that there won't be black bars on iphone 4/5 or ipad? Any suggestion will be appreciated. Thanks!
Since the iPhone 4, iPhone 5, and iPad all have different screen aspect ratios it's impossible to have a single size of video which in full-screen mode won't have black bars on some devices.
Instead, you can use the scalingMode property of MPMoviePlayerController to keep your video zoomed in to fit the screen (assuming that's what you're using to play back your video - similar analogues exist in other video playback classes). You probably want to use the MPMovieScalingModeAspectFill scaling mode, which will fill the video to fit the screen without distorting it.

iPad 2 back-facing camera field of view

I want to render virtual content over the camera image from the back-facing camera of the iPad 2. To achieve this, OpenGL ES is used to transform the content into the correct screen coordinates.
projectionMatrix =
GLKMatrix4MakePerspective(GLKMathDegreesToRadians(FOV),
16.0f / 9.0f, 0.05f, 5.0f);
The problem is the field of view parameter.
There were several posts about iPhone or the iPad 1; however, I couldn't find one yet for iPad 2.
What is the field of view of the iPad 2 in landscape 16:9 HD mode?
This blog will probably help you:
http://hunter.pairsite.com/blogs/20110317/
In particular,
Using some basic trigonometry, this allowed me to determine that 4:3 stills taken with the iPad 2 back camera have an approximate 34.1 degree vertical field of view and an approximate 44.5 degree horizontal field of view. This equates roughly to a hypothetical 43mm focal length lens on a 35mm camera.

Resources