-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathineko.py
43 lines (40 loc) · 1.04 KB
/
ineko.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# coding=utf-8
import requests
import json
import os
import cv2
import time
def recogn_face(img_url):
# Loading cat-face detector
cat_path = 'haarcascade_frontalcatface.xml'
cat_path = 'C:\\Users\\zbzha\\Documents\\iNeko\\haarcascade_frontalcatface.xml'
face_cascade = cv2.CascadeClassifier(cat_path)
img = requests.get(img_url)
fname = 'temp.jpg'
f = open(fname, 'wb')
f.write(img.content)
f.close()
img = cv2.imread(fname)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(
gray,
scaleFactor=1.02,
minNeighbors=3,
minSize=(150, 150),
flags=cv2.CASCADE_SCALE_IMAGE
)
os.remove(fname)
if faces == ():
return "NULL"
for (x, y, w, h) in faces:
cut_img = img[y: y + h, x: x + w]
path = '/' + str(time.time()) + '.jpg'
cv2.imwrite(path, cut_img)
# print(response)
return {
'cut_img': '/' + path,
'x': str(x),
'y': str(y),
'w': str(w),
'h': str(h)
}