diff --git a/client/sbs_client.py b/client/sbs_client.py new file mode 100644 index 0000000000000000000000000000000000000000..4e816444969b1fce314df9cc1dc2b618d6dc880e --- /dev/null +++ b/client/sbs_client.py @@ -0,0 +1,65 @@ +# -*- 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(): + # 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" + } + ) + + response = requests.post("http://tensorflow.stop.capstone.utu.fi/api/v1/classifyImage/&stop_code=test", data=multipart_data, + headers={"Content-Type": multipart_data.content_type}) + +# Removing image for security purposes +def removeImage(): + os.remove(image) + +# Taking a picture from default webcam and saving it +def takePicture(): + cap = cv2.VideoCapture(0) + + ret, frame = cap.read() + + # Trying to detect faces + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + faces = face_cascade.detectMultiScale(gray, 1.3, 5) + + for (x,y,w,h) in faces: + cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2) + roi_gray = gray[y:y+h, x:x+w] + roi_color = frame[y:y+h, x:x+w] + + x = 0 + y = 20 + text_color = (0,255,0) + + cv2.imwrite(image,frame) + cap.release() +# cv2.destroyAllWindows() + + + +takePicture() +sendImage() +removeImage()