【发布时间】:2022-01-20 11:08:39
【问题描述】:
我正在使用颤振,我试图从我之前设置的 shared_preferences 中获取一个值,并将其显示在一个文本小部件中。但获取 Future 的实例而不是值。这是我的代码:
String _recog(imglib.Image img) {
List input = imageToByteListFloat32(img, 112, 128, 128);
input = input.reshape([1, 112, 112, 3]);
List output = List(1 * 192).reshape([1, 192]);
interpreter.run(input, output);
output = output.reshape([192]);
e1 = List.from(output);
return compare(e1).toString();
}
Future<String> compare(List currEmb) async {
var firdoc = await _firestore
.collection('allfaces')
.doc(_auth.currentUser.uid)
.collection('faces')
.get();
if (data.length == 0) return Future.value("No Face saved");
double minDist = 999;
double currDist = 0.0;
String predRes = "NOT RECOGNIZED";
for (var doc in firdoc.docs) {
currDist = 0.0;
for (int i = 0; i < currEmb.length; i++) {
currDist += (currEmb[i] - doc.data()['embedding'][i]).abs().toDouble();
}
if (currDist < minDist) {
minDist = currDist;
predRes = doc.data()['name'];
}
}
print(minDist.toString() + " " + predRes);
return predRes;
}
【问题讨论】:
-
欢迎来到 Stack Overflow。您在这里遇到的具体问题是什么?预期的行为是什么,实际的行为是什么?
-
您在寻找
return await compare(e1)吗? -
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
标签: android firebase flutter dart google-cloud-firestore