【问题标题】:Web Camera with Raspberry Pi3 to detect objects using Google Cloud Vision带有 Raspberry Pi3 的网络摄像头使用 Google Cloud Vision 检测对象
【发布时间】:2017-07-25 06:57:33
【问题描述】:
我想将 USB 网络摄像头与 Raspberry Pi3 集成,并将捕获的图像发送到 Google Cloud Vision 以检测对象。有任何 Python 3 库可以做同样的事情吗?
我已经成功集成了我的网络摄像头,并且能够使用"Motion" 通过 URL 流式传输视频
任何类似于 Pi Camera 或可以让我从上述 Motion 库中前进的库。会有很大帮助的。
【问题讨论】:
标签:
python
camera
raspberry-pi
google-cloud-platform
google-cloud-vision
【解决方案1】:
完成:)
import pygame
import pygame.camera
import time
import base64
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
pygame.camera.init()
pygame.camera.list_cameras()
cam = pygame.camera.Camera("/dev/video0", (640, 480))
cam.start()
time.sleep(0.1)
img = cam.get_image()
if file:
pygame.image.save(img, file)
else:
pygame.image.save(img, "img_captured.jpg")
cam.stop()
credentials = GoogleCredentials.get_application_default()
service = discovery.build('vision', 'v1', credentials=credentials)
with open('img_captured.jpg', 'rb') as image:
image_content = base64.b64encode(image.read())
service_request = service.images().annotate(body={
'requests': [{
'image': {
'content': image_content.decode('UTF-8')
},
'features': [{
'type': 'LOGO_DETECTION',
'maxResults': 1
}]
}]
})
response = service_request.execute()
try:
label = response['responses'][0]['logoAnnotations'][0]['description']
except:
label = "No response."
print("Detected -->" + label)