0
我想將USB網絡攝像機與Raspberry Pi3相集成,並將拍攝的圖像發送到Google Cloud Vision以檢測物體。任何Python 3庫的做法都一樣嗎?
我已經成功地使用"Motion"
任何類似丕相機庫我的網絡攝像頭和能夠通過URL的視頻流,或者可以讓我在上面提到的動態庫前進。會有很大的幫助。使用Google Cloud Vision檢測物體的Raspberry Pi3網絡攝像機
我想將USB網絡攝像機與Raspberry Pi3相集成,並將拍攝的圖像發送到Google Cloud Vision以檢測物體。任何Python 3庫的做法都一樣嗎?
我已經成功地使用"Motion"
任何類似丕相機庫我的網絡攝像頭和能夠通過URL的視頻流,或者可以讓我在上面提到的動態庫前進。會有很大的幫助。使用Google Cloud Vision檢測物體的Raspberry Pi3網絡攝像機
做:)
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)