iPhoneのプログラム

入り口の認識のサンプルプログラム

シナリオファイル

disp3.lua
local MLTPlugin = getMLTPluginManager()
local scene = getCurrentScene()
local camera = Camera(scene:getCurrentCamera())
local vidCap = VideoCapture(scene:getObjectByName("vidcap"))
local msg = Text2D(scene:getObjectByName("txtMsg"))


local err_ret = eOk
local trackingIndex = -1
local targetStatus = {-1, -1, -1}
local action = {
"1101    found!", "1102    found!", "1103    found!",
"1104    found!", "1105    found!", "1106    found!",
"1107    found!", "1108    found!", "1109    found!",
"1110    found!", "1111    found!", "1112    found!",
"1113    found!", "1114    found!", "1115    found!",
"1116    found!", "1117    found!",
"1    found!",    "2    found!" }

local key = -1
local found = -1
local i=0
local stage = 1
local found_marker = -1
local cand = 3

local isCommand = nil
local command = nil
local mode = 1

msg:setText(" ")

err_ret, trackingIndex = MLTPlugin:startTracking("B1/tracker.xml", vidCap:getVidCapID(), camera)

function gotoStage(n)
	MLTPlugin:stopTracking(trackingIndex)
    
	stage = n

	if n == 1 then
		msg:setText("stage=1")
		err_ret, trackingIndex = 
			MLTPlugin:startTracking("B1/tracker.xml", vidCap:getVidCapID(), camera)
	elseif n == 2 then
		msg:setText("stage=2")
		err_ret, trackingIndex =
			MLTPlugin:startTracking("B2/tracker.xml", vidCap:getVidCapID(), camera)
	elseif n == 3 then
		msg:setText("stage=3")
		err_ret, trackingIndex =
			MLTPlugin:startTracking("B3/tracker.xml", vidCap:getVidCapID(), camera)
	elseif n == 4 then
		msg:setText("stage=4")
		err_ret, trackingIndex =
			MLTPlugin:startTracking("B4/tracker.xml", vidCap:getVidCapID(), camera)
	elseif n == 5 then
		msg:setText("stage=5")
		err_ret, trackingIndex =
			MLTPlugin:startTracking("B5/tracker.xml", vidCap:getVidCapID(), camera)
	elseif n == 6 then
		msg:setText("stage=6")
		err_ret, trackingIndex =
			MLTPlugin:startTracking("B6/tracker.xml", vidCap:getVidCapID(), camera)
	elseif n == 7 then
		msg:setText("stage=7")
		err_ret, trackingIndex =
			MLTPlugin:startTracking("B7/tracker.xml", vidCap:getVidCapID(), camera)
	end
end

function recognize()

		if stage <= 5 then
			cand = 3
		else
			cand = 2
		end

		for i = 1,cand do
    	err_ret, targetStatus[i] = MLTPlugin:getTargetStatus(trackingIndex, i-1)
		end

		found = -1
		for i = 1,cand do
			if (targetStatus[i] == 1) then
				found = i
				break
			end
		end

		if (found ~= -1) then

			if (stage <= 5) then
				key = found + 3*(stage-1)
			else
				key = found + 2*(stage-6) + 15
			end

			msg:setText(action[key])

			mode = 2
		else
			if (stage == 1) then
				gotoStage(2)
			elseif (stage == 2) then
				gotoStage(3)
			elseif (stage == 3) then
				gotoStage(4)
			elseif (stage == 4) then
				gotoStage(5)
			elseif (stage == 5) then
				gotoStage(6)
			elseif (stage == 6) then
				gotoStage(7)
			elseif (stage == 7) then
				gotoStage(1)
			end

 			coroutine.yield()
		end

end

repeat
	if (mode == 1) then

		recognize()

	end

until coroutine.yield()

AppDelegate.h
#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;

@end

AppDelegate.mm
#import "AppDelegate.h"

#import "ViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (void)dealloc
{
    [_window release];
    [_viewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

ViewController.h
#import <UIKit/UIKit.h>
#import "satchARViewer.h"

@interface ViewController : UIViewController {
    SatchARViewer *mPlayer;
}

@property (retain, nonatomic) IBOutlet UIView *mRender;

@end

ViewController.m
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize mRender;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    [SatchARViewer        setDialogMessageLoading:@"ローディング..."];
    [SatchARViewer        setToastMessageNoNetworkConnection:@"ネットワークに接続されていません。"];
    [SatchARViewer        setToastMessageNetworkError:@"通信中にエラーが発生しました。"];
    [SatchARViewer        setToastMessageLicenceError:@"認証に失敗しました"];
    
    mPlayer = [[[SatchARViewer alloc] init] initialize:mRender];
    [self start];
}

- (void)viewDidUnload
{
    [self setMRender:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)dealloc {
    if (mPlayer) {
        [mPlayer terminate];
        [mPlayer release];
        mPlayer = nil;
    }
    
    [mRender release];
    [super dealloc];
}

- (void)start
{
    if (mPlayer) {
        [mPlayer loadScenario:@"Jan1_iphone/Jan1.dpd"
                     callback:@selector(callback:)
                          obj:self];
    }
}

- (void)stop
{
    if (mPlayer && ![mPlayer isScenarioPaused]) {
        [mPlayer pauseScenario];
    }    
}

- (void)callback:(NSNumber*)num
{
    switch ([num intValue]) {
        case LOAD_SCENARIO_STATUS_COMPLETE:
            [mPlayer playScenario];
            break;
    }
}

@end

入り口(マクドナルド側)を認識

入り口(K2号館側)を認識