Skip to content
Snippets Groups Projects
Commit 19c2f20a authored by Markus Willman's avatar Markus Willman
Browse files

delete file

parent 5cdc7982
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 20 21:33:57 2018
@author: veskuh
"""
import cv2
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
import os
# Haarcascade for face detection
face_cascade = cv2.CascadeClassifier("./haarcascade/haarcascade_frontalface_default.xml")
# Image file name and location
image = "./images/image.jpg"
# Sending image to server
def sendImage(image):
# Send local image file to tensorflow-client
multipart_data = MultipartEncoder(
fields={
# a file upload field
"image": ("image.jpg", open(image, "rb"), "image/jpg"),
"stop_code": "Test"
}
)
requests.post("http://tensorflow.stop.capstone.utu.fi/api/v1/classifyImage/", data=multipart_data,
headers={"Content-Type": multipart_data.content_type})
# Removing image for security purposes
def removeImage(image):
os.remove(image)
# Taking a picture from default webcam and saving it
def takePicture(image, face_cascade):
# Take picture
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
cv2.imwrite(image,frame)
cap.release()
# Locate faces
image = cv2.imread(image)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)
return len(faces)
facesDetected = takePicture(image, face_cascade)
if facesDetected > 0:
print ("Faces detected: " + str(facesDetected))
sendImage(image)
removeImage(image)
#
#
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment