Code Sample - AR SDK

From WakingApp SDKs
Jump to: navigation, search

Setting image from memory

//download an image from url
NSString* targetImageURL = @"";
NSURL* url = [NSURL URLWithString:targetImageURL];
NSData* targetImageData = [NSData dataWithContentsOfURL:url];
if (targetImageData )
    //set image as target image to be tracked
    [TrackerAPI setTargetImageFromMemory: targetImageData];

Setting image from file

  • Create a folder named Assets and drag into your Xcode project hierarchy.
  • Set target/tile image using:
[TrackerAPI setTargetImageFromFile : "targetImage.png"];
[TrackerAPI setTileImageFromFile : "sample.jpeg"];

Tracking found/lost events

  • an interface may implement <ARCameraDelegate> in order to listen to track image found/lost events. To listen to the events implement the following methods:
	NSLog(@"track found\n");

	NSLog(@"track lost\n");
  • The viewcontroller is set as the default delegate. It is possible to set a different class as delegate using :
MyDelegateClass* instanceOfDelegateClass = [[MyDelegateClass alloc] init];
[TrackerAPI setDelegate : instanceOfDelegateClass];

Obtaining camera frame

  • an interface may implement <ARCameraDelegate> in order to listen to a camera frame event and obtain camera image data. To listen to the event implement the following method:
-(void)onCameraFrame:(NSData*)yBuffer : (NSData*)uvBuffer
    NSLog(@"camera frame obtained\n");
    //Conversion from yBuffer (Grayscale image) to CGImageRef
    const CGSize cameraResolution = [TrackerAPI getCameraResolution];
    const unsigned long bytesPerRow = [yBuffer length] / cameraResolution.height;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
    CGContextRef context = CGBitmapContextCreate((void*)[yBuffer bytes], cameraResolution.width, cameraResolution.height, 8,
                                                 bytesPerRow, colorSpace,
    CGImageRef myGrayImage = CGBitmapContextCreateImage(context);
    //You may get a UIImage representation like this-
    //UIImage *image = [UIImage imageWithCGImage:myGrayImage];