# -*- coding:utf8 -*-
import cv
import cv2
import time
import json
#import pygame
#import pickle
import requests
import numpy as np
from PIL import Image
import win32com.client
import matplotlib.pyplot as plt
cap = cv2.VideoCapture(0)
index = 0
while True:
ret,frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(500) :
cv2.imwrite("face.jpg",frame)
index = index + 1
print"截图成功"
url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'
files = {'image_file':open('F:\\code\\face.jpg', 'rb')}
payload = {'api_key': 'l5E2ZGh_s6ts4MKFrGfa9uA2kcJXuf-A',
'api_secret': 'eGYbKZsgNAaTBCE5mIX2DyMFEwDqrvnD',
'return_landmark': 0,
'return_attributes':'gender,age,smiling,facequality,glass'}
c = requests.post(url,files=files,data=payload)
data=json.loads(c.text)
print c.text
l = c
f = open('test.txt','w')
f.writelines(l)
f.close()
if cv2.waitKey(2) :
break
cap.release()
cv2.destroyAllWindows()