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
init { | |
imgData = ByteBuffer.allocateDirect( | |
DIM_BATCH_SIZE | |
* imageSizeX | |
* imageSizeY | |
* DIM_PIXEL_SIZE // 3 | |
* numBytesPerChannel | |
) | |
imgData!!.order(ByteOrder.nativeOrder()) | |
} |
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
fun setDrawPoint( | |
point: Array<FloatArray>, | |
ratio: Float | |
) { | |
var tempX: Float | |
var tempY: Float | |
for (i in 0..13) { | |
tempX = point[0][i] / ratio / mRatioX | |
tempY = point[1][i] / ratio / mRatioY | |
mDrawPoint.add(PointF(tempX, tempY)) |
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
override fun runInference() { | |
val tempArray = FloatArray(outputW * outputH) | |
val outTempArray = FloatArray(outputW * outputH) | |
for (i in 0..13) { | |
// doing filtering and getting maximum possibility for key points. | |
mPrintPointArray!![0][i] = maxX | |
mPrintPointArray!![1][i] = maxY | |
} | |
} |
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
override fun runInference() { | |
tflite?.run(imgData!!, heatMapArray) | |
mPrintPointArray = Array(2) { FloatArray(14) } | |
// Gaussian Filter 5*5 | |
mMat = Mat(outputW, outputH, CvType.CV_32F) | |
val tempArray = FloatArray(outputW * outputH) | |
val outTempArray = FloatArray(outputW * outputH) | |
} |
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
fun addPixelValue(pixelValue: Int) { | |
val red = (pixelValue and 0x00FF0000 shr 16) / 255f * 2.0f - 1.0f | |
val green = (pixelValue and 0x0000FF00 shr 8) / 255f * 2.0f - 1.0f | |
val blue = (pixelValue and 0x000000FF) / 255f * 2.0f - 1.0f | |
} |
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
fun addPixelValue(pixelValue: Int) { | |
//bgr | |
imgData!!.putFloat((pixelValue and 0xFF).toFloat()) | |
imgData!!.putFloat((pixelValue shr 8 and 0xFF).toFloat()) | |
imgData!!.putFloat((pixelValue shr 16 and 0xFF).toFloat()) | |
} |
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
/** Writes Image data into a `ByteBuffer`. */ | |
private fun convertBitmapToByteBuffer(bitmap: Bitmap) { | |
imgData!!.rewind() | |
// intValues are input image size memory like IntArray(bitmap.width * bitmap.height) | |
bitmap.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height) | |
// Convert the image to floating point. | |
var pixel = 0 | |
for (i in 0 until imageSizeX) { | |
for (j in 0 until imageSizeY) { | |
val v = intValues[pixel++] |
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
@Throws(IOException::class) | |
private fun loadModelFile(activity: Activity): MappedByteBuffer { | |
// modelPath would be something like "image_classifier.tflite" | |
val fileDescriptor = activity.assets.openFd(modelPath) | |
val inputStream = FileInputStream(fileDescriptor.fileDescriptor) | |
val fileChannel = inputStream.channel | |
val startOffset = fileDescriptor.startOffset | |
val declaredLength = fileDescriptor.declaredLength | |
return fileChannel.map(MapMode.READ_ONLY, startOffset, declaredLength) | |
} |
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
fun create( | |
activity: Activity, | |
imageSizeX: Int = 192, | |
imageSizeY: Int = 192, | |
outputW: Int = 96, | |
outputH: Int = 96, | |
modelPath: String = "model.tflite", | |
numBytesPerChannel: Int = 4 | |
): ImageClassifierFloatInception = | |
ImageClassifierFloatInception( |
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
private fun classifyFrame() { | |
// Get a bitmap with requested width and height. | |
// Also, this bitmap uses ARGB_8888 format. | |
val bitmap = textureView!!.getBitmap(classifier!!.imageSizeX, classifier!!.imageSizeY) | |
// This classifier's function internally has the byte data converted from this bitmap. | |
classifier!!.classifyFrame(bitmap) | |
bitmap.recycle() | |
// mPrintPointArray is the output(results) of inference from input(byte data above) | |
drawView!!.setDrawPoint(classifier!!.mPrintPointArray!!, 0.5f) | |
} |
NewerOlder