def train(request):
# check to see if this is a GET request
if request.method == "GET":
# check to see if an image was uploaded
if request.GET.get("imageBase64", None) is not None and request.GET.get("user", None) is not None :
# grab the uploaded image
image = _grab_image(base64_string=request.GET.get("imageBase64", None))
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
rects = detector.detectMultiScale(image, scaleFactor=1.1, minNeighbors=5,
minSize=(30, 30), flags=0)
# construct a list of bounding boxes from the detection
rects = [(int(x), int(y), int(x + w), int(y + h)) for (x, y, w, h) in rects]
if len(rects) == 0:
return JsonResponse({"error" : "No faces detected"})
else :
x, y, w, h = rects[0]
cv2.imwrite( TRAINED_FACES_PATH + "/" + str(request.GET.get("user", None)) + "/" + str(uuid.uuid4()) + ".jpg", image[y:h, x:w] );
return JsonResponse({"success" : True})
评论列表
文章目录