Skip to content

Instantly share code, notes, and snippets.

@ArtemSyzonenko
Last active February 3, 2016 13:42
Show Gist options
  • Save ArtemSyzonenko/2c19c1720a4b7d39b756 to your computer and use it in GitHub Desktop.
Save ArtemSyzonenko/2c19c1720a4b7d39b756 to your computer and use it in GitHub Desktop.
library vision;
import 'dart:io';
import 'package:crypto/crypto.dart';
import 'package:http/http.dart' as http;
import 'package:jsonx/jsonx.dart';
encodeFile(file) {
var contents = new File(file).readAsBytesSync();
String encoded = CryptoUtils.bytesToBase64(contents);
return encoded;
}
main() async {
String filepath = "/path/124015.jpg";
var content = encodeFile(filepath);
Map data = {
'requests': {
'image': {'content': content},
'features': {'type': 'LABEL_DETECTION', 'maxResults': 20}
}
};
String jsonData = encode(data);
var url = "https://vision.googleapis.com/v1alpha1/images:annotate?key=your-key";
var response = await http.post(
url, headers: {'Content-Type': 'application/json'}, body: jsonData);
Map parsedJson = decode(response.body);
List dig = parsedJson["responses"][0]["labelAnnotations"];
String keywords = "";
for (var i in dig) {
keywords = keywords + i["description"] + ", ";
}
String enhanced = keywords.replaceRange(keywords.length - 2, keywords.length, "");
print(enhanced);
}
@ArtemSyzonenko
Copy link
Author

dependencies:
crypto: any
http: any
jsonx: any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment