forked from suquark/Hackathon2015
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectColor.py
More file actions
25 lines (23 loc) · 728 Bytes
/
DetectColor.py
File metadata and controls
25 lines (23 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import picamera
import requests
import tempfile
import time
url = "https://api.projectoxford.ai/vision/v1/analyses?Color"
headers = {'Ocp-Apim-Subscription-Key': "INPUT YOUR API KEY HERE"}
camera = picamera.PiCamera()
camera.video_stabilization = True
LastColor = None
while True:
f = tempfile.NamedTemporaryFile(delete=True, suffix='.jpg', prefix='camera')
camera.capture(f.name)
files = {'file': open(f.name, 'rb')}
r = requests.post(url, files=files, headers=headers)
data = json.loads(r.text)
color = data["color"]["dominantColorBackground"]
if (color != LastColor):
print(u"报警!");
LastColor = color
time.sleep(1)