Last active
June 9, 2023 12:43
-
-
Save joelibaceta/1883dcb9ad7cd15a627be1a815f393e4 to your computer and use it in GitHub Desktop.
Preprocessing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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