Last active
February 3, 2016 13:42
-
-
Save ArtemSyzonenko/2c19c1720a4b7d39b756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dependencies:
crypto: any
http: any
jsonx: any