Ошибка API Google Cloud Vision: Неизвестно: Нет Поток удален - PullRequest
0 голосов
/ 06 июня 2019

Я написал программу для обнаружения животных, используя Cloud Vision API для обнаружения объекта захваченного изображения с камеры Raspberry Pi.Если есть животное, прервите процесс отправки электронной почты и смс с изображением.Мой скрипт на Python работает просто отлично, но иногда случайно я получаю странную ошибку, такую ​​как:

Unknown: None Stream removed. 

Как я могу исправить эту ошибку и сделать мою программу более стабильной?

Мой код:

def detectImage(self, image_name):
    path = '/home/pi/project/pictures/' + image_name
    max_results=1
    with open(path, 'rb') as image_file:
        content = image_file.read()
    image = vision.types.Image(content=content)
    objects = client.object_localization(image=image, max_results=max_results).localized_object_annotations
    image_file.close()
    for object_ in objects:
        if (object_.name == 'Animal' or object_.name == 'Cat' or object_.name == 'Dog' or object_.name == 'Bird' or object_.name == 'Insect'):
            print ('False Alarm: This is an animal!')
            if os.path.exists('/home/pi/project/pictures/' + image_name):
                os.remove('/home/pi/project/pictures/'+image_name) #Deletes the taken picture in case of False Alarm
                print 'File', image_name, 'has beeen deleted'
        else:
            Process(target=interact().takePicture(image_name)).start()
            print('Not an animal!')

Ошибка:

Process Process-2:
Traceback (most recent call last):

  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()

  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)

  File "startup.py", line 70, in pir
    Process(target=interact().detectImage(image_name)).start()   #Start the procedure for animal detection.

  File "/home/pi/project/functions.py", line 305, in detectImage
    objects = client.object_localization(image=image, max_results=max_results).localized_object_annotations

  File "/usr/local/lib/python2.7/dist-packages/google/cloud/vision_helpers/decorators.py", line 101, in inner
    response = self.annotate_image(request, retry=retry, timeout=timeout)

  File "/usr/local/lib/python2.7/dist-packages/google/cloud/vision_helpers/__init__.py", line 72, in annotate_image
    r = self.batch_annotate_images([request], retry=retry, timeout=timeout)

  File "/usr/local/lib/python2.7/dist-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 234, in batch_annotate_images
    request, retry=retry, timeout=timeout, metadata=metadata

  File "/usr/local/lib/python2.7/dist-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)

  File "/usr/lib/python2.7/dist-packages/six.py", line 737, in raise_from
    raise value
Unknown: None Stream removed
...