Emulating the camera apps 'tap to focus' - iphone

I am trying hard to emulate the basic functionality of the built in camera app. Thus far I have become stuck on the 'tap to focus' feature.
I have a UIView from which I am collecting UITouch events when a single finger is tapped on the UIView. This following method is called but the camera focus & the exposure are unchanged.
-(void)handleFocus:(UITouch*)touch
{
if( [camera lockForConfiguration:nil] )
{
CGPoint location = [touch locationInView:cameraView];
if( [camera isFocusPointOfInterestSupported] )
camera.focusPointOfInterest = location;
if( [camera isExposurePointOfInterestSupported] )
camera.exposurePointOfInterest = location;
[camera unlockForConfiguration];
[cameraView animFocus:location];
}
}
'camera' is my AVCaptureDevice & it is non-nil. Can someone perhaps tell me where I am going wrong?
Clues & boos all welcome.
M.

This snippet might help you...There is a CamDemo provided by apple floating around which allows you to focus, change exposure while tapping, set flash, swap cameras and more, it emulates the camera app pretty well, not sure if youll be able to find it since it was part of wwdc, but if u leave some email address in the comments i can email you the sample code...
- (void) focusAtPoint:(CGPoint)point
{
AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
} else {
id delegate = [self delegate];
if ([delegate respondsToSelector:#selector(acquiringDeviceLockFailedWithError:)]) {
[delegate acquiringDeviceLockFailedWithError:error];
}
}
}
}

Related

IOS - LED Strobe Flashlight Slider iPhone

Hi i am making a flashlight app in Objective C for iPhones, i have got some basic features such as an LED dimming slider and a button to turn the flashlight on and off but i wanted to add a second slider to add a strobe light effect where sliding the slider would increase the frequency of the flashes.
I have tried anything i can think of and nothing is working :/
This is part of the code i am using for it:
-(IBAction)torchOn:(id)sender;
{
onButton.hidden = YES;
offButton.hidden = NO;
onView.hidden = NO;
offView.hidden = YES;
if([self.flashlight isTorchAvailable] && [self.flashlight isTorchModeSupported:AVCaptureTorchModeOn])
{
BOOL success = [self.flashlight lockForConfiguration:nil];
if (success)
{
[self.flashlight setTorchMode:(AVCaptureTorchModeOn)];
[self.flashlight unlockForConfiguration];
}
}
}
- (IBAction)intensitySliderValueChanged:(UISlider*)sender {
if(sender.value == 0 || sender.value > 1) return;
if([self.flashlight isTorchAvailable] && [self.flashlight isTorchModeSupported:AVCaptureTorchModeOn])
{
BOOL success = [self.flashlight lockForConfiguration:nil];
if (success)
{
[self.flashlight setTorchModeOnWithLevel:sender.value error:nil];
[self.flashlight unlockForConfiguration];
}
}
}
I know this is not particularly useful in understanding my problem but if any of you have a solution i would be extremely grateful!

Switch On/Off flash while recording the Video in iphone app

I am recording video from my iPhone app.
I am using an overlay over the camera and placed a button in the overlay. I want to know with the help of which function can I turn camera's flash on/off while the video is being recorded.
How can I set a flash button in the camera overlay?
If you are using AVFoundation for video recording, You should first check if device has torch/flash because torch is available when video is being recorded from the back camera, you can not have the torch/flash when using front camera.
using something like this
- (BOOL) hasTorch
{
return [[[self avCaptureDeviceInput] device] hasTorch];
}
and then set the torch accordingly using AVCaptureTorchMode
- (void) setTorchMode:(AVCaptureTorchMode)torchMode
{
AVCaptureDevice *device = [[self videoInput] device];
if ([device isTorchModeSupported:torchMode] && [device torchMode] != torchMode) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setTorchMode:torchMode];
[device unlockForConfiguration];
} else {
id deleg = [self delegate];
if ([deleg respondsToSelector:#selector(acquiringDeviceLockFailedWithError:)]) {
[deleg acquiringDeviceLockFailedWithError:error];
}
}
}
}
if you follow the AVCam Demo from Apple you will get your answers basically.
Assuming you are using UIImagePickerController (from your tag), use the cameraFlashMode provided by UIImagePickerController to control the flash.
You can set its value to UIImagePickerControllerCameraFlashModeOff, UIImagePickerControllerCameraFlashModeAuto or UIImagePickerControllerCameraFlashModeOn. Default is auto.

modifying zxing library files barcode scanner iPhone

I want to modify the zxing library files (which is an open source library) a bit to have the cameraFlashMode On as soon as user taps on scan button to open the bar code scanner camera. Also, I want to add one or two UIButtons at the bottom. In short, I want to customize that camera view according to my needs.
If anyone has done it or knows how to do it, then please help me.
You need to implement your customizations in OverlayView.m. Add the buttons in
- (id) initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled;
And set the flashmode in ZXingWidgetController.h in
- (void)initCapture;
Set the flashMode on with:
- (void)activateFlash {
Class captureDeviceClass = NSClassFromString(#"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
if ( [device hasFlash] ) {
[device setFlashMode:AVCaptureFlashModeOn];
}
[device unlockForConfiguration];
}
}

How to use AVCaptureConnnections?

i am new to AVFoundation and i am trying to implement a video camera with AVFoundation here is my basic setup. Basically, when you click a button it will call the showCamera method. In here i create the session and then add an audio input and video input then add the video output.
Where in here do i add the AVCaptureConnection and how do i do it? Is there some tutorial that shows how to use the connections? Any help is appreciated.
- (IBAction) showCamera
{
//Add the camview to the current view ontop of controller
[[[[[UIApplication sharedApplication] delegate] self] window] addSubview:camView];
session = [[AVCaptureSession alloc] init];
//Set preset on session to make recording scale high
if ([session canSetSessionPreset:AVCaptureSessionPresetHigh]) {
session.sessionPreset = AVCaptureSessionPresetHigh;
}
// Add inputs and outputs.
NSArray *devices = [AVCaptureDevice devices];
//Print out all devices on phone
for (AVCaptureDevice *device in devices)
{
if ([device hasMediaType:AVMediaTypeVideo])
{
if ([device position] == AVCaptureDevicePositionBack)
{
//Add Rear Video input to session
[self addRearCameraInputToSession:session withDevice:device];
}
}
else if ([device hasMediaType:AVMediaTypeAudio])
{
//Add Microphone input to session
[self addMicrophoneInputToSession:session withDevice:device];
}
else
{
//Show error that your camera does not have a phone
}
}
//Add movie output
[self addMovieOutputToSession:session];
//Construct preview layer
[self constructPreviewLayerWithSession:session onView:camView];
}
You don't add AVCaptureConnections manually. When you have both an input and an output added to the AVCaptureSession object, the connections are automatically created for you. Quoth the documentation:
When an input or an output is added to a session, the session greedily forms connections between all the compatible capture inputs’ ports and capture outputs.
Unless you need to disable one of the automatically-created connections, or change the videoMirrored or videoOrientation properties, you shouldn't have to worry about them at all.
Take a look at following URLs...
Documentation from Apple:
An Article:
Video Recording using AVFoundation Framework iPhone?
I think, it will help you....

IPhone iOS 4.3 camera focus square - removeable programmatically?

Since my friend updated his iPhone iOS to 4.3 there's a small square which appears every time he takes a picture with the camera.
We're developing an app that uses the camera and would like to remove this annoying square. I didn't find anything about it in Apple's UIImagePickerController documentation.
The square didn't exist in former iOS versions.
You may want to try to lock the focus to disable auto-focus. Here is a sample code:
NSArray *devices = [AVCaptureDevice devices];
NSError *error;
for (AVCaptureDevice *device in devices) {
if (([device hasMediaType:AVMediaTypeVideo]) &&
([device position] == AVCaptureDevicePositionBack) ) {
[device lockForConfiguration:&error];
if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
device.focusMode = AVCaptureFocusModeLocked;
NSLog(#"Focus locked");
}
[device unlockForConfiguration];
}
}
Setting the .showsCameraControls property of your picker controller to NO should remove the focus square (it did pre 4.3, I don't think anything has changed), but the downside is you'll need to provide your own controls (to take photos, etc). It's all or nothing I'm afraid!
Create a custom overlay and default overlay will not display. You can make your overlay can be completely empty.