Last active
          April 23, 2024 10:58 
        
      - 
            
      
        
      
    Star
      
          
          (218)
      
  
You must be signed in to star a gist  - 
              
      
        
      
    Fork
      
          
          (37)
      
  
You must be signed in to fork a gist  
- 
      
 - 
        
Save kylehounslow/767fb72fde2ebdd010a0bf4242371594 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
kylehounslow revised this gist
Jun 19, 2019 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ from __future__ import print_function import requests import json import cv2 @@ -15,6 +16,6 @@ # send http request with image and receive response response = requests.post(test_url, data=img_encoded.tostring(), headers=headers) # decode response print(json.loads(response.text)) # expected output: {u'message': u'image received. size=124x124'}  - 
        
kylehounslow created this gist
May 8, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ import requests import json import cv2 addr = 'http://localhost:5000' test_url = addr + '/api/test' # prepare headers for http request content_type = 'image/jpeg' headers = {'content-type': content_type} img = cv2.imread('lena.jpg') # encode image as jpeg _, img_encoded = cv2.imencode('.jpg', img) # send http request with image and receive response response = requests.post(test_url, data=img_encoded.tostring(), headers=headers) # decode response print json.loads(response.text) # expected output: {u'message': u'image received. size=124x124'} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ from flask import Flask, request, Response import jsonpickle import numpy as np import cv2 # Initialize the Flask application app = Flask(__name__) # route http posts to this method @app.route('/api/test', methods=['POST']) def test(): r = request # convert string of image data to uint8 nparr = np.fromstring(r.data, np.uint8) # decode image img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) # do some fancy processing here.... # build a response dict to send back to client response = {'message': 'image received. size={}x{}'.format(img.shape[1], img.shape[0]) } # encode response using jsonpickle response_pickled = jsonpickle.encode(response) return Response(response=response_pickled, status=200, mimetype="application/json") # start flask app app.run(host="0.0.0.0", port=5000)