BOOL start()
{
bool status = true;
status &= (camera != nil) && [camera start];
status &= (streamer != nil) && [streamer start];
status &= (cloud_recognizer != nil) && [cloud_recognizer start];
[camera setFocusMode:easyar_CameraDeviceFocusMode_Continousauto];
for (easyar_ImageTracker * tracker in trackers) {
status &= [tracker start];
}
return status;
}
BOOL initialize()
{
camera = [easyar_CameraDevice create];
streamer = [easyar_CameraFrameStreamer create];
[streamer attachCamera:camera];
cloud_recognizer = [easyar_CloudRecognizer create];
[cloud_recognizer attachStreamer:streamer];
bool status = true;
status &= [camera open:easyar_CameraDeviceType_Default];
[camera setSize:[easyar_Vec2I create:@[@1280, @720]]];
uids = [[NSMutableSet<NSString *> alloc] init];
[cloud_recognizer open:cloud_server_address appKey:cloud_key appSecret:cloud_secret callback_open:^(easyar_CloudStatus status) {
if (status == easyar_CloudStatus_Success ) {
NSLog(@"CloudRecognizerInitCallBack: Success");
} else if (status == easyar_CloudStatus_Reconnecting) {
NSLog(@"CloudRecognizerInitCallBack: Reconnecting");
} else if (status == easyar_CloudStatus_Fail) {
NSLog(@"CloudRecognizerInitCallBack: Fail");
} else {
NSLog(@"CloudRecognizerInitCallBack: %ld", (long)status);
}
} callback_recognize:^(easyar_CloudStatus status, NSArray<easyar_Target *> * targets) {
if (status == easyar_CloudStatus_Success ) {
NSLog(@"CloudRecognizerCallBack: Success");
} else if (status == easyar_CloudStatus_Reconnecting) {
NSLog(@"CloudRecognizerCallBack: Reconnecting");
} else if (status == easyar_CloudStatus_Fail) {
NSLog(@"CloudRecognizerCallBack: Fail");
} else {
NSLog(@"CloudRecognizerCallBack: %ld", (long)status);
}
@synchronized (uids) {
for (easyar_Target * t in targets) {
if (![uids containsObject:[t uid]]) {
NSLog(@"add cloud target: %@", [t uid]);
[uids addObject:[t uid]];
[[trackers objectAtIndex:0] loadTarget:t callback:^(easyar_Target *target, bool status) {
NSLog(@"load target (%@): %@ (%d)", status ? @"true" : @"false", [target name], [target runtimeID]);
}];
}
}
}
}];
if (!status) { return status; }
easyar_ImageTracker * tracker = [easyar_ImageTracker create];
[tracker attachStreamer:streamer];
trackers = [[NSMutableArray<easyar_ImageTracker *> alloc] init];
[trackers addObject:tracker];
return status;}