Pergunta

I'm trying to implement tap to focus and tap to exposure in my iPhone app.

I'm using the AVFoundation camera interface and I'm having trouble moving between the 2 co-ord systems.

UIView uses a system that goes from (0,0) in the top left (in portrait mode) to (320,480) in the bottom right.

However the AVCaptureSession uses a system that goes from (0,0) in the top right to (1,1) in the bottom left.

I've had a look at the AVCamDemo but it doesn't seem to do anything to convert these, one minute you have the UIView coords and the next you have the AV coords.

Any help is appreciated!

Thanks

Oliver

Foi útil?

Solução

OK, I worked out what was going on. I'm writing the app at home though so can't update during the day :(

Anyway, the coord system for the touch is from (0,0) to (320,480) (top left to bottom right in portrait mode).

The coord system for the focal point of interest is (0,0) to (1,1) (top left to bottom right in landscape right mode).

In order to get the tap to focus you'll need an AVCaptureVideoPreviewLayer embedded into a subclass of UIView. (I'm assuming in this that the view is displayed across the entire screen).

To get from a tap to a focal point do the following.

Get the tap CGPoint (e.g. tapPoint).

Then use...

CGPoint focalPoint = CGPointMake(tapPoint.y/480, (320 - tapPoint.x)/320);

There may be a bit of code that does this for you but until then this will suffice.

Outras dicas

I know this is an old question, but THERE WAS a function in AVCamDemo to do the conversion in all videoGravity cases (your code only work if videoGravity of the videoPreviewLayer is AVLayerVideoGravityResize)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top