This file contains 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
class FaceDetector(private val callback: DetectorCallback?) : IFrameProcessor { | |
interface DetectorCallback { | |
fun onSuccess(frameData: ByteBuffer, results: List<FirebaseVisionFace>, frameMetadata: FrameMetadata) | |
fun onFailure(exception: Exception) | |
} | |
companion object { | |
private const val TAG = "FaceDetector" | |
} |
This file contains 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
// Expected json response from webservice | |
//{ | |
// "payload": [ | |
// { | |
// "classification": { | |
// "score": 0.87991875 | |
// }, | |
// "displayName": "Andy" | |
// } | |
// ] |
This file contains 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
// Expected json payload for webservice. | |
// { | |
// "payload": { | |
// "image": { | |
// "imageBytes": "YOUR_IMAGE_BYTE" | |
// } | |
// } | |
// } | |
data class CloudAutoMLModel(val payload: Payload) |
This file contains 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 getRESTService(): CloudAutoMLService { | |
val gsonFactory = GsonConverterFactory | |
.create(GsonBuilder().create()) | |
val networkClient = OkHttpClient.Builder() | |
.addInterceptor(HttpLoggingInterceptor().apply { | |
level = HttpLoggingInterceptor.Level.BODY | |
}) | |
.build() |
This file contains 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
companion object { | |
private const val PROJECT = "devnibbles" | |
private const val LOCATION = "us-central1" | |
private const val MODEL = "ICN3704829353327390855" | |
private const val ACCESS_TOKEN = "<insert token here>" | |
} | |
fun classifyUsingRetrofit(faceId: Int, imageBytes: ByteArray) { | |
launch(errorHandler) { | |
// Show loading indicator while we wait for the request. |
This file contains 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
companion object { | |
private const val PROJECT = "devnibbles" | |
private const val LOCATION = "us-central1" | |
private const val MODEL = "ICN3704829353327390855" | |
private const val SERVICE_ACCOUNT_JSON = "<insert json here>" | |
} | |
private val mServiceCredentials = ServiceAccountCredentials | |
.fromStream(ByteArrayInputStream(SERVICE_ACCOUNT_JSON.toByteArray(Charset.defaultCharset()))) | |
.createScoped(mutableListOf("https://www.googleapis.com/auth/cloud-platform")) |
This file contains 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 onNewItem(faceId: Int, item: Face) { | |
mFaceGraphic = FaceGraphic(faceId, mGraphicOverlay) | |
mDetector.lastFrame?.let { frame -> | |
// Lets try and find out who this face belongs to | |
mViewModel.classify(faceId, frame.convertToByteArray()) | |
} | |
} |
This file contains 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 lateinit var mViewModel: CloudAutoMLViewModel | |
override fun onCreate(icicle: Bundle?) { | |
super.onCreate(icicle) | |
mViewModel = ViewModelProviders.of(this).get(CloudAutoMLViewModel::class.java) | |
mViewModel.subscribeClassifications() | |
.observe(this, Observer<Resource<Pair<Int, String>, Throwable>> { resource -> | |
when (resource) { | |
is LoadingResource -> { |
This file contains 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
import android.graphics.Typeface | |
import androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.BoxWithConstraints | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.RowScope | |
import androidx.compose.foundation.layout.fillMaxHeight | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.runtime.Composable |
This file contains 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
import androidx.compose.animation.core.FastOutSlowInEasing | |
import androidx.compose.animation.core.animateFloatAsState | |
import androidx.compose.animation.core.tween | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.BoxWithConstraints | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.RowScope | |
import androidx.compose.foundation.layout.fillMaxHeight | |
import androidx.compose.foundation.layout.fillMaxSize |