Skip to content

Instantly share code, notes, and snippets.

View MCarlomagno's full-sized avatar
🚀

Marcos Carlomagno MCarlomagno

🚀
  • OpenZeppelin
  • Rosario - Argentina
View GitHub Profile
double _euclideanDistance(List e1, List e2) {
double sum = 0.0;
for (int i = 0; i < e1.length; i++) {
sum += pow((e1[i] - e2[i]), 2);
}
return sqrt(sum);
}
_cameraService.cameraController.startImageStream((image) async {
...
try {
/// returns a list of faces, but for our propose we just need the first one detected
List<Face> faces = await _mlVisionService.getFacesFromImage(image);
...
} catch (e) {
...
}
}
setCurrentPrediction(CameraImage cameraImage, Face face) {
/// crops the face from the image and transforms it to an array of data
List input = _preProcess(cameraImage, face);
/// then reshapes input and ouput to model format 🧑‍🔧
input = input.reshape([1, 112, 112, 3]);
List output = List(1 * 192).reshape([1, 192]);
/// runs the interpreter and produces the output 🤖
this._interpreter.run(input, output);
// Example object result
{
"score": 0.32371445304906,
"keypoints": [
...
{
"position": {
"y": 113.9603729248,
"x": 393.19735717773
// right and left wrists are the objects given by the model
const rx = rightWrist.position.x;
const ry = rightWrist.position.y;
const lx = leftWrist.position.x;
const ly = leftWrist.position.y;
// vertical and horizontal distance
var dy = ly - ry;
var dx = lx - rx;
// calculate angle
let angle = 0.0;
angle = angleBetween(wrists);
// right condition
if(angle < -25) {
turnRight();
toRight = true;
toLeft = false;
} else if(toRight) {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var startGame = () => {
var options = {
arena: {
arena: mk.arenas.types.THRONE_ROOM
},
fighters: [{ name: 'Subzero' }, { name: 'Kano' }],
gameType: 'multiplayer'
};
var getState = function (index) {
var me = mk.game.fighters[index]
// 0 === false and 1 === true in js conditionals
var opponent = index ? mk.game.fighters[0] : mk.game.fighters[1];
var myLife = me._life;
var opponentLife = opponent._life;
var myPosition = me._position;
subzeroActions = {
RIGHT: 39, // right arrow
LEFT : 37, // left arrow
UP : 38, // up arrow
DOWN : 40, // down arrow
BLOCK: 81, // Q
HP : 65, // A
LP : 83, // S
LK : 68, // D
HK : 70 // F