title: Flask OpenCV Send and Receive Images in Bytes
body: <p>I want to send and receive images in bytes in my flask API. I also want to send some json alongside the image. How can I achieve this? </p>
  
  <p>Below is my current solution that does not work </p>
  
  <p>flask: </p>
  
  <pre><code>    @app.route('/add_face', methods=['GET', 'POST'])
      def add_face():
      if request.method == 'POST':
          # print(request.json)
          nparr = np.fromstring(request.form['img'], np.uint8)
          print(request.form['img'])
          img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
  
          cv2.imshow("frame", img)
          cv2.waitKey(1)
  
      return "list of names &amp; faces"
  </code></pre>
  
  <p>client: </p>
  
  <pre><code>def save_encoding(img_file):
      URL = "http://localhost:5000/add_face"
      img = open(img_file, 'rb').read()
  
      response = requests.post(URL, data={"name":"obama", "img":str(img)})
      print(response.content)
  </code></pre>
  
  <p>produced error:</p>
  
  <pre><code>cv2.imshow("frame", img)
  cv2.error: OpenCV(3.4.3) /io/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width&gt;0 &amp;&amp; size.height&gt;0 in function 'imshow'
  </code></pre>