import requests
import cv2

#get x,y,w,h
API_URL = "https://boundary-detection.herokuapp.com/predict"; 
files = {'file': ("images.jpg", open('images.jpg', 'rb'))} 
resp = requests.post(API_URL, files=files) 
data = resp.json()

if(resp.status_code == 200):
    x = int(data['x'])
    y = int(data['y'])
    w = int(data['w'])
    h = int(data['h'])

    img = cv2.imread('images.jpg')
    img = img[y:h,x:w]
    cv2.imwrite('cropped.jpg',img)

    API_URL = "https://step-count.herokuapp.com/predict"; 
    files = {'file': ('cropped.jpg',open("cropped.jpg", 'rb'))} 
    resp = requests.post(API_URL, files=files) 
    
    data = resp.json()
    print(resp.status_code) 
    print(data)
    print(data['steps'])
else:
    print("No staircase")