# filters.py import base64 from flask import current_app import cv2 def to_base64(image_np): # Convert numpy array to PNG image in memory _, img_encoded = cv2.imencode('.png', image_np) img_base64 = base64.b64encode(img_encoded).decode('utf-8') return img_base64 def init_app(app): app.jinja_env.filters['to_base64'] = to_base64