filters.py 351 B

12345678910111213
  1. # filters.py
  2. import base64
  3. from flask import current_app
  4. import cv2
  5. def to_base64(image_np):
  6. # Convert numpy array to PNG image in memory
  7. _, img_encoded = cv2.imencode('.png', image_np)
  8. img_base64 = base64.b64encode(img_encoded).decode('utf-8')
  9. return img_base64
  10. def init_app(app):
  11. app.jinja_env.filters['to_base64'] = to_base64