Advertisement
RupeshAcharya60

Flask handle request

Jun 3rd, 2023
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. from flask import Flask,request
  2. import numpy as np
  3. import tensorflow as tf
  4.  
  5. app = Flask(__name__)
  6.  
  7.  
  8.  
  9. def get_coordinate():
  10.     image = load_img(path) #pil object
  11.     image = np.array(image,dtype=np.uint8) #8 bit array(0,255)
  12.     image1 = load_img(path,target_size=(224,224))
  13.     #data_preprocessing
  14.     image_arr_224 = img_to_array(image1)/255.0 #convert into array and get normalized array
  15.     h,w,d = image.shape
  16.     test_arr = image_arr_224.reshape(1,224,224,3)
  17.     #make prediction
  18.     coords = model.predict(test_arr)
  19.     #denormalize the value
  20.     denorm = np.array([w,w,h,h])
  21.     coords = coords * denorm
  22.     coords = coords.astype(np.int32)
  23.     #drawing bounding box on top of the image
  24.     xmin, xmax,ymin,ymax = coords[0]
  25.     pt1 = (xmin,ymin)
  26.     pt2 = (xmax,ymax)
  27.     print(pt1, pt2)
  28.     cv2.rectangle(image,pt1,pt2,(0,255,0),3)
  29.     return coords
  30.  
  31.  
  32.  
  33. @app.route("/sendimage",methods=["POST"])
  34. def hello_world():  
  35.     data = request.files["image"]
  36.     cods = get_coordinate(data)
  37.     img = np.array(load_img(data))
  38.     xmin,xmax,ymin,ymax = cods[0]
  39.     roi = img[ymin:ymax,xmin:xmax]
  40.     text = pt.image_to_string(roi)
  41.     text = "image"
  42.     return {"data":"data"}
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement