Created
April 5, 2020 01:46
-
-
Save kiwiandroiddev/5f49317353e54988a4de8604cbdb6f9c to your computer and use it in GitHub Desktop.
Decode an Android test resource image as an OpenCV Mat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Uses OpenCV to decode an image that is an android test resource i.e. | |
* a file from `src/androidTest/resources`. | |
* Note that the resulting Mat will be empty if there was a problem loading the file. | |
*/ | |
private fun loadOpenCvImage(testResourceFilename: String): Mat { | |
val bytes: ByteArray = javaClass.classLoader!!.getResource(testResourceFilename).readBytes() | |
val matOfByte = MatOfByte().apply { fromList(bytes.toList()) } | |
return Imgcodecs.imdecode(matOfByte, CV_LOAD_IMAGE_COLOR) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment