LoginSignup
3
4

More than 5 years have passed since last update.

【手順】AndroidアプリにOpenCVModuleを組み込む「Kotlin編」

Posted at

目次

  • 開発環境
  • 手順
  • おわりに

手順

  1. openCVモジュールをプロジェクト内にインポートする。
  2. 各モジュール(appとopenCV)のcompileとbuildバージョンを合わせる。
  3. OpenCVライブラリをappモジュールに組み込む。
  4. appモジュールの依存関係にopenCVモジュールを追加する。

1. openCVモジュールをプロジェクト内にインポートする。

2. 各モジュール(appとopenCV)のcompileとbuildバージョンを合わせる。

3. OpenCVライブラリをappモジュールに組み込む。

4. appモジュールの依存関係にopenCVモジュールを追加する。

おわりに

  1. ソースコード
  2. 実行結果

1. ソースコード

MainActivit.kt
package and.syun.com.kotlinwithopencv001

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView

import org.opencv.android.OpenCVLoader

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

        val versionString :String = openCVVersionString(OpenCVLoader.initDebug())
        findViewById<TextView>(R.id.text_view).text = versionString
    }

    private fun openCVVersionString(arg: Boolean): String {
        when (arg) {
            true -> return "OpenCV Version: "+OpenCVLoader.OPENCV_VERSION
            false -> return "ERROR: OpenCV Load Failed"
        }
    }

}

2. 実行結果

3. かわいいアルパカ

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4