Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask,request
- import numpy as np
- import tensorflow as tf
- app = Flask(__name__)
- def get_coordinate():
- image = load_img(path) #pil object
- image = np.array(image,dtype=np.uint8) #8 bit array(0,255)
- image1 = load_img(path,target_size=(224,224))
- #data_preprocessing
- image_arr_224 = img_to_array(image1)/255.0 #convert into array and get normalized array
- h,w,d = image.shape
- test_arr = image_arr_224.reshape(1,224,224,3)
- #make prediction
- coords = model.predict(test_arr)
- #denormalize the value
- denorm = np.array([w,w,h,h])
- coords = coords * denorm
- coords = coords.astype(np.int32)
- #drawing bounding box on top of the image
- xmin, xmax,ymin,ymax = coords[0]
- pt1 = (xmin,ymin)
- pt2 = (xmax,ymax)
- print(pt1, pt2)
- cv2.rectangle(image,pt1,pt2,(0,255,0),3)
- return coords
- @app.route("/sendimage",methods=["POST"])
- def hello_world():
- data = request.files["image"]
- cods = get_coordinate(data)
- img = np.array(load_img(data))
- xmin,xmax,ymin,ymax = cods[0]
- roi = img[ymin:ymax,xmin:xmax]
- text = pt.image_to_string(roi)
- text = "image"
- return {"data":"data"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement