Vinicius Carvalho
09/24/2018, 1:54 PMcameraSource.takePicture({}, { bytes -> detectFaces(bytes) })
fun detectFaces(bytes: ByteArray) {
launch(CommonPool) {
val faces = facesClient.detect(bytes.inputStream(), true, false, arrayOf(FaceServiceClient.FaceAttributeType.Age))
val results = facesClient.identity("family", faces.map { it.faceId }.toTypedArray(), 4)
results.forEach { r ->
val name = personMap[r.candidates[0].personId.toString()]
Log.i(TAG,"Found $name")
}
}
}
gildor
09/24/2018, 2:39 PMVinicius Carvalho
09/24/2018, 2:44 PMgildor
09/24/2018, 2:45 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) {}
Vinicius Carvalho
09/24/2018, 2:46 PMgildor
09/24/2018, 2:46 PMVinicius Carvalho
09/24/2018, 2:47 PMgildor
09/24/2018, 2:47 PMVinicius Carvalho
09/24/2018, 2:50 PMsuspend fun detectFaces(bytes: ByteArray)
withContext(<http://Dispatchers.IO|Dispatchers.IO>){ detectFaces(...)
is that what you are saying?gildor
09/24/2018, 3:17 PMsuspend fun detectFaces(): SomeResult = withContext(IO) {
//Some blocking code that returns SomeResult
}
Vinicius Carvalho
09/24/2018, 11:09 PMTracker
, it seems that the source can create as many Tracker instances as it wants, I first thought the Tracker to be a single instance per CameraSourceval cameraCallback: (ByteArray) -> Unit = { bytes ->
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
val results = detectFaces(bytes)
results.forEach {
Log.i(TAG, "Person: ${personMap[it.candidates[0].personId.toString()]}")
}
}
}
gildor
09/25/2018, 12:50 AMVinicius Carvalho
09/25/2018, 2:22 AMgildor
09/25/2018, 2:24 AMseems that the Tracker reference gets destroyed before the connection and the suspended function endsSure, because you have callback, so coroutine is destroyd.
Vinicius Carvalho
09/25/2018, 2:24 AMgildor
09/25/2018, 2:24 AMI’m positive that it has to be due some object being reclaimed by the GC, and the context that holds the thread that was running being destroyed before it finishesIf you keep reference on this object, GC cannot collect it
Vinicius Carvalho
09/25/2018, 2:26 AMgildor
09/25/2018, 2:27 AMVinicius Carvalho
09/25/2018, 2:27 AMTracker
that is the class with the method that has an event when a face is foundgildor
09/25/2018, 2:28 AMVinicius Carvalho
09/25/2018, 2:29 AMgildor
09/25/2018, 2:30 AMVinicius Carvalho
09/25/2018, 2:35 AMgildor
09/25/2018, 2:50 AMVinicius Carvalho
09/25/2018, 1:15 PMgildor
09/25/2018, 1:26 PM