Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Last active June 9, 2023 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelibaceta/1883dcb9ad7cd15a627be1a815f393e4 to your computer and use it in GitHub Desktop.
Save joelibaceta/1883dcb9ad7cd15a627be1a815f393e4 to your computer and use it in GitHub Desktop.
Preprocessing
import cv2
import numpy as np
import base64
def process_image(image_data):
# Decodificar el contenido base64 a una matriz de bytes
contenido_bytes = base64.b64decode(image_data.split(',')[1])
# Convertir los bytes en una matriz de numpy
nparr = np.frombuffer(contenido_bytes, np.uint8)
img_bytes = np.frombuffer(nparr, np.uint8)
img_cv = cv2.imdecode(img_bytes, cv2.IMREAD_COLOR)
# Convertir la imagen a escala de grises
gray_img = cv2.cvtColor(img_cv, cv2.COLOR_BGR2GRAY)
# Aplicar detección de bordes utilizando el algoritmo Canny
edges = cv2.Canny(gray_img, 100, 200)
# Devolver los bordes detectados como un array de píxeles
return edges.tolist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment