title: Receiving an image with Fast API, processing it with cv2 then returning it
body: <p>I am trying to build an API which receives an image and does some basic processing on it, then returns an updated copy of it using Open CV and Fast API. So far, I have the receiver working just fine, but when I try to base64 encode the processed image and send it back my mobile front end times out. </p>
  
  <p>As a debugging practice I've tried just printing the encoded string and making the API call using Insomnia, but after 5 solid minutes of printing data I killed the application. Is returning a base64 encoded string the right move here? Is there an easier way to send an Open CV image via Fast API? </p>
  
  <pre><code>class Analyzer(BaseModel):
      filename: str
      img_dimensions: str
      encoded_img: str
  
  @app.post("/analyze", response_model=Analyzer)
  async def analyze_route(file: UploadFile = File(...)):
      contents = await file.read()
      nparr = np.fromstring(contents, np.uint8)
      img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
  
      img_dimensions = str(img.shape)
      return_img = processImage(img)
  
      encoded_img = base64.b64encode(return_img)
  
      return{
          'filename': file.filename,
          'dimensions': img_dimensions,
          'encoded_img': endcoded_img,
      }
  </code></pre>