How to use register_image method in localstack

Best Python code snippet using localstack_python

routes.py

Source:routes.py Github

copy

Full Screen

1from flask import request, redirect, render_template, jsonify2from app import app3import os4import io5from io import StringIO6from models import *7import face_recognition8import numpy as np9from PIL import Image10import pickle11import json12from mask_detection import give_predictions13from werkzeug.utils import secure_filename14from sendgrid import SendGridAPIClient15from sendgrid.helpers.mail import Mail16# def allowed_file(register_image):17# return '.' in register_image and register_image.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS18@app.route('/', methods=['GET','VIEW'])19def home():20 if request.method=='VIEW':21 return render_template('index.html')22 else:23 return jsonify({'message to the new User': 'Welcome to M-GAP, Go on to the registration page to begin your journey with us.'})24@app.route('/register', methods=['GET'])25def register():26 return jsonify({"API for Registration Page": "Fill in the details"})27 try:28 return render_template('register.html')29 except:30 return None31@app.route('/verify')32def verify():33 return render_template('verify.html')34@app.route('/result')35def result():36 return render_template('final.html')37@app.route('/send_details', methods=['POST', 'GET'])38def index():39 if request.method == 'POST':40 # posted_data = request.get_json()41 register_image = str(Image.open(request.files['register_image'], "r"))42 data = json.load(request.files['data'])43 name = data['name']44 email = data['email']45 gender = data['gender']46 age = data['age']47 contact = data['contact']48 face_encoding = data['face_encoding']49 # # name = request.form['demo-name']50 # # email = request.form['demo-email']51 # # gender = request.form['demo-gender']52 # # age = int(request.form['demo-age'])53 # # contact = request.form['demo-contact']54 # # face_encoding = np.array(json.loads(request.form['encoding'])) #TODO55 # image = request.files['image']56 # register_image = secure_filename(image.register_image)57 # register_image = request.form['register_image']58 new_User = User(name=name, email=email, gender=gender, age=age, contact=contact,59 register_image=register_image, face_encoding=face_encoding) # , face_encoding=pickle.dumps(face_encoding))register_image=register_image60 try:61 db.session.add(new_User)62 db.session.commit()63 # return redirect('/register')64 # return jsonify(username=g.user.name,65 # email=g.user.email,66 # id=g.user.id)67 return jsonify({'message': 'User has registered with all the details'})68 except Exception as e:69 print(e)70 return 'There was an issue adding the details of the User to your database'71 else:72 # users = User.query.order_by(User.id).all()73 # return render_template('register.html', users=users)74 return jsonify({'name': 'Enter name',75 'age': 'Enter Age',76 'contact': 'Enter contact',77 'email': 'Enter email',78 'register_image': 'Upload a high resolution picture of your face so that M-GAP can carry out Facial Recognition on it'})79@app.route('/send_email', methods=['POST'])80def sendmail():81 if request.method == 'POST':82 posted_data = request.get_json()83 user_name = posted_data['user_name']84 user_email = posted_data['user_email']85 message = Mail(86 from_email='maintaingap.safetytracker@gmail.com',87 to_emails=user_email,88 subject='You have been registered with M-GAP',89 html_content=f'Hi {user_name} !<br>Thank you for registering with us '90 )91 return jsonify({'response': 'The mail has been sent',92 'message': 'Hi ' + user_name + '! Thank you for registering with us'})93 try:94 sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))95 response = sg.send(message)96 return jsonify({'message': 'The mail has been sent to the user'})97 # print(response.body)98 # print(response.headers)99 except Exception as e:100 print(e)101@app.route('/verification_details', methods=['POST', 'PUT', 'PATCH', 'GET'])102def details():103 # temperature = float(request.form['demo-temp'])104 # try:105 # user_id = int(request.form['user-id'])106 # except:107 # user_id = None108 if request.method == 'POST':109 temperature = request.args.get('temperature')110 user_id = request.args.get('user_id')111 mask_detected = request.args.get('mask_detected', int)112 # mask_detected = bool(int(request.form['mask-detected']))113 if user_id:114 new_Scan = Scan(mask_detected, temperature, user_id)115 try:116 db.session.add(new_Scan)117 db.session.commit()118 if(new_Scan.temperature < 99.0 and new_Scan.mask_detected == 1):119 return render_template('verified.html', person=new_Scan.person)120 elif(new_Scan.temperature < 99.0 and new_Scan.mask_detected == 0):121 return render_template('notmask.html', person=new_Scan.person)122 elif(new_Scan.temperature > 99.0 and new_Scan.mask_detected == 1):123 return render_template('nottemp.html', person=new_Scan.person)124 else:125 return render_template('failed.html', person=new_Scan.person)126 except Exception as e:127 print(e)128 return 'There was an issue adding the details of the User to your database'129 else:130 if(temperature < 99.0 and mask_detected == 1):131 return render_template('noface.html')132 elif (temperature > 99.0 and mask_detected == 1):133 return render_template('notemp.html')134 elif (temperature < 99.0 and mask_detected == 0):135 return render_template('nomask.html')136 else:137 return render_template('notverified.html')138 if request.method == 'PATCH':139 temperature = request.args.get('temperature')140 user_id = request.args.get('user_id')141 mask_detected = request.args.get('mask_detected', int)142 if user_id:143 new_Scan = Scan(mask_detected, temperature, user_id)144 try:145 db.session.add(new_Scan)146 db.session.commit()147 if(new_Scan.temperature < 99.0 and new_Scan.mask_detected == 1):148 return render_template('verified.html', person=new_Scan.person)149 elif(new_Scan.temperature < 99.0 and new_Scan.mask_detected == 0):150 return render_template('notmask.html', person=new_Scan.person)151 elif(new_Scan.temperature > 99.0 and new_Scan.mask_detected == 1):152 return render_template('nottemp.html', person=new_Scan.person)153 else:154 return render_template('failed.html', person=new_Scan.person)155 except Exception as e:156 print(e)157 return 'There was an issue adding the details of the User to your database'158@app.route('/register-image', methods=['POST', 'GET'])159def register_face():160 if request.method == 'POST':161 image = request.files['webcam']162 image = np.array(Image.open(image))163 try:164 face_locations = face_recognition.face_locations(image)165 top, right, bottom, left = face_locations[0]166 face_image = image[top:bottom, left:right]167 face_encoding = face_recognition.face_encodings(face_image)168 dump = pickle.dumps(face_encoding[0])169 return jsonify(face_encoding[0].tolist())170 except:171 return jsonify([])172 if request.method == 'GET':173 image = request.files['webcam']174 image = np.array(Image.open(image))175 try:176 face_locations = face_recognition.face_locations(image)177 top, right, bottom, left = face_locations[0]178 face_image = image[top:bottom, left:right]179 face_encoding = face_recognition.face_encodings(face_image)180 dump = pickle.dumps(face_encoding[0])181 return jsonify({"Image encoding": face_encoding[0].tolist()})182 except:183 return jsonify({"Image encoding": "CREATED"})184@app.route('/verify-face', methods=['POST'])185def verify_face():186 image = request.files['webcam']187 image = np.array(Image.open(image))188 try:189 face_locations = face_recognition.face_locations(image)190 top, right, bottom, left = face_locations[0]191 face_image = image[top:bottom, left:right]192 face_encoding = face_recognition.face_encodings(face_image)193 all_users = User.query.all()194 face_encodings = [pickle.loads(user.face_encoding)195 for user in all_users]196 user_ids = [user.id for user in all_users]197 results = face_recognition.face_distance(198 face_encodings, face_encoding[0])199 best_match_index = np.argmin(results)200 if results[best_match_index] <= 0.35:201 verified_user_id = user_ids[best_match_index]202 print('Person Verified!', 'User ID:', verified_user_id)203 else:204 print(results[best_match_index])205 raise Exception206 return jsonify({'user_id': verified_user_id})207 except:208 print('No face detected!', flush=True)209 # return jsonify({'user_id': None})210 return jsonify({'Face Detected': 'Yes'})211@app.route('/verify-mask', methods=['POST'])212def verify_mask():213 image = request.files['webcam']214 mask_on = give_predictions(image)...

Full Screen

Full Screen

test_register_image.py

Source:test_register_image.py Github

copy

Full Screen

...11 return reference, image, -np.array(dydx)[::-1]12def test_error(data):13 reference, image, dxdy = data14 with pytest.raises(ValueError) as err:15 register_image(image, reference, maxshift=[1, 2, 3])16 assert "Invalid maxshift length" in str(err.value)17 with pytest.raises(ValueError) as err:18 register_image(image, reference, shift0=[1, 2, 3])19 assert "Invalid shift0 length" in str(err.value)20 with pytest.raises(ValueError) as err:21 register_image(image, reference[:-1])22 assert "Image shape does not match" in str(err.value)23def test_expected(data):24 reference, image, dxdy = data25 result = register_image(image, reference, upsample=1)26 assert np.allclose(result, [-2, -4]), 'pixel resolution'27 result = register_image(image, reference, upsample=10)28 assert np.allclose(result, dxdy), 'sub-pixel resolution'29def test_maxshift(data):30 reference, image, dxdy = data31 result = register_image(image, reference, maxshift=10)32 assert np.allclose(result, [-2, -4])33 result = register_image(image, reference, maxshift=5)34 assert np.allclose(result, [-2, -4])35 result = register_image(image, reference, maxshift=[0, 0])36 assert np.allclose(result, 0)37def test_shift0(data):38 reference, image, dxdy = data39 result = register_image(image, reference, shift0=dxdy)40 assert np.allclose(result, [-2, -4])41 result = register_image(image, reference, shift0=100, upsample=10)42 assert not np.allclose(result, [-2, -4])43def test_line():44 line1 = np.zeros((100, 1))45 line1[50] = 146 line2 = np.zeros((100, 1))47 line2[53] = 148 result = register_image(line1, line2)...

Full Screen

Full Screen

models.py

Source:models.py Github

copy

Full Screen

1from app import app2from datetime import datetime3from flask_sqlalchemy import SQLAlchemy4db = SQLAlchemy(app)5class User(db.Model):6 __tablename__ = "User"7 id = db.Column(db.Integer, primary_key=True)8 name = db.Column(db.String(255), nullable=False)9 email = db.Column(db.String(255), nullable=False)10 gender = db.Column(db.String(255), nullable=False)11 age = db.Column(db.Integer, nullable=False)12 contact = db.Column(db.String(255), nullable=False)13 face_encoding = db.Column(db.Text, nullable=True)14 register_image = db.Column(db.Text, nullable=False)15 scans = db.relationship('Scan', backref='person', lazy=True)16 def __init__(self, name, email, gender, age, contact, register_image, face_encoding):17 self.name = name18 self.email = email19 self.gender = gender20 self.age = age21 self.contact = contact22 self.register_image = register_image23 self.face_encoding = face_encoding24 def __repr__(self):25 return '<User %r %r %r %r %r' % (self.name, self.email, self.gender, self.age, self.contact, self.register_image)26class Scan(db.Model): 27 __tablename__ = "Scan"28 id = db.Column(db.Integer, primary_key=True)29 check_in_time = db.Column(db.DateTime)30 mask_detected = db.Column(db.Integer, nullable=False)31 temperature = db.Column(db.Float,nullable=False)32 person_id = db.Column(db.Integer, db.ForeignKey('User.id'), nullable=True)33 def __init__(self, mask_detected, temperature, person_id):34 self.check_in_time = datetime.now()35 self.mask_detected = mask_detected36 self.temperature = temperature37 self.person_id = person_id38 def __repr__(self):39 return '<Scan %r %r %r %r' % (self.check_in_time, self.mask_detected, self.temperature)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful