Я реализую API Google Cloud Vision по этой ссылке.
Ниже приведен мой код, в котором я получаю исключение:
private void callCloudVision(final Bitmap bitmap) throws IOException {
new AsyncTask() {
@Override
protected String doInBackground(Object... params) {
try {
List requests = new ArrayList();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
ByteString imgBytes = ByteString.readFrom(bs);
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Feature.Type.WEB_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
***//Getting exception here at the time of execution...***
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.printf("Error: %s\n", res.getError().getMessage());
return "";
}
System.out.println("\nPages with matching images: Score\n==");
for (WebDetection.WebPage page : annotation.getPagesWithMatchingImagesList()) {
System.out.println(page.getUrl() + " : " + page.getScore());
}
}
}
return "";
} catch (Exception e) {
Log.d("LOG_TAG", "Request failed: " + e.getMessage());
return "Cloud Vision API request failed.";
}
}
protected void onPostExecute(String result) {
}
}.execute();
}
Я получаю сообщение об ошибке
java.io.IOException: приложение по умолчанию Учетные данные недоступны. Они доступны при работе в Google Compute Engine. В противном случае необходимо определить переменную среды GOOGLE_APPLICATION_CREDENTIALS, указывающую на файл, определяющий учетные данные. Дополнительную информацию см. на странице https://developers.google.com/accounts/ ... redentials.
Мой graddle< /p>
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.+'
**compile 'com.google.cloud:google-cloud-vision:1.21.0'**
compile group: 'com.google.apis', name: 'google-api-services-sqladmin', version: 'v1beta4-rev52-1.23.0'
compile('com.google.api-client:google-api-client-android:1.22.0') {
exclude module: 'httpclient'
exclude group: 'com.google.guava'
}
compile('com.google.http-client:google-http-client-gson:1.20.0') {
exclude module: 'httpclient'
exclude group: 'com.google.guava'
}
Подробнее здесь: https://stackoverflow.com/questions/493 ... pi-android
Как авторизовать Google Cloud Vision API Android ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1722679459
Anonymous
Я реализую API Google Cloud Vision по этой ссылке.
Ниже приведен мой код, в котором я получаю исключение:
private void callCloudVision(final Bitmap bitmap) throws IOException {
new AsyncTask() {
@Override
protected String doInBackground(Object... params) {
try {
List requests = new ArrayList();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
ByteString imgBytes = ByteString.readFrom(bs);
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Feature.Type.WEB_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
***//Getting exception here at the time of execution...***
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.printf("Error: %s\n", res.getError().getMessage());
return "";
}
System.out.println("\nPages with matching images: Score\n==");
for (WebDetection.WebPage page : annotation.getPagesWithMatchingImagesList()) {
System.out.println(page.getUrl() + " : " + page.getScore());
}
}
}
return "";
} catch (Exception e) {
Log.d("LOG_TAG", "Request failed: " + e.getMessage());
return "Cloud Vision API request failed.";
}
}
protected void onPostExecute(String result) {
}
}.execute();
}
Я получаю сообщение об ошибке
java.io.IOException: приложение по умолчанию Учетные данные недоступны. Они доступны при работе в Google Compute Engine. В противном случае необходимо определить переменную среды GOOGLE_APPLICATION_CREDENTIALS, указывающую на файл, определяющий учетные данные. Дополнительную информацию см. на странице https://developers.google.com/accounts/docs/application-default-credentials.
Мой graddle< /p>
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.+'
**compile 'com.google.cloud:google-cloud-vision:1.21.0'**
compile group: 'com.google.apis', name: 'google-api-services-sqladmin', version: 'v1beta4-rev52-1.23.0'
compile('com.google.api-client:google-api-client-android:1.22.0') {
exclude module: 'httpclient'
exclude group: 'com.google.guava'
}
compile('com.google.http-client:google-http-client-gson:1.20.0') {
exclude module: 'httpclient'
exclude group: 'com.google.guava'
}
Подробнее здесь: [url]https://stackoverflow.com/questions/49376836/how-to-authorize-google-cloud-vision-api-android[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия