- OpenCVの公式サイトhttps://opencv.org/releases/にブラウザでアクセスします。現時点(2020/10/07)では、OpenCV-4.4.0 が最新のようなので iOS pack をクリックすると opencv-4.4.0-ios.zipがダウンロードされる。
-

- Xcode を起動して "Create a new Xcode project" で
"iOS"の"App"を指定して新しいプロジェクトを開きます。
ここではプロジェクト名を SwiftOpenCV としています。



-
Main.storyboard上の ViewController の中に、ウィンドウ右下の "Object library" から
"Button" をドラッグして配置します。Buttonのtextは "Go" に変更しました。

-
Main.storyboard 上で "Button" を1回クリックして選択してから、マウスを右ドラッグ
(または Control + 左ドラッグ)し、で新しく作成した View Controller 上でマウスのボタンを離します。

Action Segue から Present Modally を選択します。

元のView Controller から新しい View Controller に向けて Segue を表す矢印が表示されて、
画面が遷移できることを表します。

- ウィンドウ左の "Show the project navigator"
でプロジェクト名のフォルダを右クリックして"New File"を選択する。

- "Choose a template for your new file" では、
iOS -> Source ->
"Cocoa Touch Class"を選択して"Next"をクリックする。

-
Subclss of: に対しては "UIViewContoller" を、言語には "Swift" 選択し
Class: には適当な名前をつける。ここでは ViewController2 とした。

-
ViewController2.swift が生成されるフォルダは、他のファイルと同じく SwiftOpenCV のままで構わない。

-
ウィンドウ左の project navigator から Main.storyboardを選ぶ。
新しくできた View Controller を1回クリックして選択してから
ウィンドウ右の "Show the identity inspector"
を選んで、Custom Class の Class を先ほど作成した ViewController2 を選択する。


-
Main.storyboard上の右の(新しい)View Controller上に、ウィンドウ右下の
"Show the object library" から Button を配置する。
ボタンのtextは "Back" に変更しておく。

- Main.storyboardが表示されている状態で、
ウィンドウの右上の "Show the Assistant Editor" ボタン
をクリックし、さらに Main.storyboard上で右の新しい View Controller を選択して、
右側のウィンドウに ViewController2.swift が表示されている状態にします。

-
Main.storyboard上の右側の新しいView Controller 上の Button ("Back"というtextです)を1回クリックして選択してから、
右マウスボタン(またはControllキー+左マウスボタン)でドラッグして、
右側の画面のViewController2.swift の
class ViewController2: UIViewController {
の下の行まで持っていきます。
ConnectionはAction, Name は tapBack として Connect をクリックしましょう。

-
ViewController2.swift に
@IBAction func tapBack(sender: AnyObject) {
}
という2行が追加されます。

- ViewController2.swift を変更します。
- 現在一番上にあるViewを取り除いて、その直下にあるViewを表示するコードを書き加えます。
ViewController2.swiftに追加するコード(赤字部分) |
授業で配布するプリントを参照して下さい。
|
- Xcodeを起動中にiOSデバイスを Mac に接続すると、
Xcode のstatusに
"Processing symbol files"

と表示されて、しばらく待つと
左上の実行デバイスに
接続したiOSデバイスの名前が表示される。
これを選択して実行する。

-
サンプルのプロジェクトはこちら。(Xcode 8.3.2版)