Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
¿Cómo enviar una imagen directamente desde el servidor de matraz a html?

Soy nuevo en el matraz y estoy tratando de hacer una aplicación, tal imagen es tomada por el html y js de la cámara web y luego se envía al servidor con una solicitud ajax. Tengo esta parte. Luego, se realiza un procesamiento en la imagen y debe enviarse de vuelta a la interfaz. Sé cómo enviar datos normalmente en matraz, como en

 @app.route('/') def function(): return render_template("index.html", data = data)

Pero en python, las imágenes están en forma de matrices numpy y js no puede leer matrices numpy y convertirlas en imágenes (al menos no conozco ninguna forma de hacerlo). Entonces, ¿cuál es la forma en que se puede hacer esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto muestra cómo convertir una matriz numpy a PIL.Image y luego usarla con io.BytesIO para crear un archivo PNG en la memoria.

Y luego puede usar send_file() para enviar PNG al cliente.

 from flask import Flask, send_file from PIL import Image import numpy as np import io app = Flask(__name__) raw_data = [ [[255,255,255],[0,0,0],[255,255,255]], [[0,0,1],[255,255,255],[0,0,0]], [[255,255,255],[0,0,0],[255,255,255]], ] @app.route('/image.png') def image(): # my numpy array arr = np.array(raw_data) # convert numpy array to PIL Image img = Image.fromarray(arr.astype('uint8')) # create file-object in memory file_object = io.BytesIO() # write PNG in file-object img.save(file_object, 'PNG') # move to beginning of file so `send_file()` it will read from start file_object.seek(0) return send_file(file_object, mimetype='image/PNG') app.run()

De la misma manera puedes enviarlo como GIF o JPG.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!