Skip to content
Snippets Groups Projects
Commit 9b8f9782 authored by Vesa Halenius's avatar Vesa Halenius
Browse files

Upload New File

parent 63cdd960
Branches
Tags
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():
# 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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment