Ошибка сегментации с использованием Google Cloud Vision API - PullRequest
0 голосов
/ 12 февраля 2020

Здравствуйте. У меня проблема с использованием Google Cloud Vision API для обнаружения объектов. Ошибка ошибки сегментации возникла только тогда, когда я соединил свою функцию google vision (как вы видите ниже) с двумя другими функциями в длинном скрипте python. Если я использую только эту функцию в другом скрипте, она работает отлично. Как я могу это исправить?

from google.cloud import vision
client = vision.ImageAnnotatorClient()
path = '/home/pi/cat.jpg'
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
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!')
    else:
      print('Not an animal!')

В сочетании с двумя другими моими функциями:

  if (status == 'True'):
    print ("Correct passcode not entered, emailing picture and sounding alarm.")
        Process(target=interact().takePicture(image_name)).start()
def detectImage(self, image_name):
  from google.cloud import vision
  client = vision.ImageAnnotatorClient()
  path = '/home/pi/homesecurity/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
  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!')
        os.remove('/home/pi/homesecurity/pictures/' + image_name) #Deletes the taken picture.
        print 'File', image_name, 'has beeen deleted'
      else:
        print('Not an animal!')
        Process(target=interact().takePicture(image_name)).start()
def takePicture(self, image_name):
  image_path = '/home/pi/homesecurity/pictures/' + image_name  
  Process(target=interact().ftpSession, args=(queue, image_path, image_name)).start()  
  Process(target=interact().sendEmail, args=(queue, "Home Security System: Intruder Detected!", "See the attached picture.", image_path, database().getEmail())).start()   
  Process(target=interact().sendSms, args=(queue, "Home Security System: Intruder Detected!, please check your email.")).start()   
  GPIO.output(alarm,1)

...