-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compare from base64 image #12
Comments
imglib.Image _convertCameraImage(
CameraImage image, CameraLensDirection _dir) {
int width = image.width;
int height = image.height;
// imglib -> Image package from https://pub.dartlang.org/packages/image
var img = imglib.Image(width, height); // Create Image buffer
const int hexFF = 0xFF000000;
final int uvyButtonStride = image.planes[1].bytesPerRow;
final int uvPixelStride = image.planes[1].bytesPerPixel!;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
final int uvIndex =
uvPixelStride * (x / 2).floor() + uvyButtonStride * (y / 2).floor();
final int index = y * width + x;
final yp = image.planes[0].bytes[index];
final up = image.planes[1].bytes[uvIndex];
final vp = image.planes[2].bytes[uvIndex];
// Calculate pixel color
int r = (yp + vp * 1436 / 1024 - 179).round().clamp(0, 255);
int g = (yp - up * 46549 / 131072 + 44 - vp * 93604 / 131072 + 91)
.round()
.clamp(0, 255);
int b = (yp + up * 1814 / 1024 - 227).round().clamp(0, 255);
// color: 0x FF FF FF FF
// A B G R
img.data[index] = hexFF | (b << 16) | (g << 8) | r;
}
}
var img1 = (_dir == CameraLensDirection.front)
? imglib.copyRotate(img, -90)
: imglib.copyRotate(img, 90);
return img1;
}
String _recog(imglib.Image img) {
List input = imageToByteListFloat32(img, 112, 128, 128);
input = input.reshape([1, 112, 112, 3]);
List output = List.filled(1 * 192, null, growable: false).reshape([1, 192]);
interpreter.run(input, output);
output = output.reshape([192]);
e1 = List.from(output);
return compare(e1!).toUpperCase();
}
String compare(List currEmb) {
if (data.length == 0) return "No Face saved";
double minDist = 999;
double currDist = 0.0;
String predRes = "NOT RECOGNIZED";
for (String label in data.keys) {
currDist = euclideanDistance(data[label], currEmb);
if (currDist <= threshold && currDist < minDist) {
minDist = currDist;
predRes = label;
}
}
// print(minDist.toString() + " " + predRes);
return predRes;
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I'm trying compare image from base64 with the camera, but I'm stuck in this step:
and compare Lists, where currEmb is my face detection from camera:
but always return NOT RECOGNIZED. Any sugestion for recognize from base64?
The text was updated successfully, but these errors were encountered: