Advanced iOS video configuration

From ARToolworks support library

Jump to: navigation, search

Main Page > ARToolKit Professional > ARToolKit for iOS > Advanced iOS video configuration

Capturing a high-resolution image from the camera

As of ARToolKit v4.6.4 (iOS release 15) it is possible to capture a high-resolution image from the camera without closing the live video stream.

The photo that is captured uses the full photo resolution of the camera in use, and the size of this varies from device to device. As of ARToolKit v4.6.4, the photo is always captured in portrait mode (taller than wide). Here are some example sizes:

iPad 3 (rear), iPhone 4 (rear) 1936x2592 pixels
iPhone 4s, iPhone 5 (rear) 2448x3264 pixels
iPad 2 (rear) 960x720 pixels

The photo capture is initiated by invoking a method on the CameraVideo instance. In ARToolKit for iOS's ARViewController class, the CameraVideo instance is retrieved in the -start method:

    // libARvideo on iPhone uses an underlying class called CameraVideo. Here, we
    // access the instance of this class to get/set some special types of information.
    CameraVideo *cameraVideo = ar2VideoGetNativeVideoInstanceiPhone(gVid->device.iPhone);
    if (!cameraVideo) {
        NSLog(@"Error: Unable to set up AR camera: missing CameraVideo instance.\n");
        [self stop];
    // The camera will be started by -startRunLoop.
    [cameraVideo setTookPictureDelegate:self];
    [cameraVideo setTookPictureDelegateUserData:NULL];

Before invoking the photo capture method, we must add a delegate method to the same class that receives delegate calls for incoming video frames. The delegate method is an optional member of the ../../../support/library/_lt.css;CameraVideoTookPictureDelegate> protocol, cameravideoTookPictureHires:userData:jpegData:.

To this delegate method will be vended any user data set with setTookPictureDelegateUserData:, as well as a pointer to an NSData record holding the JPEG file. This file is suitable for writing to disk, or can alternately be saved to the user's photo roll.

- (void) cameravideoTookPictureHires:(id)sender userData:(void *)data jpegData:(NSData *)jpegData
    if (![jpegData writeToFile:jpegPath atomically:NO]) {
        NSLog(@"Error writing captured photo to '%@'\n", jpegPath);

or could be saved to the user's photo library with this version:

#import ../../../support/library/_lt.css;AssetsLibrary/AssetsLibrary.h>
- (void) cameravideoTookPictureHires:(id)sender userData:(void *)data jpegData:(NSData *)jpegData
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeImageDataToSavedPhotosAlbum:jpegData metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
        if (error) {
            NSLog(@"Error writing captured photo to photo album.\n");
    [library release];

Finally, the actual CameraVideo method to invoke the capture operation can be called directly:

    [cameraVideo capturePhoto];

or can be registered (under an alternative name) as the receiver of an NSNotification, for example an ARViewTouchNotification vended by ARToolKit's default ARView class:

    // Setup:
    [[NSNotificationCenter defaultCenter] addObserver:cameraVideo selector:@selector(capturePhotoNotification:) name:ARViewTouchNotification object:nil];
    // Removal of observer is required PRIOR to the CameraVideo instance being dealloc'ed:
    // Cleanup (done some time later):
    [[NSNotificationCenter defaultCenter] removeObserver:cameraVideo name:ARViewTouchNotification object:nil];


  • Photo capture will result in an interruption to video stream capture while the photo is captured and compressed to JPEG.
  • Photo capture may disrupt focus, exposure and white balance of the video stream capture.
  • A shutter sound plays during photo capture. This sound is played by the operating system, and cannot be disabled, although it will be silent if the device is muted.
Personal tools