【发布时间】:2019-11-20 07:51:41
【问题描述】:
我正在使用 Google Cloud Vision API 来检测从 pi 相机拍摄的图像,如果该图片被检测为动物,它将删除该图片,如果不是,它将运行另一个名为:takePicture(image_name) 的函数.我的脚本运行得非常好,但大多数时候我有一个奇怪的问题,叫做 Segmentation Fault,当这种情况发生时它不会中断我的 python 程序,但我的 4x4 键盘(连接到 RPi)停止工作并且自动创建 Python 程序的另一个循环进程,即使“键盘中断”仍在运行。
def detectImage(self, image_name):
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'
break
else:
Process(target=interact().takePicture(image_name)).start()
print('Not an animal!')
旧硬件有可能吗?因为我使用的是 Raspberry Pi Model B 和 python 2.7
pi@raspberrypi:~ $ cat /proc/cpuinfo
processor : 0
model name : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 697.95
Features : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7
Hardware : BCM2835
Revision : 000e
Serial : 0000000095fec982
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
【问题讨论】:
标签: python raspberry-pi segmentation-fault google-cloud-vision